Question
What’s the C++ code to this? So that my output is:
CCTAGAATG
| | X | | X | |
GGACCTAAC
Validity: 77.7778%
Stability: 57.1429%

Part #02 The goal is to write a complete C++ program that inputs 2 strings from the keyboard, where each string denotes a DNA strand such as CCTAGAATG. Assume the 2 strings are the same length. The program will then CS 109: htp:/bwww.csic.edu i109 Page I of 3 line up the two strands to see how many of the pairs form valid base pairs, ie. that a C is paired with a G and an A is paired with a T. The program also outputs the percentage of valid base pairs, and the stability of the DNA strand formed by the valid base pairs. For example, suppose the following two strings are input from the keyboard: CCTAGAATG and GGACCTAAC. The program outputs the following: CCTAGAATG IIIxI IXII GGACCTAAC Validity: 77.7778% Stability: 57.1429% The program outputs the 1st strand, then compares each characters in the first strand to the corresponding character in the second strand. If the characters form a valid base pair, then l is output connecting the two characters (thats the vertical bar character on right-side of keyboard). If the characters do not form a valid base pair, then X is output denoting that the pair is not valid. This output is followed by the 2nd strand, and then the percentage of valid pairs (7/9 in this case) and the stability of the DNA strand formed by the valid base pairs. The notion of stability is defined as the percentage of C and G characters in the subset of valid base pairs (from either string). For example, given the strings above, pick either string. There are 7 valid base pairs, and within those 7 there are 4 C and G characters. So thats 4/7, or 57.1429%. Assume the user will enter valid strings that contain a sequence of capital letters consisting of A,C,G, and T. Also assume the two strings entered by the user are the same length.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include<iostream>
using namespace std;

int main()
{
    string dna1,dna2,compare("");
    double CG=0,pairs=0,validity,stability;
    cout<<"Enter DNA 1:";
    getline(cin,dna1);
    cout<<"Enter DNA 2:";
    getline(cin,dna2);
    for(int i=0; i<dna1.size(); i++)
    {
        if ((dna1[i]=='C'&&dna2[i]=='G')||(dna1[i]=='G'&&dna2[i]=='C'))
        {
            compare=compare+'|';
            CG++;
            pairs++;
        }
        else if((dna1[i]=='A'&&dna2[i]=='T')||(dna1[i]=='T'&&dna2[i]=='A'))
        {
            compare=compare+'|';
            pairs++;
        }
        else
            compare=compare+'X';
    }
    validity=pairs*100/dna1.size();
    stability=CG*100/pairs;
    cout<<dna1<<"\n"<<compare<<"\n"<<dna2;
    cout<<"\nValidity: "<<validity<<"%";
    cout<<"\nStability: "<<stability<<"%";
    return 0;
}

Enter DNA 1:CCTAGAATG Enter DNA 2:GGACCTAAC CCTAGAATG GGACCTAAC Validity: 77.7778% stability: 57.1429% Process exited after 1

Add a comment
Know the answer?
Add Answer to:
What’s the C++ code to this? So that my output is: CCTAGAATG | | X |...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in c++ language please Summary given 2 DNA strands of equal length, compare the bas Given...

    in c++ language please Summary given 2 DNA strands of equal length, compare the bas Given two DNA strands of equal length, write a complete C++ program to compare the corresponding bases, and report mismatches. For example, suppose the input to your program are the following two DNA strands CCATGGTC CCAGTGAC then your program should produce the following output **Differences: 3 In other words, your program should output the first strand, then on the next line output a space if...

  • Three C Code Questions: 5. Write a C program that declares an array of 10 strings,...

    Three C Code Questions: 5. Write a C program that declares an array of 10 strings, each of max length 50 characters, and then reads an entire line of text from the keyboard into each string. 6. Write C code that finds the longest name in this array of strings that you read in Q5. Hint: find the position of the longest string, not the string itself. 7. Write a C program that creates a 4 x 6 two dimensional...

  • Can someone help me with this, and it has to be written in the C programming...

    Can someone help me with this, and it has to be written in the C programming language: Write a program that reads a string from the keyboard. If the length of the string is an even number, your program should split the string into two strings of equal length. If the length of the string is odd, your program should split the string into two strings where the first part has one more character than the second part. Your program...

  • c programming

    Write a c program that reads a string with a maximum length of 30 from the keyboard[1]. The program should then copy the characters from that input string into a second character array (in order of input). However, only if a character is a vowel (a, e, i, o, u) should it be copied into the second array. Once copied, the program should output the values stored in the second array (in order of input). The program should then count...

  • Pig Latin program using Linked Lists C++

    Write a program that prompts the user to input a string and then outputs the string in the pig Latin form. The rules for converting a string into pig Latin form are asfollows:a. If the string begins with a vowel, add the string "-way" at the end of the string. for example, the pig Latin form of the string "eye" is "eye-way".b. If the string does not begin with a vowel, first ass "-" at the end of the string....

  • IN C language Write a C program that prompts the user to enter a line of...

    IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...

  • Write Java code to implement a FSM machine that recognizes the language for the alphabet {a,b,c} ...

    Write Java code to implement a FSM machine that recognizes the language for the alphabet {a,b,c} consisting of all strings that contain two consecutive c's and end with b.                   Your FSM program should include the following three static methods (Java) or functions (C):                                           a.    int nextState(int state, char symbol)                                  A state-transition function that returns the next state based on the                                  current state and an input symbol. This function should also return                                  -1 when an invalid input character is detected.                                  State...

  • Use c-strings for the following project: Write a C++ program that declares an array containing up...

    Use c-strings for the following project: Write a C++ program that declares an array containing up to a maximum of 20 sentences, each sentence of maximum 81 characters long, using c-strings. Continue reading sentences from the user and store them in the array of sentences, until the user enters a NULL string for the sentence or 20 sentences have been entered. Then, one by one, display each sentence entered by the user and present the following menu of operations on...

  • Hi everyone, I have a problem about C programming. Background Material: The figure 6 is as...

    Hi everyone, I have a problem about C programming. Background Material: The figure 6 is as below: The task: Download the file 55.c. Study the C code, then build an executable and run it to see what the output is. Modify the program so that the output is The string in buffer is "In C the value of 12 + 34 / 5 is 18." Do this by looking up decimal values for ASCII codes in Figure 6 and typing...

  • Use C++ language, keep it simple Exercise #2: Strings' operations Write a C++ program that prompts...

    Use C++ language, keep it simple Exercise #2: Strings' operations Write a C++ program that prompts the user to enter a sentence, the program then does the following: 1. Prints the total characters in the sentence. 2. Prints the word count of the sentence, assuming only one space between each tow words. 3. Prints total vowel (a, e, i, o, u) in the sentence. 4. Prints the vowel frequency as shown in the sample below. 5. Prints the sentence in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT