Creating a file, comparing answer sheet with student data.

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <cstdlib>
#include <iostream>
#include <fstream> 

using namespace 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.
Are you running the program from a different directory as the one that has the .dat files?

Try using the full path on the file name.
Topic archived. No new replies allowed.