I needed some C++ practice (I've been stuck in strictly-C world for far too long) so I did this program as a quick exercise. There are a number of ways to get the data in, but this is one way.
Code:
bool Seminar::loadData(const string &filename)
{
ifstream s;
s.open(filename.c_str(), ios::in);
if (!s.is_open())
{
cerr << "Unable to open " << filename << endl;
return false;
}
while (!s.eof())
{
// First, get the student's name into a string.
string name;
s >> name;
if (name == "")
continue; //blank line...skip it
// OK, create the student.
Student st(name);
while (true)
{
// Read the grades until you find the sentinel values.
string classname;
double grade;
s >> classname >> grade;
if (classname == STOP_SIGNAL && grade == STOP_GRADE)
break; // Found the sentinels, so get out.
// Create a grade
Grade g(classname, grade);
// Add the grade to the student's record
st.addGrade(g);
}
// Add the student to the seminar's class list.
theStudents.push_back(st);
}
// Close the open file.
s.close();
return true;
}