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

Driver\'s License Exam The State Department of Motor Vehicles (DMV) has asked yo

ID: 3909133 • Letter: D

Question

Driver's License Exam The State Department of Motor Vehicles (DMV) has asked you to write a program that grades the written portion of the driver's license exam, which has 20 multiple choice questions. Here are the correct answers 1.B 2.D 3.A 4.A 13.D 14.A 15.D 16.? 17.C 18.B 19.D 20.A 5.? 10.D 11.B 12.? 6.? 8.A To do this, you should create a TestGrader class. The class will have an answers array of 20 characters, which holds the correct test answers. It will have two public member functions that enable user programs to interact with the class: setKey and grade. The setKey function receives a 20-character string holding the correct answers and copies this information into its answers array. The grade function receives a 20-character array holding the test taker's answers and compares each of their answers to the correct one. An applicant must correctly answer 15 or more of the 20 questions to pass the exam. After "grading the exam, the grade function should create and return to the user a string that includes the following information .A message indicating whether the applicant passed or failed the exam .The number of right answers and the number of wrong answers . A list of the question numbers for all incorrectly answered questions The client program that creates and uses a TestGrader object should first make a single call to setKey, passing it a string containing the 20 correct answers. Once this is done, it should allow a test taker's 20 answers to be entered, making sure only answers of A-D are accepted, and store them in a 20-character array. Then it should call the grade function to grade the exam and should display the string the function returns. The program should loop to allow additional tests to be entered and graded until the user indicates a desire to quit.

Explanation / Answer

#include<iostream>
#include<string>

using namespace std;

class TestGrader{

    private:
        char ans[20];
    public:
        void setKey(string a){
           for (int i = 0; i<20; i++){
                ans[i] = a[i];
           }
        }
        void grade(char a[]){
          
            int incorrect[20];
            int correctCount = 0;
            int incorrectCount = 0;
            for(int i = 0; i<20; i++){
               if (a[i] == ans[i]){
                  correctCount++;
               }
               else {
                  incorrect[incorrectCount] = i+1;
                  incorrectCount++;
                 
               }
            }
            if (correctCount >= 15){
               cout << "Congartulations! You Passed ";
            }
            else {
               cout << "Sorry! You failed ";
            }
            cout << "Number of correct answers:" << correctCount << endl;
            cout << "Number of incorrect answers:" << incorrectCount << endl;
            if (incorrectCount > 0){
               cout << "Incorrectly answered questions:" ;
               for (int i = 0; i<incorrectCount; i++){
                   cout << incorrect[i] << " ";
               }
               cout << endl;
            }
        }
};


int main(){

   string str = "BDAACABACDBCDADCCBDA";
   TestGrader t;
   t.setKey(str);

   char ans[20];
   while(true){
      
       for(int i = 0; i<20; i++){
           while(true){
             
              cout << "Enter choice for question " << i+1 << ":";
              cin >> ans[i];
              if (ans[i] == 'A' || ans[i] == 'B' || ans[i] == 'C' || ans[i] == 'D')
                 break;
              else
                 cout << "Invalid input ";
           }
       }
       t.grade(ans);
       cout << "Continue(y/n)?:";
       string ch;
       cin >> ch;
       if (ch[0] == 'n')
          break;
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote