cin >> DNA; while (DNA != \"#\") { . . . cin >> DNA; } Summary analyze a set of
ID: 3872792 • Letter: C
Question
cin >> DNA;
while (DNA != "#") { . . . cin >> DNA; } Summary analyze a set of DNA strands for validity. CG percentage, and overall stability Write a complete C++ program to analyze a set of DNA strands input from the keyboard For each strand, output the strand followed by validity, CG percentage, and overall stability. For example, given this input sequence CCGA ACTGATGC ACITGATTX TTCAA Your program should output the following: CCGA: valid, CG-75%, highly stable ACTGATGC : valid,CG#50% , stable ACTGATxc: invalid mCAA: valid, CG-20%, unstable In terms of overall stability, if the CG percentage is 75 or greater, than the DNA strand is considered highly stable'. If the CG percentage is
Explanation / Answer
#include<iostream>
#include<string>
using namespace std;
int main()
{
string DNA;
cin >> DNA;
int flag=1,count=0;
double percent;
while (DNA != "#")
{
for(int i=0;i<DNA.length();i++){
if(DNA[i]!='A'&&DNA[i]!='C'&&DNA[i]!='T'&&DNA[i]!='G'){
flag=0;
}
if(DNA[i]=='C'||DNA[i]=='G'){
count++;
}
}
percent=((double)count/(double)DNA.length())*100;
if(flag==1){
if(percent>=75){
cout<<DNA<<": valid "<<percent<<"% highly stable"<<endl;
}else if(percent>=50){
cout<<DNA<<": valid "<<percent<<"% stable"<<endl;
}else if(percent>=25){
cout<<DNA<<": valid "<<percent<<"% less stable"<<endl;
}else if(percent<25){
cout<<DNA<<": valid "<<percent<<"% unstable"<<endl;
}
}else{
cout<<DNA<<" invalid"<<endl;
}
cin >> DNA; // read next DNA strand:
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.