#include <cstdlib>
#include <iostream>
#include <fstream>
usingnamespace std;
int main(int argc, char *argv[])
{
ifstream student_answer;
ifstream correct_answer;
ofstream report;
char student, correct;
int marks, index;
string answer_file, correct_answer_file;
student_answer.open("answer.dat");
if (student_answer.fail())
{
cout << "Answer.dat opening faled.\n";
exit(1);
}
correct_answer.open("booklet.dat");
if (correct_answer.fail());
{
cout << "booklet.dat opening failed.\n";
exit(1);
}
report.open("report.dat");
if (report.fail())
{
cout << "Report.dat opening failed.\n";
exit(1);
}
student_answer.get(student);
correct_answer.get(correct);
index = 1;
while(! student_answer.eof())
{
while(! index > 50)
{
if (student == '\n')
{ if (student = correct)
{
marks = marks + 1;
index = index +1;
student_answer.get(student);
}
}
else
{
index = index + 1;
student_answer.get(student);
}
}
while(! index < 51)
{
while (! student == '\n')
{
report << student_answer;
index = index +1;
cout << student_answer;
student_answer.get(student);
}
if (student == '\n')
{
cout << marks;
report << marks;
report << student_answer;
index = 0;
student_answer.get(student);
}
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
The program is supposed to read from a file called booklet.dat which contains the correct answer for a multiple question (50 questions) exam.
The program then compares this with a file called answer.dat which contains the student's answers with a space followed by a four digit code, space, and then the surname of the student space the marks obtained.
All of this has to be saved to a file called report.dat in he format
6555 Mahmut 10
My program however....
It compiles without being able to open booklet.dat even after
I have created the file manually with a text editor and changed the flename to .dat.
I have also created the answersheet answer.dat manually and typed out the answers so that it may compare it with the student's data which i have also manually typed out
Created the all the files with the correct name and extension.
I would greatly appreciate your input and any comments on style.