1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Maslowich
2 years ago
12

Write a program that grades arithmetic quizzes as follows: Ask the user how many questions are in the quiz. Ask the user to ente

r 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.
Computers and Technology
1 answer:
kirill115 [55]2 years ago
7 0

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

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

<em>        cin>>answerkey[i];    }</em>

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<<"%";

You might be interested in
Question: 4/8
Gemiola [76]

The generated test cases for the function assuming another developer coded the function is given below in a C++ program.

<h3>THE CODE</h3>

#include <iostream>  

#include <iomanip>

#include <string>

using namespace std;

// define the data type "triangletype" with {values}

enum triangleType { scalene, isosceles, equilateral, noTriangle };

// Prototype function which returns the position of triangleType{value}

// Example: Scalene = 0, isosceles = 1, etc. These are zero indexed.

triangleType triangleShape(double a, double b, double c);

// Prototype function which takes the integer value of the

// triangle type and outputs the name of triangle

string shapeAnswer(int value);

int main() {

   double inputA;

   double inputB;

   double inputC;

   cout << "To determine whether a triangle is either:" << endl;

   cout << setw(50) << " - Scalene" << endl; // Unequal in length

   cout << setw(52) << " - Isosceles" << endl; // Two sides equal length

   cout << setw(54) << " - Equilateral" << endl; // All sides equal

   cout << setw(57) << " - Not a triangle" << endl;

   cout << "Enter side A: ";

   cin >> inputA;

   cout << "Enter side B: ";

   cin >> inputB;

  cout << "Enter side C: ";

   cin >> inputC;

   cout << "The triangle is " << shapeAnswer(triangleShape(inputA, inputB, inputC)) << endl;

}

triangleType triangleShape(double a, double b, double c) {

   triangleType answer;

   if ( c >= (a + b) || b >= (a + c) || a >= (b + c) ) {

       answer = noTriangle;

   }

   else if (a == b && b == c) {

       answer = equilateral;

   }

   // Test the 3 options for Isosceles equality

   else if ( (a == b) && (a != c) || (b == c) && (b != a) || (a == c) && (a != b) ) {

       answer = isosceles;

   }

   else {

       answer = scalene;

   }

   return answer;

}

string shapeAnswer(int value) {

   string answer;

  switch (value) {

   case 0:

       answer = "Scalene";

       break;

   case 1:

       answer = "Isosceles";

       break;

   case 2:

       answer = "Equilateral";

       break;

   case 3:

       answer = "Not a triangle";

       break;

   default:

       break;

   }

   return answer;

}

Read more about C++ programs here:

brainly.com/question/20339175

#SPJ1

8 0
1 year ago
What caused accident? into passive voice​
lozanna [386]
Accident was caused by what
6 0
2 years ago
After selecting a cell in the data range, what are some ways to create a table? Check all that apply.
lana66690 [7]

Answer: the answer is B /E

3 0
2 years ago
Read 2 more answers
Please help me with these two questions! 60 points!
RUDIKE [14]

Answer:

Networks prevent unauthorized access to data and protect equipment. Networked computers are less likely than single computers to suffer equipment failure. Networks allow computers to connect quickly and to share data or equipment.

Explanation:

3 0
2 years ago
What does the hard disk drive do?
Airida [17]
It stores data and retrieving digital information using one or more rigid rapidly rotating disks (platters) coated in magnetic material
4 0
3 years ago
Read 2 more answers
Other questions:
  • Answer this question please
    6·1 answer
  • "Suppose that instead of always selecting the first activity to finish, we instead select the last activity to start that is com
    14·1 answer
  • By defeaut, Excel cells are top aligned<br><br> a. True<br><br> b. False
    12·1 answer
  • Which different supports from a part of the matte box?
    8·1 answer
  • Explain what occurs when you synchronize computer and mobile devices.
    5·1 answer
  • How do you write the slope-intercept form?
    5·1 answer
  • What is a slide master ?
    8·2 answers
  • Determine the following information about each value in a list of positive integers.
    14·1 answer
  • PLEASE ANSWER LAST DAY OF SCHOOL. Discussion Topic
    10·1 answer
  • Why does the media play such an important role in our personal freedom? Select 3 options.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!