I need to read a set of data from a file into a vector.First column contains the names of the student and other two contain their grades. Then from a vector I need to calculate which student have passed using function grade. This is one of the tasks from Accelerated C++. I assume I had made a mistake in read function.
//Student_info.cpp
#include "Student_info.h"
#include "grade.h"
using std::istream; using std::vector;
bool compare(const Student_info& x, const Student_info& y)
{
return x.name < y.name;
}
istream& read(istream& is, Student_info& s)
{
// read and store the student's name and midterm and final exam grades
is >> s.name >> s.midterm >> s.final;
read_hw(is, s.homework); // read and store all the student's homework grades
return is;
}
istream& read_hw(istream& in, vector<double>& hw)
{
if (in)
{
// get rid of previous content
hw.clear();
// read homework grades
double x;
while (in >> x)
hw.push_back(x);
// clear the stream so that input will work for the next student
in.clear();
}
return in;
}
vector<Student_info> extract_fails(vector<Student_info>& students)
{
vector<Student_info> fail;
vector<Student_info>::iterator iter = students.begin();
while (iter != students.end()) {
if (fgrade(*iter)) {
fail.push_back(*iter);
iter = students.erase(iter);
} else
++iter;
}
return fail;
}