C++ Writing Functions 1) Write a function i sValidDNAchar that returns true if a
ID: 3762163 • Letter: C
Question
C++ Writing Functions
1) Write a function isValidDNAchar that returns true if a char argument is one of 'a', 'c', 'g', 't'. Otherwise the function returns false.
2) Then using that function, write a function isValidDNAstring that returns true if a string is only made up of valid DNA characters (a, c, g, t). If any other character exists in the string false is returned. You will want to call isValidDNAchar from within this function.
3) Then write a function ,transcribe, that changes DNA into RNA. Taking a string of DNA (ex. ttagcatctgg) , and couting the same thing except 't' is changed to a 'u' (ex. uuagcaucugg)
Explanation / Answer
#include<iostream>
using namespace std;
bool isValidDNAChar(char c){
if( c == 'a' || c == 'c' || c == 'g' || c == 't')
return true;
else
return false;
}
bool isValidDNAString(string s){
for(int i = 0; i < s.length(); i++)
if( !isValidDNAChar(s[i]))
return false;
return true;
}
int main(){
cout<<isValidDNAString("tgaaacccfcc");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.