USING VISUAL STUDIO 2015 Task 3 using visualstudio 2015 - Arrays Driver\'s Licen
ID: 3861578 • Letter: U
Question
USING VISUAL STUDIO 2015
Task 3 using visualstudio 2015 - Arrays
Driver's License Exam
The local Driver's License Office has Asked you to write a program that grades the written type
portion of the driver's license exam. The exam has 20 multiple choice questions.
Here are the correct answers:
1. A 2. D 3. B 4. B 5. C
6. B 7. A 8. B 9. C 10. D
11. A 12. C 13. D 14. B 15. D
16. C 17. C 18. A 19. D 20. B
Your program should large 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 two 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.
Input Validation: Only accept the letters A, B, C, or D as answers.
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
int main()
{
char originalAnswers[] = {'A', 'D','B','B','C','B','A','B','C','D','A','C','D','B','D','C','C','A','D','B'};
char answers[20];
for(int i=0; i<20; i++){
cout<<"Enter the question "<<(i+1)<<" answer: ";
cin >> answers[i];
if(!(answers[i] == 'A' || answers[i] == 'B' || answers[i] == 'C' || answers[i] == 'D')) {
cout<<"Invalid answer. Answer must be A, B, C or D."<<endl;
i--;
}
}
int correctAnswersCount = 0, wrongAnswersCount = 0;
string s =" ";
for(int i=0; i<20; i++){
if(answers[i] ==originalAnswers[i] ){
correctAnswersCount++;
}
else{
wrongAnswersCount++;
s = s + to_string(i+1) +" ";
}
}
cout<<"Number of correct answers: "<<correctAnswersCount<<endl;
cout<<"Number of wrong answers: "<<wrongAnswersCount<<endl;
cout<<"Wrong answers question no's: "<<s<<endl;
if(correctAnswersCount>=15){
cout<<"EXAM PASS"<<endl;
}
else{
cout<<"EXAM FAIL"<<endl;
}
return 0;
}
Output:
sh-4.2$ g++ -std=c++11 -o main *.cpp
sh-4.2$ main
Enter the question 1 answer: A
Enter the question 2 answer: B
Enter the question 3 answer: C
Enter the question 4 answer: D
Enter the question 5 answer: q
Invalid answer. Answer must be A, B, C or D.
Enter the question 5 answer: A
Enter the question 6 answer: B
Enter the question 7 answer: D
Enter the question 8 answer: C
Enter the question 9 answer: A
Enter the question 10 answer: D
Enter the question 11 answer: C
Enter the question 12 answer: B
Enter the question 13 answer: w
Invalid answer. Answer must be A, B, C or D.
Enter the question 13 answer: E
Invalid answer. Answer must be A, B, C or D.
Enter the question 13 answer: D
Enter the question 14 answer: A
Enter the question 15 answer: C
Enter the question 16 answer: D
Enter the question 17 answer: A
Enter the question 18 answer: D
Enter the question 19 answer: C
Enter the question 20 answer: B
Number of correct answers: 5
Number of wrong answers: 15
Wrong answers question no's: 2 3 4 5 7 8 9 11 12 14 15 16 17 18 19
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.