Question
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 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 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
it should indicate that the students failed the test.
COPYABLE CODE
Explanation / Answer
// Pound includes #include #include #include #include #include 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 correctAnswers[MAX_SIZE]; char studentAnswers[MAX_SIZE]; // Total number of questions int numOfQuestions; // Student Correct Answers int studentNumCorrect; // Any other variables would be considered temporary and can be // declared when you use them }; // Function Prototypes void printHeader(string, string, string, string); int readData(string, char []); // Input Function read a character array void scoreTest(TestData); void printResults(TestData); // Definition of the program function int main(void) { // Call the splash screen function printHeader("Your Name", "CMPSC 121", "Date", "Program Description"); // Create an object to hold the test question data TestData midterm; // Pass the object to a function score the test scoreTests(midterm); // Needs three of the four arrays // Call the printResults function to print the results by passing the // object return 0; } void scoreTests(TestData test) { // SCORETESTS scoreTest(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: // // Use readData function (twice) to read in the array data // Compare the two arrays to determine the test grade return; } 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()) { // File opened so enter the data // Using a loop while(inStream >> tempChar) { size++; // Update the counter // Copy character into array inArray[size] = tempChar; } } else { // File did not open so throw and error message cout