Write a complete C++ program to analyze a set of DNA strands input from the keyb
ID: 3873024 • Letter: W
Question
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:
Your program should output the following:
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 < 75 but 50 or greater, it's considered "stable". Less than 50 but 25 or greater is considered "less stable". And a CG percentage < 25 is considered "unstable".
Recall that validity and CG percentage were the focus on lab this week. You will need a loop to input and process the strands one by one. Here's a skeleton loop structure to build upon:
Explanation / Answer
C++ CODE:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string DNA;
cout << "Enter DNA sequence! ";
cin >> DNA;
while(DNA != "#")
{
int CG = 0;
bool isvalid = true;
for (int i = 0; i < DNA.length(); ++i)
{
if(DNA[i] == 'C' or DNA[i] == 'G' )
{
CG++;
}
if(DNA[i] != 'C' and DNA[i] != 'G' and DNA[i] != 'T' and DNA[i] != 'A')
{
isvalid = false;
break;
}
}
if(isvalid)
{
float per = 100*(float)CG/(float)(DNA.length());
string stability;
if(per >= 75)
{
stability = "Highly stable";
}
else if(per < 75 and per >= 50)
{
stability = "stable";
}
else if(per < 50 and per >= 25)
{
stability = "less stable";
}
else
{
stability = "unstable";
}
cout << DNA << ": valid, CG = " << per << " percent, " << stability << endl;
}
else
{
cout << DNA << ": Invalid ";
}
cout << "Enter DNA sequence! ";
cin >>DNA;
}
return 0;
}
Sample Output:
Enter DNA sequence!
CCGA
CCGA: valid, CG = 75 percent, Highly stable
Enter DNA sequence!
ACTGATGC
ACTGATGC: valid, CG = 50 percent, stable
Enter DNA sequence!
ACTGATXC
ACTGATXC: Invalid
Enter DNA sequence!
TTCAA
TTCAA: valid, CG = 20 percent, unstable
Enter DNA sequence!
#
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.