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

Summary: analyze a set of DNA strands for validity, CG percentage, and overall s

ID: 3873209 • Letter: S

Question

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:

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:

PROGRAMMING INSTRUCTIONS

Zyante contains a complete C++ programming environment, so you are free to work here. Zyante provides 2 modes: "Develop" and "Submit". In Develop mode, you supply the input values in the text field provided, then click Run program to run your program and see the output. This gives you a chance to develop and test your program as you see fit.

When you are ready to submit your program for grading, switch to Submit mode, and click Submit for grading. This will run your program against the provided test cases (some of which may be hidden). The zyante system will submit a copy of your program, along with your score. In this assignment you may submit as many times as you want without penalty --- zyante records your highest score. If you fail to pass a test, keep in mind that auto-grading systems demand 100% precision. For example, your answer will be marked as incorrect if you do not output the requested values in the desired format --- extra spaces or missing newlines will be marked as incorrect. Compare youroutput to the expected output to determine what's wrong.

Does zyante save your work? Zyante saves the most recent copy that you submitted --- i.e. the last time you clicked the "Run program" or "Submit for grading" button. If you close the browser and reload the web page, this is the version of the program you will see. There is no way to go back to earlier versions, or "save" your current work unless you Run / Submit. For this reason, it is recommended that you save your work in an editor or word processor.

You are free to work outside of zyante in a programming environment of your choice, but you must submit for grading using the zyante system: copy-paste your program into zyante, switch to Submit mode, and Submit for grading. Note that different programming environments have different defaults, so it's quite possible that a program working outside of zyante will fail when run inside zyante. This is not an error in the zyante system --- this means there is a logic error in your program. The most common mistake is failure to initialize a variable. If your program fails to produce output here in zyante, then switch to Develop mode, supply some test inputs, and Run program. Make sure your program compiles, and runs to completion. Add output statements if you need to debug further.

Explanation / Answer

#include<iostream>
#include<vector>
#include<string>
#include<sstream>
using namespace std;

main()
{
// declaring variables
vector<string> dnaname;
vector<int> dnaper;
int index = 0, cg, per,flag;
string dna;
  
cin >> dna;
  
// as long as dna is not #
while(dna!="#"){
  
cg = 0;
flag = 0;
  
// looping through each character in dna
for(int i=0;i<dna.length();i++)
{
// if it is c or g then incrementing cg by 1
if(dna[i]=='C' || dna[i]=='G')
cg++;
// else if it is neither t nor a then it is invalid character.
// Setting the flag and not considering it further
else if(dna[i]!='T' and dna[i]!='A')
flag = 1;
}
  
// pusing dna to vector
dnaname.push_back(dna);
  
// valid dna and calculating percentage
if(flag == 0)
{
per = (cg*1.0/dna.length())*100;
dnaper.push_back(per);
}
//not considering it further hence pushing -1
else
{
dnaper.push_back(-1);
}
cin >> dna;
}
  
// looping through each dna and printing output
for(int i=0;i<dnaname.size();i++)
{
cout << dnaname[i];
if(dnaper[i]>=75)
cout << ": valid, CG=" << dnaper[i] << "%, highly stable"<< endl;
else if(dnaper[i]>=50)
cout << ": valid, CG=" << dnaper[i] << "%, stable"<< endl;
else if(dnaper[i]>=25)
cout << ": valid, CG=" << dnaper[i] << "%, less stable"<< endl;
else if(dnaper[i]==-1)
cout << ": invalid" << endl;
else
cout << ": valid, CG=" << dnaper[i] << "%, unstable"<< endl;
}
}

#include<iostream>
#include<vector>
#include<string>
#include<sstream>
using namespace std;

main()
{
// declaring variables
vector<string> dnaname;
vector<int> dnaper;
int index = 0, cg, per,flag;
string dna;
  
cin >> dna;
  
// as long as dna is not #
while(dna!="#"){
  
cg = 0;
flag = 0;
  
// looping through each character in dna
for(int i=0;i<dna.length();i++)
{
// if it is c or g then incrementing cg by 1
if(dna[i]=='C' || dna[i]=='G')
cg++;
// else if it is neither t nor a then it is invalid character.
// Setting the flag and not considering it further
else if(dna[i]!='T' and dna[i]!='A')
flag = 1;
}
  
// pusing dna to vector
dnaname.push_back(dna);
  
// valid dna and calculating percentage
if(flag == 0)
{
per = (cg*1.0/dna.length())*100;
dnaper.push_back(per);
}
//not considering it further hence pushing -1
else
{
dnaper.push_back(-1);
}
cin >> dna;
}
  
// looping through each dna and printing output
for(int i=0;i<dnaname.size();i++)
{
cout << dnaname[i];
if(dnaper[i]>=75)
cout << ": valid, CG=" << dnaper[i] << "%, highly stable"<< endl;
else if(dnaper[i]>=50)
cout << ": valid, CG=" << dnaper[i] << "%, stable"<< endl;
else if(dnaper[i]>=25)
cout << ": valid, CG=" << dnaper[i] << "%, less stable"<< endl;
else if(dnaper[i]==-1)
cout << ": invalid" << endl;
else
cout << ": valid, CG=" << dnaper[i] << "%, unstable"<< endl;
}
}

  SAMPLE OUTPUT   CCGA   ACTGATGC   ACTGATXC   TTCAA   #  CCGA: valid, CG=75%, highly stable  ACTGATGC: valid, CG=50%, stable  ACTGATXC: invalid  TTCAA: valid, CG=20%, unstable  
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