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

C++ Writing Functions 1) Write a function, gc . gc : The GC content of a single

ID: 3762166 • Letter: C

Question

C++ Writing Functions

1) Write a function, gc .

gc : The GC content of a single DNA sequence is the ratio of the total number of c’s and g’s to the length of the strand. For example, the sequence atcgtttgga is of length 10 and has a total of 4 c’s and g’s, so its GC content is 0.4. This function should return a double between 0 and 1 that is the GC content of a DNA sequence.

2)Write a function, complementChar.

complementChar: returns the complement of the base character. If the argument is the base character 'a', then the character 't' is returned and vice versa; If the argument is the base character 'c', then 'g' is returned and vice versa. Assume valid DNA string.

3) Write a funciton, complementStr

complementStr: returns the complementary DNA string of a valid DNA string . Assume valid DNA string. (ex. ttagcatct returns aatcgtaga)

Explanation / Answer

#include<iostream>

#include<string.h>

using namespace std;

double gc(string str) {

double count = 0;

for (int i=0; i<str.length(); i++) {

if (str[i] == 'g' || str[i] == 'c') {

count++;

}

}

return count/str.length();

}

char complementChar(char ch) {

if (ch == 'a') {

return 't';

} else if (ch == 't') {

return 'a';

} else if (ch == 'c') {

return 'g';

} else {

return 'c';

}

}

string complementStr(string str) {

char *arr = new char[str.length()];

for (int i=0; i<str.length(); i++) {

arr[i] = complementChar(str[i]);

}

return arr;

}

int main() {

cout << "GC count: "<<gc("atcgtttgga")<<endl;

cout<<"Complement string: "<<complementStr("ttagcatct")<<endl;

cout<<" ";

return 0;

}

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