13.3k views
2 votes
The local Driver’s License Office has asked you to write a program that grades the written portion of the driver’s license exam. The exam has 20 multiple choice questions. Here are the correct answers: B 2.D 3.A 4.A 5.C 6.A 7.B 8.A 9.C 10.D 11.B 12.C 13.D 14.A 15.D 16.C 17.C 18.B 19.D 20.A Your program should store the correct answers shown above in an array. It should ask the user to enter the student’s answers for each of the 20 questions, and the answers should be stored in another array. After the student’s answers have been entered, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions. in C++

User Bian
by
7.7k points

1 Answer

1 vote

Answer: The c++ program is shown below.

#include <iostream>

using namespace std;

int main() {

int ques[20], correct=0, incorrect=0, q[20];

// arrays to store answers for the questions

char a[20], ans[20];

// variable to store pass or fail result

string result;

for(int k=0; k<20; k++)

{

ques[k] = k+1;

q[k] = 0;

}

ans[0]='B';

ans[1]='D';

ans[2]='A';

ans[3]='A';

ans[4]='C';

ans[5]='A';

ans[6]='B';

ans[7]='A';

ans[8]='C';

ans[9]='D';

ans[10]='B';

ans[11]='C';

ans[12]='D';

ans[13]='A';

ans[14]='D';

ans[15]='C';

ans[16]='C';

ans[17]='B';

ans[18]='D';

ans[19]='A';

for(int k=0; k<20; k++)

{

cout<<"Enter the ans for question "<<k+1<<endl;

cin>>a[k];

}

for(int k=0; k<20; k++)

{

if(a[k] == ans[k])

correct++;

else

{

incorrect++;

q[k] = k+1;

}

}

if(correct >= 15)

result = "passed";

else if(incorrect >= 5)

result = "failed";

cout<<endl<<"You have "<<result<<" in the exam."<<endl;

cout<<"Correctly answered questions "<<correct<<endl;

cout<<"Incorrectly answered questions "<<incorrect<<endl;

cout<<"Incorect questions are "<<endl;

cout<<"\t";

for(int k=0; k<20; k++)

{

// 0 indicates correct question

if(q[k] == 0)

continue;

else

cout<<k+1<<"\t";

}

}

OUTPUT

Enter the ans for question 1

A

Enter the ans for question 2

A

Enter the ans for question 3

A

Enter the ans for question 4

A

Enter the ans for question 5

A

Enter the ans for question 6

A

Enter the ans for question 7

A

Enter the ans for question 8

A

Enter the ans for question 9

A

Enter the ans for question 10

A

Enter the ans for question 11

A

Enter the ans for question 12

A

Enter the ans for question 13

A

Enter the ans for question 14

A

Enter the ans for question 15

A

Enter the ans for question 16

D

Enter the ans for question 17

D

Enter the ans for question 18

D

Enter the ans for question 19

D

Enter the ans for question 20

D

You have failed in the exam.

Correctly answered questions 6

Incorrectly answered questions 14

Incorect questions are

1 2 5 7 9 10 11 12 13 15 16 17 18 20

NOTE:

The answers are stored in upper case. This program may not accept answers in lower case.

User Serhii Londar
by
6.6k points