in c++ how do I print the complement of a number or character?
hello
I'm writing a bioinformatics program that performs the transcription process and I need it to print out the complement of these 4 letters (A complement U, G complement C, C complement G and T complement A) how do I get the program to automatically print out the letters complement
here's my code so far
it reads the characters from a file and then for each character I want it to print out the complement
could i use a nested switch statement
switch (input){
case 1:
char transcription[100];
ifstream sequence;
cin.getline(transcription, 100);
sequence.open(transcription);
if(!sequence.is_open()){
exit(EXIT_FAILURE);
}
char transcription2[100];
sequence>>transcription2;
while(sequence.good()){
cout<<transcription2<<" ";
**********************//this is where the code for the complement to the letter must come in*************
sequence>>transcription2;
}
For example you can define a map the following way
std::map<char, char> m;
Then fill it with your pairs of characters.
So then you read a character, for example, 'A', its compliment is very easy to get with expression m['A'];
Another way is to use an array of std::pairs or two arrays or pointers to string literals. For example