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

(JAVA) The local Driver\'s License Office has asked you to write a program that

ID: 3771832 • Letter: #

Question

(JAVA) 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: 1. B 6. A 11. B 16. C 2. D 7. B 12. C 17. C 3. A 8. A 13. D 18. B 4. A 9. C 14. A 19. D 5. C 10. D 15. D 20. A

Write a PROGRAM named DriverExam that holds the correct answers to the exam in an array field. The class should also have an array field that holds the student's answers. The PROGRAM should do the following. NO CLASSES(or methods).

Determine and display if the student "passed" or " failed" the exam.
Determine and display the total number of correctly answered questions
Determine and display the total of incorrectly answered questions
Determine and display the question numbers that the student missed.
Test for invalid inputs.

Explanation / Answer

#include <iostream>
#include <conio.h>
#include <cctype>

using namespace std;


void input(char[], int); //Function prototype
void checkAnswers(char[], char[], int, int);


int main()
{
const int NUM_QUESTIONS = 20;
const int MIN_CORRECT = 15;
int correctAnswers = 0; //Accumulator for number of correct answers
int incorrectAnswers = 0; //Accumulator for number of incorrect answers
char answers[NUM_QUESTIONS] = { 'B', 'D', 'A', 'A', 'C',
'A', 'B', 'A', 'C', 'D',
'B', 'C', 'D', 'A', 'D',
'C', 'C', 'B', 'D', 'A'};
int replies;
char stu_answers[NUM_QUESTIONS];

//Loop for users answers
for (replies = 0; replies < NUM_QUESTIONS; replies++)
{
cout<< "Please enter your answers (Hint: Use capital letters): "
<< (replies + 1) << ": ";
cin >> stu_answers[replies];

//Validation of users answers
while (stu_answers[replies] != 'A' && stu_answers[replies] != 'B' && stu_answers[replies] != 'C' && stu_answers[replies] != 'D')
{
cout << "You must enter A, B, C, or D ";

cout<< "Please enter your answers (Hint: Use capital letters): "
<< (replies + 1) << ": ";
cin >> stu_answers[replies];
}

}


checkAnswers(answers, stu_answers, NUM_QUESTIONS, MIN_CORRECT);

return 0;
}

void checkAnswers(char answers1[], char stu_answers1[], int NUM_QUESTIONS, int MIN_CORRECT)
{
//cout << "max: " << NUM_QUESTIONS;
int correctAnswers = 0;
int incorrectAnswers = 0;
int wrongAnswers[]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int j = 0;

//Check the student's replies against the correct answers
for (int i = 0; i < NUM_QUESTIONS; i++)
{
if (answers1[i] == stu_answers1[i])
correctAnswers++;
else if (answers1[i] != stu_answers1[i])
{
incorrectAnswers++;
wrongAnswers[j] = i + 1;
j++;
}
}
//Did they pass or fail?
if (correctAnswers >= MIN_CORRECT)
{
cout << " You must have at least 15 correct to pass.";
cout << " Student passed the exam ";
}
else
{
cout << " You must have at least 15 correct to pass.";
cout <<" Student failed the exam ";
}

//Display a list of the questions that were incorrectly answered.
cout << "The list below shows the question numbers of the incorrectly";
cout << " answered questions. ";
for (int i = 0; i < NUM_QUESTIONS; i++)
{
if (wrongAnswers[i] != 0)
cout << "Question # " << wrongAnswers[i] << " is incorrect." << endl;
}

//Display the number of correct and incorrect answers provided by the student.
cout << " Correct Answers = " << correctAnswers << endl;
cout << "Incorrect Answers = " << incorrectAnswers << endl;
}