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

CREATE 2 CLASSES. Write the data type class named DriverTestScoredriver AND the

ID: 3770884 • Letter: C

Question

CREATE 2 CLASSES. Write the data type class named DriverTestScoredriver AND the the driver class named DriverLicenseOnline .The local driver’s license office has asked you to write a program that grades the written portion of the driver’s license test. The driver license test has 25 multiple choice questions. The program will display the question numbers and read the answers from the keyboard. The driver should type a letter A, B, C or D to answer each question. The set of answers should be evaluated by comparing to the following key answers: 1.B 6.A 11. B 16. C 21.A 2.D 7.B 12.C 17.C 22.B 3.A 8.A 13.D 18.B 23.C 4.A 9.C 14.A 19.D 24.A 5.C 10.D 15.D 20.A 25.D A driver must have 20 correct questions to pass the test. The result will be displayed on the screen in the following format: Driver’s name: Jones, Becky Driver’s License: 123456789 Test date: 11/10/2014 (display current date) Result: PASSED Missed Questions: 5, 12, 15

Explanation / Answer

#include <iostream>
using namespace std;

int main()
{
  
    const int NUM_QUESTIONS = 20;
    const int MIN_CORRECT = 15;
    char answers[NUM_QUESTIONS] =
    {
        'B', 'D', 'A', 'A', 'C',
        'A', 'B', 'A', 'C', 'D',
        'B', 'C', 'D', 'A', 'D',
        'C', 'C', 'B', 'D', 'A'
    };

  
    char a = 'A';
    a=toupper(a);
  
    char b = 'B';
    b=toupper(b);
  
    char c = 'C';
    c=toupper(c);
  
    char d = 'D';
    d=toupper(d);
  
    char studentAnswers[NUM_QUESTIONS];
    void Answer ( char studentAnswers[] );
    void Grade ( char studentAnswers[] );
    void Display ( char studentAnswers[] );
  
    cout<< "Welcome to the Driver's License Test! ";
    cout << "You must correctly answer at least 15 out of the 20 questions to pass! ";
  
    Answer(studentAnswers);
    Grade(studentAnswers);
    Display(studentAnswers);
  
  
    return 0;
}

void Answer(char studentAnswers[])
{

    for (int index = 0; index < NUM_QUESTIONS; index++)
    {
      
        cout << " Please enter your answer for question " << (index + 1) << ": ";
        cin >> studentAnswers[index];
      
        //Input validation of users answers
         if ('a' <= student_input_answers[index] && student_input_answers[index] <= 'd')
                     student_input_answers[index] = (char)toupper(student_input_answers[index]);
  
  
            cout << "You must enter A, B, C, or D ";
          
            cout << " Please enter your answer for question " << (index + 1) << ": ";
            cin >> studentAnswers[index];
        }
      
    }
}


void Grade(char student_input_answer[])

{
  
    int correctAnswers = 0;
    cout << " You must have at least 15 correct to pass.";
    for (int index = 0; index < NUM_QUESTIONS; index++)
    {
      
        using namespace std;
      
      
        if (student_input_answer[index] == (CORRECTanswer[index]))
          
            correctAnswers++;
      
      
      
    }
    if (correctAnswers >= MIN_CORRECT)
    {
        cout << " Congratulations! You passed the exam! ";
    }
  
    else
    {
        cout << " Sorry, you did not pass the exam." << endl;
    }
  
  
  
  
}

// Display Function

void Display(char student_input_answers[])
{
  
    cout << " Incorrect Answers: "
  
    for ( int index = 0; index < NUM_QUESTIONS; index++)
   {
      
       if (student_input_answers[index] != CORRECTanswer[index])
            cout << " " << index + 1 << "." << student_input_answers[index];
      
   }  
}