I was wondering if someone could tell me how I could do this:
I had to write this program for an exam last week and I was never clear how to do this, so I know I missed this question but I still need to know how it is done for future reference.
The idea is that I have a file named "TheGrades.txt"
So in this file, there are names with grade IDs and then grades written like this:
Maria Final 82 Midterm 65 Quiz 98 STOP -1
Tom Final 90 Midterm 84 Quiz 46 STOP -1
John Final 54 Midterm 54 Quiz 87 STOP -1
I have created have 3 classes in the program.
The idea is to use ifstream to input each line and when it gets to STOP -1, that is the end of the grades for that particular student.
I don't need to know how to write the program, I just want to know how I can input several things of different data types (strings and doubles) through ifstream because I feel like I have missed something in class pertaining to this.
After this we are supposed to output each student and the grades they recieved. I know I haven't written any functions in the program, but I just want to know how to use the ifstream (or maybe I use istream& as a parameter placeholder??) anyway, any advice would be great! Thank you!
I will try to demonstrate
Code:#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Grade
{
public:
private:
string ID;
double score;
};
class Student
{
public:
private:
string mName;
vector <Grade> theGrades;
};
class Seminar
{
public:
private:
vector <Student> theStudents;
};
int main()
{
return 0;
}