Answer to Question #255019 in C++ for Bryson Fugarino

Question #255019

Write a program in DNA sequence analysis

in c++ coding the goal to provide a report of the number of each nucleotide within the sequence, and the percent each nucleotide makes up of the total.


Every DNA sequence consists of four nucleotides: Adenine, Thymine, Cytosine, and Guanine, referred to by the first letters of their chemical names (A, T, C, and G).


Output:

DNA sequence analysis:

29782 nucleotides in the sequence


Sequence breakdown:


Adenine: 8892 29.86%

Thymine: 9581 32.17%

Cytosine: 5462 18.34%

Guanine: 5847 19.63%



1
Expert's answer
2021-10-22T07:54:32-0400
#include<iostream>
using namespace std;
int main(){
	string dna = "GTCGTAGAATAGTCGTAGAATAGGGTAGGGTAATTAATTATAATATGC";
	float n = dna.length();
	float g=0, t=0, c=0, a=0;
	
	for(int i=0; i<n; i++){
		if(dna[i]=='G'){
			g++;
		}
			else if(dna[i]=='C'){
			c++;
		}
		else if(dna[i]=='A'){
			a++;
		}
		else if(dna[i]=='T'){
			t++;
		}
		
	}
	cout<<"DNA sequence analysis:\n"<<n<<" nucleotides in the sequence\n";
	cout<<"Adenine:  "<<a<<"  "<<(a/n) * 100<<"%"<<endl;
	cout<<"Thymine:  "<<t<<"  "<<(t/n) * 100<<"%"<<endl;
	cout<<"Cytosine:  "<<c<<" "<<(c/n) * 100<<"%"<<endl;
	cout<<"Guanine:  "<<g<<" "<<(g/n) * 100<<"%"<<endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS