Use C++ A DNA sequence is a string that contains only the characters ‘A’, ‘T’, ‘C’, ‘G’ (representing the four bases ade

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Use C++ A DNA sequence is a string that contains only the characters ‘A’, ‘T’, ‘C’, ‘G’ (representing the four bases ade

Post by answerhappygod »

Use C++
A DNA sequence is a string that contains only the characters
‘A’, ‘T’, ‘C’, ‘G’ (representing the four bases adenine, A;
thymine, T; cytosine, C; guanine, G). You are to implement a C++
class that can count the number of times a specific triplet of
bases (also called a codon, e.g., “ATC”, “GGG”,
“TAG”) appears in a set of DNA sequences.
For example, given two DNA sequences: TCTCCCTGACCC
and CCCTGACCC
Implement your logic in a class Codons. The class should
have 3 public member functions:
These public member functions will be called from the provided
main program (dna.cpp) and the answers checked there. You can
modify the main function to test your code with different input
cases to make sure the logic will work in the general case - we
will test your code with different DNA sequences not included
here.
Hint:
Data structures: you are
encouraged to use the C++ Standard Library containers.
Required documentation:
dna.cpp
#include <iostream>
#include <string>
#include "Codons.h"
using std::string;
using std::cout;
template <typename T>
bool testAnswer(const string &nameOfTest, const T&
received, const T& expected);
int main() {
{
Codons codons;
cout << "Reading one string: TCTCCCTGACCC\n";
codons.readString("TCTCCCTGACCC");
testAnswer("count(TCT)", codons.getCount("TCT"), 1);
testAnswer("count(CCC)", codons.getCount("CCC"), 2);
testAnswer("count(TGA)", codons.getCount("TGA"), 1);
testAnswer("count(TGT)", codons.getCount("TGT"), 0);
}
{
Codons codons;
cout << "Reading one string:
TCTCCCTGACCCTCTCCCTCT\n";
codons.readString("TCTCCCTGACCCTCTCCCTCT");
testAnswer("count(TCT)", codons.getCount("TCT"), 3);
testAnswer("count(CCC)", codons.getCount("CCC"), 3);
testAnswer("count(TGA)", codons.getCount("TGA"), 1);
testAnswer("count(TGT)", codons.getCount("TGT"), 0);
}
{
Codons codons;
cout << "Reading two strings: TCTCCCTGACCC and
TCTCCCTGACCCTCTCCCTCT\n";
codons.readString("TCTCCCTGACCC");
codons.readString("TCTCCCTGACCCTCTCCCTCT");
testAnswer("count(TCT)", codons.getCount("TCT"), 4);
testAnswer("count(CCC)", codons.getCount("CCC"), 5);
testAnswer("count(TGA)", codons.getCount("TGA"), 2);
testAnswer("count(TGT)", codons.getCount("TGT"), 0);
}
{
Codons codons;
cout << "Reading two strings: TCTCCCTGACCC and
TCTCCCTGACCCTCTCCCTCT\n";
codons.readString("TCTCCCTGACCC");
codons.readString("TCTCCCTGACCCTCTCCCTCT");
testAnswer("count(TCT)", codons.getCount("TCT"), 4);
testAnswer("count(CCC)", codons.getCount("CCC"), 5);
testAnswer("count(TGA)", codons.getCount("TGA"), 2);
testAnswer("count(TGT)", codons.getCount("TGT"), 0);
cout << "Reading third string:
ACCAGGCAGACTTGGCGGTAGGTCCTAGTG\n";
codons.readString("ACCAGGCAGACTTGGCGGTAGGTCCTAGTG");
testAnswer("count(TCT)", codons.getCount("TCT"), 4);
testAnswer("count(CCC)", codons.getCount("CCC"), 5);
testAnswer("count(TGA)", codons.getCount("TGA"), 2);
testAnswer("count(TAG)", codons.getCount("TAG"), 1);
testAnswer("count(GGG)", codons.getCount("GGG"), 0);
}
}
template <typename T>
bool testAnswer(const string &nameOfTest, const T&
received, const T& expected) {
if (received == expected) {
cout << "PASSED " << nameOfTest <<
": expected and received " << received << "\n";
return true;
}
cout << "FAILED " << nameOfTest << ":
expected " << expected << " but received " <<
received << "\n";
return false;
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply