Rate my c++ Genetics Project

This project is for my school and works fine till now. This is complete till now. My school has windows xp but I have Kubuntu so I just wanna know if it would run without any error on my school computer.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* Project by Navsangeet Singh*/
/* Project on Genetics: Computer Science*/
/* Submitted to: Mr. Yadwinder Singh */



#include <iostream>
#include <iomanip>
#include <fstream>
 #include <cstdlib>


char cyan[] =" \x1b[36m";
char red[]= "\x1b[31;1m";


using namespace std;

int size=0;
int get(char b[]);
int set(char b[], char c[]);
int set_r(char b[], char r[]);
int draw(int l=0);

int main()
{
cout<<cyan;

 	char * bp = new char[size];
	char * cbp = new char[size];
	char *rbp = new char[size];
	int choice;
draw(5);
	cout<<"\x1b[31;5;1mWelcom To Genetic Project \033[0m"<<cyan;
	draw(5);
	cout<<endl;


	cout<<endl;
	cout<<red<<"Warning: If you have no idea about DNA or RNA please select option 5\n "<<cyan<<endl;
	start:
	cout<<"Enter your choice."<<endl;
	cout<<"1.Make full DNA from one strand "<<endl;
	cout<<"2.Make RNA from a new strand"<<endl;
	cout<<"3.Make RNA from previous strand"<<endl;
	cout<<"4.Go online for details"<<endl;
    cout<<"5.Get descreptive information about DNA and RNA"<<endl;
	cout<<"0.To Exit"<<endl;
	cin>>choice;

	switch (choice){

	case 1:
	cout << "Enter size\n";
	cin >> size;
		cout<<"Enter the DNA sequence for half strand "<<endl;
	get(bp);
	draw(5);
	cout<<"The complete DNA strand is";
	draw(5);
	cout<<endl;
	set(bp,cbp);

	break;

	case 2:
	cout<<"Enter the size of strand"<<endl;
	cin>>size;
	get(bp);
	draw(5);
	cout<<"RNA is " ;
	draw(5);
	cout<<endl;
	set(bp,rbp);

	break;

	case 3:
	draw(5);
	cout<<"The RNA is";
	draw(5);
	cout<<endl;
	break;

case 4:
 system( "firefox http://www.elmhurst.edu/~chm/vchembook/580DNA.html");

break;

	case 5:
	draw(10);
	ifstream infor;
    string line;
	infor.open("info.txt",ios::in);
	if(!infor){
	cout<<"Database Error\n We are sorry for inconveninence"<<endl;

	}
	while(!infor.eof()){
   getline(infor,line,'.');
    cout<<endl;
	cout<<line;
	}
	infor.close();

break;


	};
 if(choice !=0)
 goto start;

	return 0;
}

int get(char b[])
{
	for(int i = 0; i < size; i++)

	{
		cout << "Enter " << i + 1 << endl;
		cin >> b[i];
		b[i] = toupper(b[i]);
		if( b[i] != 'A' && b[i] !='C' && b[i] !='G' && b[i]!='T' )
		{
			cout << "Error: No such Nitrogen Base Found. You need to enter this value again \n";
			--i;
		}
	}
	return 0;
}

int set(char b[], char c[])
{
    int count=0;
    for(int j = 0; j < size; j++)	{

		if(b[j]=='A')
			c[j]='T';
		if(b[j]=='T')
			c[j]='A';
		if(b[j]=='C')
			c[j]='G';
		if(b[j]=='G')
			c[j]='C';

count++;
		cout << setw(10) << "-" << b[j] << "-" << c[j] << "-" << endl;
    if(count%3==0)
    cout<<endl;

    }
    return 0;
}


int set_r(char b[], char r[]){

for(int j = 0; j < size; j++)
	{

		if(b[j]=='A')
			r[j]='U';
		if(b[j]=='T')
			r[j]='A';
		if(b[j]=='C')
			r[j]='G';
		if(b[j]=='G')
			r[j]='C';

			cout<<setw(8)<<"-"<<r[j]<<"-"<<endl;
	}

return 0;

}
int draw(int l)
{
 for(int i=0;i<l;i++)
 cout<<"====";
return 0;
}


Have I used everything alright? I couldn't do much because of OS incompatibility. Please rate it.
A question: If OS like windows and MAC were written in C and C++ then how do they use graphics? I know c or c++ has no native GUI. Even if they used their own APIs then how did they make it if c has no default gui?
Needs a lot of polish. Look at how it worked compiled and run under Win 7 (note the escape sequences for color coding and errors when something unexpected happened):
 ←[36m====================←[31;5;1mWelcom To Genetic Project ←[0m ←[36m=========
===========

←[31;1mWarning: If you have no idea about DNA or RNA please select option 5
  ←[36m
Enter your choice.
1.Make full DNA from one strand
2.Make RNA from a new strand
3.Make RNA from previous strand
4.Go online for details
5.Get descreptive information about DNA and RNA
0.To Exit
4            // <======= MY INPUT 
'firefox' is not recognized as an internal or external command,
operable program or batch file.
Enter your choice.
1.Make full DNA from one strand
2.Make RNA from a new strand
3.Make RNA from previous strand
4.Go online for details
5.Get descreptive information about DNA and RNA
0.To Exit
3               // <======= MY INPUT
====================The RNA is====================
Enter your choice.
1.Make full DNA from one strand
2.Make RNA from a new strand
3.Make RNA from previous strand
4.Go online for details
5.Get descreptive information about DNA and RNA
0.To Exit
3                // <======= MY INPUT
====================The RNA is====================
Enter your choice.
1.Make full DNA from one strand
2.Make RNA from a new strand
3.Make RNA from previous strand
4.Go online for details
5.Get descreptive information about DNA and RNA
0.To Exit

Last edited on
closed account (3TXyhbRD)
Sahil512 wrote:
I just wanna know if it would run without any error on my school computer

As long as it's standard.

If you want to be cross-platform use standard code only and avoid system() and popen() as they are platform dependent. If you still want to use them you will need to use #ifdef.. endif directives so the same code will compile under Kubuntu and Windows and still work accordingly. E.g.:

1
2
3
4
5
6
7
#ifdef KUBUNTU
#define SYSTEM_CALL "firefox ..."
#endif

#ifdef WINDOWS
#define SYSTEM_CALL "notepad ..."
#endif 


As a side note, if you want to open a file in a browser look for "open default browser command" for each targeted OS, it will make your life easier.

Same directives can be used for escape codes for colors.

More about preprocessing directives: http://www.cplusplus.com/doc/tutorial/preprocessor/

Seeing you're working on Kubuntu I assume you're using either gcc or g++ to compile your code. Note that (alike others) these compilers have some extensions that are included by default when you compile (e.g.: int a[0]; is not standard but gcc/g++ will compile it). To avoid compiler extensions and make your code more standard (therefore more cross platform) use the -pedantic-errors argument on the command line when compiling.

Other gcc options: http://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Option-Summary.html#Option-Summary
Code executes sequentially from top to bottom.
You've got
1
2
3
int size=0;
char * bp = new char[size];
cin>>size;
which is obviously incorrect.


By the way, when your program ends you should restore how the terminal was (my prompt is not cyan)
@ Jock x, you need to enter DNA strand first. I was using this escape sequence from wikipedia and I thought it is standard. Is there any other way to use color?

Thank all for your replies. Please suggest me something to make it better.
closed account (3TXyhbRD)
Sahil512 wrote:
Please suggest me something to make it better.

By that you mean no reply was "something to make it better"? Tell us what you mean by "better".

Colour escape codes differ from OS to OS. Not all of them use ANSI escape codes (newer versions of Windows, for example, don't use it). Linux still uses ANSI escape codes therefore your code work in Kubuntu terminal. To solve this issue, Windows has the non-standard conio.h header. You will find textcolor() there and that it works with printf().

You can define a function-like macro that is bound to the platform you compile on. For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <cstdlib>

#define KUBUNTU

#ifdef KUBUNTU
#include <iostream>
#define printColor(color, text) std::cout << "\x1b[" << 30 + color << ";5;1m" << text
#endif

#ifdef WINDOWS
#include <conio.h>
#define printColor(color, text) textcolor(color); printf(text)
#endif

int main(int argc, char *args[]){
    if (argc > 1)
        printColor(atoi(args[1]), "Hello!\n");
    else
        printColor(7, "Hello!\n");
}


The code above, with the right #define (KUBUNTU or WINDOWS) will compile and print Hello! in a colour specified as an command line argument. If no argument is specified it will write it in white/grey (Linux at least).

I do not guarantee that the textcolor() colour codes have anything in common with the ANSI escape colour codes.
Topic archived. No new replies allowed.