In: Computer Science
C++ program, include comments stating what each part of code does please. I want to be able to understand it so I'll be more knowledgeable in the future. The program is multiple files(transcribe_dna_to_rna.h file, transcribe_dna_to_rna.cpp file, main.cpp file and loops_strings_test.cpp). After the directions I also included any starter code or comments left by my professor within the files to aide us.
Directions:
In folder 05_loops_strings write prototype and definition for string value - return function transcribe_dna_into_rna with a string parameter that returns the rna string. Write the required unit test(s) in folder 05_loops_strings_test. Main program flow: No loop. Use the given string as function argument call transcribe_dna_into_rna function and display the output.
transcribe_dna_to_rna.h
| /* | |
| Create a function transcribe_dna_into_rna with a dna const reference string parameter that returns a string. | |
| */ |
transcribe_dna_to_rna.cpp
| //Write include statements | |
| /* | |
| An RNA string is a string formed from the alphabet containing 'A', 'C', 'G', and 'U'. | |
| Given a DNA string t corresponding to a coding strand, its transcribed RNA string u is formed by replacing | |
| all occurrences of 'T' in t with 'U' in u. | |
| Given: A DNA string | |
| Return: The transcribed RNA string of the DNA string | |
| Examle: | |
| dna_string: GATGGAACTTGACTACGTAAATT | |
| transcribe_dna_into_rna("GATGGAACTTGACTACGTAAATT"); | |
| returns: | |
| GAUGGAACUUGACUACGUAAAUU | |
| */ |
main.cpp
| //Write include statements | |
| //Write using statements | |
| /* | |
| No loop. | |
| Use the string "GATGGAACTTGACTACGTAAATT" call the transcribe_dna_into_rna function and display the result | |
| */ | |
| int main() | |
| { | |
| return 0; | |
| } |
loops_strings_test.cpp
| #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file | |
| #include "catch.hpp" | |
| //Write include statements | |
| /* | |
| Write test case for transcribe dna to rna with string: | |
| "GATGGAACTTGACTACGTAAATT" returns GAUGGAACUUGACUACGUAAAUU | |
| */ |
// transcribe_dna_to_rna.h
//function for converting DNA to RNA
string transcribe_dna_into_rna(string t){
string u = "";
//iterating over whole DNA string t to construct RNA string u
for(int i=0;i<t.length();i++){
//checking if character at position i is T which needs to be converted to U
if(t[i]=='T'){
//if T exists at position i then we add U in place of T
u += 'U';
}else{
//if any other character appears in other than T then we add the correcponding character to RNA string
u += t[i];
}
}
return u;
}
// main.cpp
#include<iostream>
#include "transcribe_dna_to_rna.h"
using namespace std;
int main(){
//calling function transcribe_dna_into_rna to convert DNA to RNA;
string rna = transcribe_dna_into_rna("GATGGAACTTGACTACGTAAATT");
cout<<rna<<endl;
return 0;
}
// loops_strings_test.cpp
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
#include "transcribe_dna_to_rna.h" //including our header file
//writing test case for the function RNA to DNA
TEST_CASE("Testing DNA to RNA function") {
//calling the function and then comparing with the correct data, REQUIRE ensures that the condition is matched else the test case will fail
REQUIRE(transcribe_dna_into_rna("GATGGAACTTGACTACGTAAATT").compare("GAUGGAACUUGACUACGUAAAUU")==0)
}
Hope this helps. Please upvote. thanks.