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.
/* 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";
usingnamespace 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 = newchar[size];
char * cbp = newchar[size];
char *rbp = newchar[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
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.:
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
@ 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.
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:
#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.