Input from file and Sorted output to a different file

I have a problem. I've to make project that takes input from one file, that contains names of students and their answers to a test, then I have to count the numbers of right, wrong and blank answers, amount of points and if they suceeded or failed the test, and then sort out this information to a different file (from the highest grade to the lowest).

this is what I have right now.

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
 #include <iostream>
#include <fstream>
#include <string>

using namespace std;

struct Students{
  string name, surname;
  string q1, q2, q3, q4, q5;
};

bool readStudents(ifstream &fromStream, Students &a) {
    getline(fromStream, a.name, ',');
    getline(fromStream, a.surname, ',');
    getline(fromStream, a.q1, ',');
    getline(fromStream, a.q2, ',');
    getline(fromStream, a.q3, ',');
    getline(fromStream, a.q4, ',');
    getline(fromStream, a.q5);    
 return true;
}


bool writeStudents(ostream &toStream, Students a) {
    toStream << a.name << "\t" << a.surname  << "\t"
             << a.q1  << "\t" <<  a.q2  << "\t" << a.q3 <<
             "\t" << a.q4 << "\t" << a.q5 << endl;
 return true;
}

int main()
{
    string name = "input.csv";
    string name2 = "output.csv";

    ifstream iF(name.c_str());
    if (iF == NULL) {
      cout << "CSV file open error" << endl;
      return -1;
    }

    Students students;
    while (!iF.eof()) {
        readStudents(iF, students);
        writeStudents(cout, students);
    }
    iF.close();

    return 0;
}


So, I presume I should use arrays? Any help would be much appreciated
Last edited on
The keyword there is "Sort" when you want to sort something it's possible to do it without an array but probably easier to do with.
Topic archived. No new replies allowed.