Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Summary: given 2 DNA strands of equal length, compare the bases. Given two DNA s

ID: 3873210 • Letter: S

Question

Summary: given 2 DNA strands of equal length, compare the bases. 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: CCATGGTC XX X CCAGTGAC **Differences: 3 In other words, your program should output the first strand, then on the next line output a space if the corresponding bases are the same and an 'X' if not, followed by the second strand, followed by a summary of the # of differences. If the strands are identical, the # of differences reported should be 0. Don't forget to #include so you have access to the string functionality in C++. [ Hint: this is not as hard as it looks. Input the 2 DNA strands, output the first, then loop over the strings like you have done in the other exercises. But instead of comparing the ith character to a known letter such as 'C' or 'G', compare to the ith character in the other string. Count and output as you loop, then after the loop output the 2nd DNA strand and the # of differences. ] PROGRAMMING INSTRUCTIONS Zyante contains a complete C++ programming environment, so you are free to work here. Zyante provides 2 modes: "Develop" and "Submit". In Develop mode, you supply the input values in the text field provided, then click Run program to run your program and see the output. This gives you a chance to develop and test your program as you see fit. When you are ready to submit your program for grading, switch to Submit mode, and click Submit for grading. This will run your program against the provided test cases (some of which may be hidden). The zyante system will submit a copy of your program, along with your score. In this assignment you may submit as many times as you want without penalty --- zyante records your highest score. If you fail to pass a test, keep in mind that auto-grading systems demand 100% precision. For example, your answer will be marked as incorrect if you do not output the requested values in the desired format --- extra spaces or missing newlines will be marked as incorrect. Compare your output to the expected output to determine what's wrong. Does zyante save your work? Zyante saves the most recent copy that you submitted --- i.e. the last time you clicked the "Run program" or "Submit for grading" button. If you close the browser and reload the web page, this is the version of the program you will see. There is no way to go back to earlier versions, or "save" your current work unless you Run / Submit. For this reason, it is recommended that you save your work in an editor or word processor. You are free to work outside of zyante in a programming environment of your choice, but you must submit for grading using the zyante system: copy-paste your program into zyante, switch to Submit mode, and Submit for grading. Note that different programming environments have different defaults, so it's quite possible that a program working outside of zyante will fail when run inside zyante. This is not an error in the zyante system --- this means there is a logic error in your program. The most common mistake is failure to initialize a variable. If your program fails to produce output here in zyante, then switch to Develop mode, supply some test inputs, and Run program. Make sure your program compiles, and runs to completion. Add output statements if you need to debug further. LAB

Explanation / Answer

#include <iostream>

using namespace std;

int main() {

// declaring variables

string a, b;

int count = 0;

// taking user input

cout << "Enter DNA 1: ";

cin >> a;

cout << "Enter DNA 2: ";

cin >> b;

// printing first strand

cout << endl << a << endl;

// looping through each character

for(int i=0;i<a.length();i++)

{

// checking if they are equal

if(a[i]==b[i])

cout << " ";

// if not, increasing count by 1 and printing X

else

{

count++;

cout << "X";

}

}

// printing second strand

cout << endl << b << endl;

cout << "**Differences: " << count << endl;

}

SAMPLE OUTPUT

Enter DNA 1: CCATGGTC

Enter DNA 2: CCAGTGAC

CCATGGTC

   XX X

CCAGTGAC

**Differences: 3

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote