Answer to Question #220603 in C++ for Layla

Question #220603

Task C: Substitution and Hamming Distance

For this task, we will explore mutations that occur by substitution. Your task is to write a program called hamming.cpp that calculates the Hamming distance between two strings. Given two strings of equal length, the Hamming distance is the number of positions at which the two strings differ. e. g.: Hamming("aactgc", "atcaga") would output 3. Notice that certain amino acids are encoded by multiple codons. Therefore, not all substitutions result in a change of protein structure. The file <code class="language-plaintext highlighter-rouge" style="font-family: monospace, monospace; font-size: 1em; padding-left: 0.5em; padding-right: 0.5em; border-style: solid; border-width: 1px; border-radius: 0.5em; border-color: rgb(248, 248, 248); background: rgb(248, 248,


1
Expert's answer
2021-07-25T16:50:08-0400


#include <iostream>


using namespace std;
int HammingDistance(char *s1, char *s2)
{
    int i = 0, count = 0;
    while (s1[i] != '\0')
    {
        if (s1[i] != s2[i])
            count++;
        i++;
    }
    return count;
}
 
int main()
{
    char string1[100];
    char string2[100];
    cout<<"\nEnter the first string: ";
    cin>>string1;
    cout<<"\nEnter the second string: ";
    cin>>string2;
    cout << HammingDistance(string1, string2);
 
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS