This is the implementation for a program that basically converts from DNA to RNA. The bases can only be GTAC, and when transcribed is GUAC, or just change the T for the U. How to do so that when the user inserts other letters that are not those the program does not run or put an error message in the bases? I attach the code:
#include <iostream>
#include <cstring>
using namespace std;
class ADN {
private:
string secuencia;
public:
ADN(string _secuencia);
string GetSecuencia();
int Longitud();
string Transcripcion();
string GetTranscripcion();
};
ADN::ADN(string _secuencia){
secuencia=_secuencia;
}
string ADN::GetSecuencia(){
return secuencia;
}
int ADN::Longitud(){
return secuencia.length();
}
string ADN::Transcripcion() {
string out = ""; // Realmente no se si esta bien :p
for (int i = 0; i <= secuencia.length(); i++)
out += (secuencia[i] == 'T')? 'U': secuencia[i];
return out;
}
int main() {
string Secuencia_ADN = "";
cout << "Inserte secuencia de ADN: ";
cin >> Secuencia_ADN;
ADN a1(Secuencia_ADN);
cout << "La secuencia de ADN es:" << a1.GetSecuencia() << endl;
cout << "La longitud de la secuencia es:" << a1.Longitud() << endl;
cout << "La secuencia de ARN es: " << a1.Transcripcion() << endl;
system("pause");
return 0;
}