QUESTION: One of your professors has asked you to write a program to grade her f
ID: 3820891 • Letter: Q
Question
QUESTION:
One of your professors has asked you to write a program to grade her final test which consist of 20 multiple-choice questions. Each question has one of four possible answers: A, B, C, or D. The file CorrectAnswers.txt contains the correct answers for all of the questions with each answer written on a separate line. The first line contains the answer to the first question, the second line contains the answer to the second question, and so forth. Write a program that reads the contents of the CorrectAnswers.txt file into a char array, and then reads the contents of another file that contains a student's answers into a second char array. The program should determine the number of questions that the student missed and then display the following
A list of the questions missed by the student showing the correct an- swer and the incorrect answer provided by the student for each missed question.
The total number of questions missed.
The percentage of the questions answered correctly.
If the percentage of correctly answered questions is 70% or greater the program should indicate that the student passed the test. Otherwise it should indicate that the students failed the test.
COPYABLE CODE
1:44 AM ...oo Verizon Please do the complete program using the copyable code format provided. Thanks in advance!! QUESTION One of your professors has asked you to write a program to grade her final test which consist of 20 multiple-choice questions. Each question has one of four possible answers: A, B, C,or D. The file C contains the correct answers for all of the questions with each answer written on a separate line. The first line contains the answer to the first question, the second line contains the answer to the second question, and so forth. Write a program that reads the contents ofthe txt file into a char array, and then reads the contents of another file that contains a stu dent's answers into a second char array. The program should determine the number of questions that the student missed and then display the following A list of the questions missed by the student showing the correct an swer and the incorrect answer provided by the student for each missed question The total number of questions missed. The percentage of the questions answered correctly. If the percentage of correctly answered questions is 70% or greater the program should indicate that the student passed the test. Otherwise should indicate that the students failed the test. COPYABLE CODE Pound includes fincludeKiostreamp- Finclude cfstreano fincludecionani Finclude string finclude comath using namespace std: Set a MAX SIZE for the arrays make it a constant Class Definitions class TestData Public Char arrays for employee IDs and hours worked char corr ect Answers MAX SIZEJi tudent Answers[MAX SIZE11 Total n umber of guestions int nunof Questions: student Correct Answer int studentNuncorrecti Any other variables would be considered temporary and can be declared when you use them Function Prototypes void print Header(string string string string): int read Data (string char Input Function read a character array void scorelest(TestData void print Results (TestData); Definition of the program function int nain void) call the splash screen function Print Header ("Your Name "CMPsc 121 Date Program Description create an object to hold the test guestion data Test Data midterm Pass the object to a function score the test score Tests (midterm): Needs three of the four arrays call the printResults function to print the results by passing theExplanation / Answer
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
#include <cmath>
using namespace std;
const int MAX_SIZE = 20;
class ExamData
{
public:
char correctAnswers[MAX_SIZE];
char studentAnswers[MAX_SIZE];
int numOfQuestions;
int studentNumCorrect;
};
void printHeader(string, string, string, string);
int readData(string, char[]);
void scoreExams(ExamData);
void printResults(ExamData);
int main()
{
// Call the splash screen function
printHeader("Your Name", "CMPSC 121", "Date", "Program Description");
// Create an object to hold the test question data
ExamData midterm;
// Pass the object to a function score the test
scoreExams(midterm);
// Call the printResults function to print the results by passing the object
printResults(midterm);
return 0;
}
void scoreExams(ExamData exam)
{
// SCORETESTS scoreTests(TestData test) is passed an object of the class
// TESTData. It then calls the input functions to 1.) read the character
// data into an array to be used for the correct answers. It calls the
// function a second time to read the student's answers into another
// array.
// Using both arrays and a for loop the function grades the student's
// test recording the number of correct answers and the percentage
// earned into the appropriate variables;
//
// Name:
// Course: CMPSC 121
// Date:e
//
// Use readData function (twice) to read in the array data
exam.numOfQuestions = readData("CorrectAnswers.txt", exam.correctAnswers);
int numAnswers = readData("StudentAnswers.txt", exam.studentAnswers);
// Compare the two arrays to determine the test grade
exam.studentNumCorrect = 0;
for(int i = 0; i < exam.numOfQuestions; i++)
if(exam.correctAnswers[i] == exam.studentAnswers[i])
exam.studentNumCorrect++;
}
int readData(string fileName, char inArray[])
{
// READDATA readData(int inArray[]) READDATA is a function that will
// open a file whose name is passed to the function. It then reads the
// data into a character array returning the number of elements in the
// array.
//
// Name: Prof. Adams
// Course: CMPSC 121
// Date: 13 April 2017
//
// Create a file stream
ifstream inStream;
// Initialize a counter to -1 - indicates failure if nothing is read
int size = -1;
// Temporary character variable
char tempChar;
// Open the file
inStream.open(fileName);
// Check that the file opened
if(!inStream.fail())
{
while(inStream >> tempChar)
{
size++;
inArray[size] = tempChar;
}
}
else
{
cout << "File: " << fileName << " failed to open ";
exit(1);
}
return size+1;
}
void printHeader(string name, string course, string dueDate, string description) {
// PRINTHEADER printHeader(string, string, string, string) is the
// function used to hide away the splash screen
//
// Name: Prof. Adams
// Course: CMPSC 121
// Date: 12 March 2017
//
// Print the splash screen
cout << endl;
cout << name << endl;
cout << course << endl;
cout << dueDate << endl;
cout << description << endl;
cout << endl;
return;
}
void printResults(ExamData exam)
{
// PRINTRESULTS printResults(Payroll employeeData) is the
// function used to print the results of the program. It is
// passed a copy of the object currently holding the arrays and
// number of employees.
//
// Name:
// Course: CMPSC 121
// Date:
//
cout << "Correct Answers: ";
for(int i = 0; i < exam.numOfQuestions; i++)
cout << exam.correctAnswers[i] << " ";
cout << endl;
cout << "Student Answers: ";
for(int i = 0; i < exam.numOfQuestions; i++)
cout << exam.studentAnswers[i] << " ";
cout << endl;
cout << "Percentage of score: " << exam.studentNumCorrect / (double)exam.numOfQuestions * 100 << "%" << endl;
}
Here is the code for you: