Answer to Question #253846 in C++ for Bryce

Question #253846

Write a Program: DNA Sequence Analysis



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). I have provided an



entire DNA sequence in the file


dnaSequence.txt.




You goal is to provide a report of the number of each nucleotide within the sequence, and the



percent each nucleotide makes up of the total. You should include your output file in the



submission in addition to our usual submission format (console output + code).




1
Expert's answer
2021-10-20T07:39:19-0400
#include <bits/stdc++.h>
using namespace std;

void printUpperHalf(string str) {
	char first, second;
	int pos = 0;
	for (int i = 1; i <= 4; i++) {
		first = str[pos];
		second = str[pos + 1];
		pos += 2;
		for (int j = 4 - i; j >= 1; j--) cout << " ";
		cout << first;
		for (int j = 1; j < i; j++) cout << "--";
		cout << second << endl;
	}
}
void printLowerHalf(string str) {
	char first, second;
	int pos = 0;
	for (int i = 1; i <= 4; i++) {
		first = str[pos];
		second = str[pos + 1];
		pos += 2;
		for (int j = 1; j < i; j++) cout << " ";
		cout << first;
		for (int j = 4 - i; j >= 1; j--) cout << "--";
		cout << second << endl;
	}
}
void printDNA(string str[], int n) {
	for (int i = 0; i < n; i++) {
		int x = i % 6;
		if (x % 2 == 0) printUpperHalf(str[x]);
		else printLowerHalf(str[x]);
	}
}

int main() {
	int n = 8;
	string DNA[] = { "ATTAATTA", "TAGCTAGC", "CGCGATAT", "TAATATGC", "ATCGTACG", "CGTAGCAT" };
	printDNA(DNA, n);
	return 0;
}

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