In: Computer Science
*******IN PSEUDOCODE AND C++******* Program 0 (Warm-up, 40 pts): Deoxyribonucleic acid, or DNA, is comprised of four bases: (G)uanine, (C)ytosine, (A)denine and (T)hymine. Ribonucleic acid, or RNA, is different than DNA in that it contains no Thymine; thymine is replaced with something called (U)racil. For this assignment, you will create an array of 255 characters. You must start by filling the array with random characters of G, C, A and T. You must then print out the array. Next, replace all the instances of Thymine with Uracil. Finally, you must print out the array again. In your solution, you must write at least one function that contributes to the solution. You must use the length attribute of the array in your answer.
Sample run
CATGGCGTCTTGCCAAGGCGGTTCCTTGTCTTGATGATGGCTGCGAGTTCCGAGTCGCCTTTTCTATGAGTCGCGAAGTATGCGGTCAAATTATGCTTGTCCGCTGTACTAGGCCCACGGATCTCCTCAGACAGCGTCGATGTCGGAATTCGCGGGGAGGAATACTAAACATGCTGAAGTTGATACATGTACAATTGCCGCGAACCAGGTGCACAGGGTGCCCAACGATCCATGTGGAACGAGAGCGATCTAGCC
CAUGGCGUCUUGCCAAGGCGGUUCCUUGUCUUGAUGAUGGCUGCGAGUUCCGAGUCGCCUUUUCUAUGAGUCGCGAAGUAUGCGGUCAAAUUAUGCUUGUCCGCUGUACUAGGCCCACGGAUCUCCUCAGACAGCGUCGAUGUCGGAAUUCGCGGGGAGGAAUACUAAACAUGCUGAAGUUGAUACAUGUACAAUUGCCGCGAACCAGGUGCACAGGGUGCCCAACGAUCCAUGUGGAACGAGAGCGAUCUAGCC
C++ code for the give problem is written below. Comments have been added to make the code comprehensible.
The code does the following in sequence:
======================================================================================
#include <iostream>
using namespace std;
//Define a function getBase() which will be used to generate a
random number between 1 and 4 and use it
//for returning either 'G', 'C', 'A' or 'T' using a switch
statement
char getBase()
{
//Generate a random number between 1 and 4 using
rand(), remember main() has already called srand() by the time
getBase() gets called from for loop
int randNum = (rand() % 4) + 1;
//Use switch to map to either 'G', 'C', 'A' or
'T' base and return to the caller
switch(randNum)
{
case 1:
return 'G';
break;
case 2:
return 'C';
break;
case 3:
return 'A';
break;
case 4:
return 'T';
break;
}
}
int main()
{
//Initialize two character arrays to store our
random characters
char dna[255], rna[255];
//Seed the random number generator with current
time so that each run will generate a different sequnce of
characters
//Just using rand() without srand() will cause
the same random pattern of character sequence to be generated
everytime
srand(time(NULL));
//Run a loop 255 times to generate and store 255
random characters for dna character array using getBase()
function
for(int i=0; i<sizeof(dna); i++)
dna[i]=getBase();
//Print the DNA array
cout << "DNA Sequence: " << dna
<< endl;
//Replace all the instances of Thymine with
Uracil
for (int i=0; i<sizeof(dna); i++)
{
//If base is Thymine,
replace with Uracil
if(dna[i]=='T')
rna[i]='U';
//Else just copy the
same base as of dna in rna character array
else
rna[i]=dna[i];
}
//Print the RNA array
cout << "RNA Sequence: " << rna
<< endl;
return 0;
}
======================================================================================
Sample Output:
======================================================================================
DNA Sequence:
AAAGCTCAGTGTTTGTGCGTGTTATTATTTTCCCCAGTCGACTCCTGCCGGCTTTTTCAAGAGCTCTGGGGAAGTTTTGGTGCTGGATCGCCACAATAATAAAGACTACTAGGGTGGCTAAGTGAAACGGGATATCGATCAACAACAAACGGCGCTATGAGCGTTTGTAGGGAA
AGTGACCTAATTACAATATTCTTAACATCGCTGGTACGCTAGAGCCTGTAGCCTTGGCTCCGGCGTTCTCCCCTATGCTGT
RNA Sequence:
AAAGCUCAGUGUUUGUGCGUGUUAUUAUUUUCCCCAGUCGACUCCUGCCGGCUUUUUCAAGAGCUCUGGGGAAGUUUUGGUGCUGGAUCGCCACAAUAAUAAAGACUACUAGGGUGGCUAAGUGAAACGGGAUAUCGAUCAACAACAAACGGCGCUAUGAGCGUUUGUAGGGAA
AGUGACCUAAUUACAAUAUUCUUAACAUCGCUGGUACGCUAGAGCCUGUAGCCUUGGCUCCGGCGUUCUCCCCUAUGCUGU
======================================================================================
DNA Sequence:
CCTTTGTACGAATGGTTATATTGGTTTATGGGAGGCGTTCTAGTAGACACTCGGATTCCTCATTATCATGTAATCGTTCAGCTCCCGGAATGGTTAAGGCCTGTTCGACCGCAGATCTGGCTGCATTCGTACAAGCGGGCAGAGGCGAGGACTAAACCTCGCAAGTGGTGCCGT
ACGATGACCCTTTGGAAGGGTGTTGTTCGTGAGCGTCAGTGTATGTAATAAAAACACGTCGTGGGGGATGCTGTAGAGAAA
RNA Sequence:
CCUUUGUACGAAUGGUUAUAUUGGUUUAUGGGAGGCGUUCUAGUAGACACUCGGAUUCCUCAUUAUCAUGUAAUCGUUCAGCUCCCGGAAUGGUUAAGGCCUGUUCGACCGCAGAUCUGGCUGCAUUCGUACAAGCGGGCAGAGGCGAGGACUAAACCUCGCAAGUGGUGCCGU
ACGAUGACCCUUUGGAAGGGUGUUGUUCGUGAGCGUCAGUGUAUGUAAUAAAAACACGUCGUGGGGGAUGCUGUAGAGAAA
======================================================================================
DNA Sequence:
TACAGCTTGCTGTACCCGCGTGTAGGAACCCCTTTGGTTCGTCGCACAAATCAATATCGGAACACCACGCAGGTGACCGTGTCAAGCCACCGTTAGGGAGAGGAGCGCACCAGACAAATGTCCTGTTGGCGAAGGACCTGAGAAATCCCGCCCAGCATCACCGTAGCTCGTTCA
ATCTGTTAGCGGAATGGGCGTTCGTACAAAGGCATACAGCTGCATGATCTGGTCCATAGCGCCCTGTGTTCAGAGTAAATA
RNA Sequence:
UACAGCUUGCUGUACCCGCGUGUAGGAACCCCUUUGGUUCGUCGCACAAAUCAAUAUCGGAACACCACGCAGGUGACCGUGUCAAGCCACCGUUAGGGAGAGGAGCGCACCAGACAAAUGUCCUGUUGGCGAAGGACCUGAGAAAUCCCGCCCAGCAUCACCGUAGCUCGUUCA
AUCUGUUAGCGGAAUGGGCGUUCGUACAAAGGCAUACAGCUGCAUGAUCUGGUCCAUAGCGCCCUGUGUUCAGAGUAAAUA