Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'ve tried my best on this problem. I would appreciate some guidance to getting

ID: 670487 • Letter: I

Question

I've tried my best on this problem. I would appreciate some guidance to getting the program to run as intended. Thanks

HERE IS THE PROBLEM DESCRIPTOIN:

5.11 DNA Batch Analysis

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 in lab this week (lab-05). You will also need a loop to input and process the strands one by one. Here's a skeleton loop structure to build upon:

*************************************************************************************************************************************************

HERE IS WHAT I DID:

#include <iostream>
#include <string>

using namespace std;

int CountCG(string DNA)
{
int result = 0;

for(size_t i = 0; i < DNA.length(); i++){
if(DNA[i] == 'C' || DNA[i] == 'G'){
result++;
}
}
return result;
}

bool isValid(string DNA){
bool result = true;
for(size_t i = 0; i < DNA.length(); i++){
if(DNA[i] != 'G'|| DNA[i] != 'C' || DNA[i] != 'A' || DNA[i] != 'T'){
result = false;
}
}
return result;
}
int main()
{
string DNA, validness, stability;
int CG, Total;
double percent;

cin >> DNA;

while(DNA != "#"){

CG = CountCG(DNA);
Total = DNA.length();
percent = ((double)CG) / Total * 100.0;

if(isValid(DNA) == true){
validness = "valid";
}
else if(isValid(DNA) == false){
validness = "invalid";
}

if(percent >= 75){
stability = "highly stable";
}
else if(percent >= 50){
stability = "stable";
}
else if(percent >= 25){
stability = "less stable";
}
else {
stability = "unstable";
}   
if(validness == "valid"){   
cout << DNA << ": " << validness << ",CG=" << percent << "%," << stability << endl;
} else{
cout << DNA << ": " << validness << endl;
}
cin >> DNA;
}

return 0;
}

*************************************************************************************************************************************************

TEST:

**INPUT:**

CCGA

ACTGATGC

ACTGATTX

TTCAA

AACCGGTTAA

#

EXPECTED OUTPUT:

CCGA: valid,CG=75%,highly stable

ACTGATGC: valid,CG=50%,stable

ACTGATTX: invalid

TTCAA: valid,CG=20%,unstable

AACCGGTTAA: valid,CG=40%,less stable

Explanation / Answer

Its problem in your isValid method. here you need to use && , not || as , any char other than GCAT are invalid.

bool isValid(string DNA){
   bool result = true;
   for(size_t i = 0; i < DNA.length(); i++){

      if(DNA[i] != 'G' && DNA[i] != 'C' && DNA[i] != 'A' && DNA[i] != 'T'){
          result = false;
          break;
      }
   }
   return result;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote