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

So far this is what I have. I am having trouble passing args into arrays and cal

ID: 3814338 • Letter: S

Question

So far this is what I have. I am having trouble passing args into arrays and calling the arrays. How can I pass the correct answers into setKey? It also says that correctAnswers is uninitialized. This is from chapter 8 of Getting Started with C++ 9th edition so please try to only include material that has been covered that far into the book. Thank you!

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


Create a TestGrader class. The class will have an answers array of 20 characters, which holds the correct test answers. It will also have a student array of 20 characters to hold the student's answers. It will have three public member functions that enable user programs to interact with the class: setKey, setStudent, and grade. The setkey function receives a 20-character string holding the correct answers and copies this information into the answers array. The setStudent function will read in the student's answers from the file student.txt and will store the answers in a 20-character array named student.   The grade method will compare each student answer to the correct answer in the key.

An applicant must correctly answer 15 or more of the 20 questions to pass the exam. After grading the exam, the program should display the following items:

the number of right answers and the number of wrong answers

a list of the question numbers for all incorrectly answered questions

a message indicating whether the applicant passed or failed the exam

Be sure to follow good object-oriented principles in this project.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;


class TestGrader
{
private:
   static const int SIZE = 20;
   char answers[SIZE];
   char student[SIZE];
   int count;

  

public:
   //TestGrader();
   void setKey(char answers[]);
   void setStudent(char student[]);
   void grade(char answers[], char student[]);

};

void TestGrader::setKey(char answers[])
{
   char correctAnswers;
   for (int count = 1; count < SIZE; count++)
   {
       cout << "Please enter the answer for question " << count;
       cout << ": " << correctAnswers;
  
   }
   return;
  
  
}


void TestGrader::setStudent(char student[])
{
   char studentAnswers;
   ifstream inputFile;
   inputFile.open("student.txt");
   for (int count = 1; count < SIZE; count++)
   {
       studentAnswers = student[count];
   }
   return;

}

void TestGrader::grade(char answers[], char student[])
{
   int correct = 1;
   int incorrect = 1;
   for (int count = 1; count < SIZE; count++)
   {
       if (student[count] == answers[count])
       {
           correct++;
       };
   };

   if (correct >= 15)
   {
       cout << " The applicant passed the exam. ";
   }
   else
   {
       cout << " The applicant failed the exam. ";
       cout << "Number of right answers: ";
       cout << SIZE - correct;
       cout << " List of the question numbers for all incorrect answers: ";
       for (int count = 1; count < SIZE; count++)
       {
           if (student[count] != answers[count])
           {
               cout << count;
           };
       };
   };
   return ;
};
//function prototypes

void setKey();
void setStudent();
void grade();


int main()
{
   static const int SIZE = 20;
   TestGrader Test;
   char answers[SIZE];
   char student[SIZE];
   char correctAnswers[SIZE] = { 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C',
   'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A' };
  

   Test.setKey(answers);
   Test.setStudent(student);
   Test.grade(answers, student);

   return 0;
}

Explanation / Answer

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

class TestGrader
{
private:
static const int SIZE = 20;
char answers[SIZE];
char student[SIZE];
int count;
  
public:
//TestGrader();
void setKey(char answers[]);
void setStudent(char student[]);
void grade(char answers[], char student[]);
};
void TestGrader::setKey(char answers[])
{
char correctAnswers;
for (int count = 1; count < SIZE; count++)
{
cout << "Please enter the answer for question " << count;
cout << ": " << correctAnswers;
  
}
return;
  
  
}

void TestGrader::setStudent(char student[])
{
char studentAnswers;
ifstream inputFile;
inputFile.open("student.txt");
for (int count = 1; count < SIZE; count++)
{
studentAnswers = student[count];
}
return;
}
void TestGrader::grade(char answers[], char student[])
{
int correct = 1;
int incorrect = 1;
for (int count = 1; count < SIZE; count++)
{
if (student[count] == answers[count])
{
correct++;
};
};
if (correct >= 15)
{
cout << " The applicant passed the exam. ";
}
else
{
cout << " The applicant failed the exam. ";
cout << "Number of right answers: ";
cout << SIZE - correct;
cout << " List of the question numbers for all incorrect answers: ";
for (int count = 1; count < SIZE; count++)
{
if (student[count] != answers[count])
{
cout << count;
};
};
};
return ;
};
//function prototypes
void setKey();
void setStudent();
void grade();

int main()
{
static const int SIZE = 20;
TestGrader Test;
char answers[SIZE];
char student[SIZE];
char correctAnswers[SIZE] = { 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C',
'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A' };
  
Test.setKey(correctAnswers);
Test.setStudent(student);
Test.grade(answers, student);
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