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

Must be done in C+ Homework VII COMSC-44 Exam Grader – Vector Version Rewrite Ho

ID: 3815043 • Letter: M

Question


Must be done in C+

Homework VII
COMSC-44
Exam Grader – Vector Version
Rewrite Homework 7a, assuming that you have no idea what the size of the
CorrectAnswer file is. Since you don’t know how big the file is (i.e. how many
multiple choice questions there were to grade), then a better choice of sequence
containers might be the vector instead of the array. Use the same files,
CorrectAnswers.txt, and StudentAnswers.txt, as before but this time determine the
number of questions to grade from the size of the Vector that you make when you load
all CorrectAnswers.txt into the CorrectAnswer Vector. You will then want to check
to be sure that the StudentAnswers.txt file contains the same number of answers as the
CorrectAnswers file, when you load those into a second Vector holding
StudentAnswers. Below are the requirements for this program.
• The output should look pretty much the same as that in Homework 7A.
• Name your program: YourName-HwrkVII.cpp .
• A list of the questions (by number) missed by the Student, showing the correct
answer, and the incorrect answer provided by the student for each missed
question.
• The total number of questions missed.
• The percentage of questions answered correctly.
• Make sure your name is displayed along with your data.
• Also, always be sure that your name appears as a comment at the top of your
program.
• Your program should test to be sure that there are the same number of answers
given in the StudentAnswers.txt file as there are Questions in the
CorrectAnswers.txt file.
o If there are not, then the program should stop, displaying on the screen
that the StudentAnswers.txt file does not have the same number of
answers as there are questions. You can use a cin.get(); to hold the error
display on the screen.
• Be sure to use Vectors, not Arrays, to obtain your result.
• Do not make the assumption that the CorrectAnswers.txt file and the
StudentAnswers.txt file have only 20 questions. They could have any number.
Below is a re-statement of Homework07A.
One of your professors has asked you to write a program to grade the final exams,
which consist of only 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, containing a student’s answers,
called StudentAnswers.txt, 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 (by number) missed by the Student, showing the correct
answer, and the incorrect answer provided by the student for each missed
question.
• The total number of questions missed.
• The percentage of questions answered correctly.


// Exam Grader
#include
#include
#include
#include
using namespace std;
const int MAXNUM= 20;
int main()
{
// Read in the Correct Answers from its file and put them in the answers[] Array
ifstream inputFile;
inputFile.open("CorrectAnswers.txt");
char answers[MAXNUM];
for (int i=0; i {
if( !(inputFile >> answers[i]))
{
cout << "Your answers file has less than 20 entries. ";
exit(0);
}
} inputFile.close();
// Read in the Student Answers from its file and put them in the studentAns[] Array
ifstream inFile;
inFile.open("StudentAnswers.txt");
char studentAns[MAXNUM];
for (int i=0; i {
if( !(inFile >> studentAns[i]))
{
cout << "Your student's file has less than 20 entries. ";
exit(0);
}
} inFile.close();

// Now compare the Student Answers to the Correct Answers and output wrong answers and correction
int numberWrong=0;
int questNum;
double percentage;
cout << "Gordon Moore's Grader ";
for (int i=0; i {
if (answers[i] != studentAns[i])
{
cout << "Question " << i+1 << ": Answer given = " << studentAns[i]
<< " Correct Answer " << answers[i] << endl;
numberWrong++;
}
}
// Now output the percent correct on the quiz
cout << fixed << showpoint << setprecision(2);
percentage = 100.00*(MAXNUM- numberWrong)/MAXNUM;
cout << "The percentage correct is: " << percentage << "% ";
return 0;
}

Must be done in C++

o MetroPCS 56% 3:40 PM desiree 2learn.4cd.edu Rewrite Homework 7a, assuming that you have no idea what the size of the CorrectAnswer file is. Since you don't know how big the file is (ie how many multiple choice questions there were to grade), then a better choice ofsegwemce containers might be the vector instead of the amay, Use the same files, and StudentAnswers tut, as before but this time determine the number of questions to grade from the size of the Vector that you make when you load txt into the CorrectAnswer Vector. You will then want to check to be sure that the StudentAnswerstxt file contains the same number of answers as the CorrectAnswers file, when you load those into a second Vector holding Below are the requirements for this program. The output should look pretty much the same as that in Homework 7A Name your program: YourName-HwrkVIIepp A list of the questions (by number missed by the Student, showing the conrect answer, and the incomect answer provided by the student for each missed question The total number of questions missed The percentage of questions answered comectly. Make sure your name is displayed along with your data. at the top of your Also, always be sure that your name appears as a Your program should test to be sure that there are the same number of answers given in the StudentAnswers.bt file as there are Questions in the CorrectAnswers. txt file. o If there are not, then the program should stop displaying on the screen hat the StudentAnswers.txt file does not have the same numberof answers as there are questions. You can use a cin. get0 to hold the error display on the screen. Be sure to use Vectors, mot Arrays, to obtain your result. Do not make the assumption that the C file and the StudentAnswerstxt file have only 20 questions. They could have any number. Below is a re-statement of Homework07A. One of your professors has asked you to write a program to grade the final exams. which consist of only multiple-choice questions. Each question has one of four possible answers. A, B, C, or D. The file CorrectAnswers.but contains the connect answers for all of the questions, with each answer written on a separate line. The first ine 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 file into a char amay, and then reads the contents of another file, containing a student's answers, called StudentAnswers txt, 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 (by number) missed by the Student, showing the correct answer, and the incomect answer provided by the student for each missed question. The total number ofquestions missed. The percentage of questions answered comectly

Explanation / Answer

Here is modified version of your program with vectors.

// Exam Grader
#include <iostream>
#include <fstream>
#include <vector>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main()
{
// Read in the Correct Answers from its file and put them in the answers[] Array
ifstream inputFile;
inputFile.open("CorrectAnswers.txt");
vector<char> answers;
char ans;
while ((inputFile >> ans))
{
answers.push_back(ans);
}
inputFile.close();

// Read in the Student Answers from its file and put them in the studentAns[] Array
ifstream inFile;
inFile.open("StudentAnswers.txt");
vector<char> studentAns;
while(inFile >> ans)
{
studentAns.push_back(ans);
}
inFile.close();

// Now compare the Student Answers to the Correct Answers and output wrong answers and correction
int numberWrong=0;
int questNum;
double percentage;
if (studentAns.size() != answers.size())
{
cout << "Size of student answers and answers do not match." << endl;
exit(0);
}
cout << "Gordon Moore's Grader ";
for (int i=0; i < answers.size(); i++)
{
if (answers[i] != studentAns[i])
{
cout << "Question " << i+1 << ": Answer given = " << studentAns[i]
<< " Correct Answer " << answers[i] << endl;
numberWrong++;
}
}
// Now output the percent correct on the quiz
cout << fixed << showpoint << setprecision(2);
int numOfQuestions = answers.size();
percentage = 100.00*(numOfQuestions - numberWrong)/numOfQuestions;
cout << "The percentage correct is: " << percentage << "% ";
return 0;
}

Sample output

Gordon Moore's Grader
Question 6: Answer given = A Correct Answer B
Question 11: Answer given = C Correct Answer D
Question 17: Answer given = B Correct Answer A
Question 24: Answer given = C Correct Answer B
The percentage correct is: 83.33%

Please rate positively if this solved your question.