Hey, everyone.
I was wondering if anyone could help me out with this program. Basically, I have to write a code that will grade an exam, which is a set of strings in a file with the first line being the answer key, and the following lines being the student's exams.
"The program will grade a series of exams and then print a grade report for students in a course.
Input: An instructor has a class of students each of whom takes a multiple-choice exam with 10 questions. For each student in the class, there is one line in the input file. The line contains the answers that student gave for the exam. The input file named "grade_data.txt" will have the following format:
line 1: the key for the exam (e.g.)
bccbbadbca
lines 2-n:
a set of answers. You know you are done when you get to a line with no data.
e.g. bccdbadda
Note: You will not know in advance how many exams you have to grade and you don't need to store the exam answers in your program."
This is what I have so far and it's not getting me anywhere. PLEASE HELP.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <iostream>
#include <fstream>
using namespace std;
int gradeExam(string key, string exam);
int main()
{
string key;
string exam;
ifstream infile;
infile.open ("grade_data.txt");
infile >> key;
int gradeExam(string key, string exam);
return 0;
}
int gradeExam(string key, string exam)
{
int i = 0, grade;
grade = 0;
while (exam != " ")
{
if (key[i] == exam[i])
grade = grade + 1;
cout << "Student " << exam[i] << " - " << grade << endl;
i++;
}
return 0; //(instead of returning 0, should I return "grade"?)
}
|