1. Using Arrays: Driver\'s License Exam Grader System The local Drivers License
ID: 3562990 • Letter: 1
Question
1. Using Arrays: Driver's License Exam Grader System The local Drivers License Office has asked you to write a program that grades the written portion of the drivers license exam. The exam has 10 multiple choice questions. Here, are the correct answers:
1. B 6. A
2. D 7. B
3. A 8. A
4. A 9. C
5. C 10. D
Your program should store the correct answers shown above in a character array named "correctAnswers" (In this assignment you are not doing any string manipulation, so the "Answer" array can be a simple character array, not a string).
Then, it should ask the user to enter the student's answers for each of the 10 questions, and the answers should be stored in another array named "studentAnswers"
In order to pass the exam a student must answer at least 8 questions out of 10. So, the "grade" function checks the entries in both array and determine if the student has answered at least 8 questions correctly.
If student has passed the exam, your program should display the following message
Congratulations!
You have passed exam.
Total number of correct answers: < >
Total number of incorrect answers: < >
If student has failed the exam, your program should display the following message
Sorry, you have not passed the exam!
Total number of correct answers: < >
Total number of incorrect answers: < >
Input validation: Only accept the letters A, B, C, or D as answers. If user enters any other letter, your program should display a message indicating A, B, C, and D are the only valid inputs. If user enters invalid input more than three times display the message "GOOD BYE" and exit the program.
Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
char answer_sheet[20] = {'B', 'D', 'A', 'A', 'C', 'A', 'A', 'D', 'B', 'B', 'B', 'D', 'C', 'A', 'C', 'C', 'A', 'D', 'A', 'A'};
char answers[20];
int i=0,correct=0, incorrect=0;
char temp_answer;
while (i< 20)
{
cout<<"Enter Answer for Question "<<i+1<<endl;
cin>>temp_answer;
if (temp_answer == 'A' || temp_answer == 'B' || temp_answer== 'C' || temp_answer == 'D')
{
answers[i] = temp_answer;
if (answers[i] == answer_sheet[i])
correct++;
else
incorrect++;
i++;
}
else
{
cout<<"Invalid Answer, please try again"<<endl;
}
}
if (correct>= 15)
cout<<"Congratulations, you passed this exam!"<<endl;
else
cout<<"Sorry, you have failed this exam!"<<endl;
cout<<"Number of answers correct: "<<correct<<endl;
cout<<"Number of answer incorrect: "<<incorrect<<endl;
char c =getchar();
c = getchar();
c=getchar();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.