Question 3
Basically what I did was read the whole memorandum into an array and then use the array to compare the characters to the individual characters read one by one from the answer file intil I got to the last answer.
Something like this:
Language: C++
// Read in all the correct answers into an array.
for(int i = 0; i < ARRAY_SIZE; i++)
correctAnswerFile >> correctAnswerArray[i];
I then used a while loop to test for the end of file and compare and record the correct answers.
Finally, I used an if loop to test for the end of the answers using the ARRAY_SIZE constant for the test. In this cast the size is 50. If true, the program then reads the student ID and Name into two seperate variables and everything is then sent to the output file report.dat
The answer counter andd array counter is then zero'd and ready for the next student's info.
Something like this:
Language: C++
// Begin comparing the student answers to the memorandum answers in booklet.dat
while(!studentAnswerFile.eof())
{
char studentAnswer;
studentAnswerFile>> studentAnswer; //read the character into the variable
if(studentAnswer == correctAnswerArray[studentAnswerCounter++]) //compare answers
numberCorrectAnswers++; //add a mark
if(studentAnswerCounter == ARRAY_SIZE) //check for end of one student';s answers.
{
That's about it. the rest of the function does a straighforward output to the report.dat file and that's it. Remember to zero the studentAnswerCounter and numberCorrectAnswers variables.
Hope this helps.
Chris Botha
=============================
Far and away the best prize that life has to offer is the chance to work hard at work worth doing.
Theodore Roosevelt