At Westonci.ca, we make it easy to get the answers you need from a community of informed and experienced contributors. Connect with a community of experts ready to provide precise solutions to your questions quickly and accurately. Experience the ease of finding precise answers to your questions from a knowledgeable community of experts.

Write a program that grades arithmetic quizzes as follows: Ask the user how many questions are in the quiz. Ask the user to enter the key (that is, the correct answers). There should be one answer for each question in the quiz, and each answer should be an integer. They can be entered on a single line, e.g., 34 7 13 100 81 3 9 10 321 12 might be the key for a 10-question quiz. You will need to store the key in an array. Ask the user to enter the answers for the quiz to be graded. As for the key, these can be entered on a single line. Again there needs to be one for each question. Note that these answers do not need to be stored; each answer can simply be compared to the key as it is entered. When the user has entered all of the answers to be graded, print the number correct and the percent correct.

Sagot :

Answer:

The program in C++ is as follows:

#include <iostream>

using namespace std;

int main(){

   int questions, answer;

   cout<<"Questions: ";

   cin>>questions;

   int answerkey[questions];

   cout<<"Enter answer keys: ";

   for(int i = 0; i< questions; i++){

       cin>>answerkey[i];    }

   int correct = 0;

   cout<<"Enter answers: ";

   for(int i = 0; i< questions; i++){

       cin>>answer;

       if(answer == answerkey[i]){

           correct++;        }    }

   cout<<"Correct answers: "<<correct<<endl;

   cout<<"Percentage correct : "<<(100 * correct)/questions<<"%";

   return 0;

}

Explanation:

This declares the number of questions and the answers submitted to each equation

   int questions, answer;

Prompt to get the number of questions

   cout<<"Questions: ";

This gets input for the number of questions

   cin>>questions;

This declares the answerkey as an array

   int answerkey[questions];

Prompt to get the answer key

   cout<<"Enter answer keys: ";

This iteration gets the answer key for each question

   for(int i = 0; i< questions; i++){

       cin>>answerkey[i];    }

This initializes the number of correct answers to 0

   int correct = 0;

Prompt to get the enter the answers

   cout<<"Enter answers: ";

This iterates through the answer keys

   for(int i = 0; i< questions; i++){

This gets the answer to each question

       cin>>answer;

This compares the answer to the answer key of the question

       if(answer == answerkey[i]){

If they are the same, correct is incremented by 1

           correct++;        }    }

Print the number of correct answers

   cout<<"Correct answers: "<<correct<<endl;

Print the percentage of correct answers

   cout<<"Percentage correct : "<<(100 * correct)/questions<<"%";