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

Write a C++ program that grades the answers to a true-false quiz given to studen

ID: 3700419 • Letter: W

Question

Write a C++ program that grades the answers to a true-false quiz given to students. The quiz consists of 5 true-false questions. Each correct answer is worth 2 points.

Use main( ) as your driver function. Write main( ) so that it allows the user to run the program as many times as desired, as indicated by input from the user. No data validation is requires for this program.

Write appropriate functions that main( ) calls to accomplish the following tasks:

Read the answer key and the number of students who took the quiz from the user.

Read the student names from the user.

Read and store the answers for each student on the quiz.

Calculate the grades.

Display each student’s name, quiz answers, and grade.

Sample Input:

This program calculates the grades for students taking a true-false quiz.

Please enter the answer key (use uppercase T or F).

Answer #1: ? T

Answer #2: ? T

Answer #3: ? F

Answer #4: ? F

Answer #5: ? T

How many students took the quiz? 4

Please enter the students' names.

Student #1 Name: ? Mike Jones

Student #2 Name: ? John Smith

Student #3 Name: ? Betty Hill

Student #4 Name: ? George Green

Please enter the answers for Mike Jones (use uppercase T or F).

Answer #1: ? T

Answer #2: ? F

Answer #3: ? T

Answer #4: ? F

Answer #5: ? T

Please enter the answers for John Smith (use uppercase T or F).

Answer #1: ? F

Answer #2: ? T

Answer #3: ? F

Answer #4: ? T

Answer #5: ? F

Please enter the answers for Betty Hill (use uppercase T or F).

Answer #1: ? T

Answer #2: ? T

Answer #3: ? T

Answer #4: ? T

Answer #5: ? T

Please enter the answers for George Green (use uppercase T or F).

Answer #1: ? F

Answer #2: ? F

Answer #3: ? F

Answer #4: ? F

Answer #5: ? F

Sample Output:

Student Name        Quiz Answers     Grade

-----------------        ------------------    --------

Key                            T T F F T           10

Mike Jones                 T F T F T            6

John Smith                  F T F T F            4

Betty Hill                    T T T T T           6

George Green              F F F F F            4

Would you like to process another quiz? Please enter 'y' for yes or 'n' for no: y

Explanation / Answer

#include <iostream>

#include <cstring>

using namespace std;

struct student

{

char name[50];

char answer[5];

};

int main(){

  

int i, j, temp, Sum;

int num_stud;

char solution[5];

cout << "Please Enter the Answer Key (Upper Case T or F)" << endl;

for (i = 0; i < 5 ; i++) {

cout << "Answer " << i + 1 << " ? ";

cin >> solution[i];

}

cout << " How many Students took the Test ? ";

cin >> num_stud;

student *stud1 = new (nothrow) student[num_stud];

int *score = new (nothrow) int[num_stud];

cout << " Please enter the students' names. " << endl;

  

for(i = 0; i < num_stud ; i++)

{

cout << "Student : " << i + 1 << " Name ? ";

cin >> stud1[i].name;

}

  

cout << endl;

  

for (i = 0; i < num_stud; i++) {

cout << "Please enter the answers for " << stud1[i].name << "(use uppercase T or F)." << endl;

score[i] = 0;

for(j = 0; j < 5; j++) {

cout << "Answer #" << j+1 << " ? ";

cin >> stud1->answer[j];

if (stud1->answer[j] == solution[j]) {

score[i] = score[i] + 2;

}

}

cout << endl;

}

  

cout << "Student Name Quiz Answers Grade" << endl;

cout << "-----------------------------------------------------------" << endl;

for(i = 0; i < num_stud + 1 ; i++){

if (i == 0){

cout << "Key ";

for(j = 0; j < 5 ; j++)

cout << solution[j] << " ";

cout << " " << 10 << endl;

}

else {

cout << stud1[i-1].name << " " ;

for(j = 0; j < 5 ; j++)

cout << solution[j] << " ";

cout << " " << score[i-1] << endl;

}

}

delete [] score; // DELETE THE DYNAMIC ARRAY

delete [] stud1; // DELETE THE DYNAMICS ARRAY OF STRUCTURES

return 0;

}

/************************* Output of Program *****************************

Please Enter the Answer Key (Upper Case T or F)

Answer 1 ? T

Answer 2 ? T

Answer 3 ? F

Answer 4 ? F

Answer 5 ? T

How many Students took the Test ? 4

Please enter the students' names.

Student : 1 Name ? MikeJones

Student : 2 Name ? JohnSmith

Student : 3 Name ? BettyHill

Student : 4 Name ? GeorgeGreen

Please enter the answers for MikeJones(use uppercase T or F).

Answer #1 ? T

Answer #2 ? F

Answer #3 ? T

Answer #4 ? F

Answer #5 ? T

Please enter the answers for JohnSmith(use uppercase T or F).

Answer #1 ? F

Answer #2 ? T

Answer #3 ? F

Answer #4 ? T

Answer #5 ? F

Please enter the answers for BettyHill(use uppercase T or F).

Answer #1 ? T

Answer #2 ? T

Answer #3 ? T

Answer #4 ? T

Answer #5 ? T

Please enter the answers for GeorgeGreen(use uppercase T or F).

Answer #1 ? F

Answer #2 ? F

Answer #3 ? F

Answer #4 ? F

Answer #5 ? F

Student Name Quiz Answers Grade

-----------------------------------------------------------

Key T T F F T 10

MikeJones T T F F T 6

JohnSmith T T F F T 4

BettyHill T T F F T 6

GeorgeGreen T T F F T 4

*******************************************************************/

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