10. Driver\'s License Exam rhe local Driver\'s License Office has asked you to w
ID: 3709147 • Letter: 1
Question
10. Driver's License Exam rhe 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 ques- tions. Here are the correct answers: 1. A 2. D 3. B 4. B 5. ? 6. ? 7. A 8. B 9, C 10. D 16. C 12. ? 13. D 14. B 15. D 18. A 19. D 20. B 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 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. put Validation: Only accept the letters A, B, C, or D as answers.Explanation / Answer
#include<iostream>
using namespace std;
int main(){
char cor[] = { 'A', 'D', 'B', 'B','C',
'B', 'A', 'B', 'C', 'D',
'A', 'C', 'D', 'B', 'D',
'C', 'C', 'A', 'D', 'B'};
char ans[20];
int correct = 0;
int incorrect = 0;
int fault[20];
for (int i = 0; i<20; i++){
cout << "Enter answer for question " << i+1 <<": ";
string ch;
cin >> ch;
while (ch[0] != 'A' && ch[0] != 'B' && ch[0] != 'C' && ch[0] != 'D'){
cout << "Invalid input ";
cin >> ch;
}
ans[i] = ch[0];
if (ans[i] == cor[i])
correct++;
else{
fault[incorrect] = i+1;
incorrect++;
}
}
if (correct >= 15)
cout << "Passed ";
else
cout << "Failed ";
cout << "Number of correct answers: " << correct << endl;
cout << "Number of incorrect answers: " << incorrect << endl;
cout << "Following questions are incorrectly answered ";
for (int i = 0; i<incorrect; i++)
cout << fault[i] << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.