Answer to Question #285077 in C++ for Sara

Question #285077

Write a function int wrong(char key[].char results[]) The function will be used to grade multiple-choice exam.

The exan has 5 questions, each answered with a letter in the range 'a', to f. All the answers for a student are stored in the character array results.

The key-answer is also stored in array key. Both arrays (results) and (key) are passed to the function wrong as parameters.

The function wrong returns the numbers of false answers given by by the student. For example if the key is-{'a','b','a','d",'e'} and the results is {'a','c','a','d','f'}. the function return 2 (since there are 2 wrong answers).


1
Expert's answer
2022-01-06T02:01:34-0500
#include <iostream>
using namespace std;


int wrong(char key[], char result[]) {
    int count = 0;


    for (int i=0; i<5; i++) {
        if (key[i] != result[i]) {
            count++;
        }
    }
    return count;
}


int main() {
    char key[5] = {'a', 'b', 'a', 'd', 'e'};
    char results[5] = {'a', 'c', 'a', 'd', 'f'};


    cout << "wrong return " << wrong(key, results) << endl;
}

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