#ifndef GUARD_Student_info
#define GUARD_Student_info
class Student_info {
public:
Student_info();
Student_info(std::istream&);
std::string name() const { return n; }
bool valid() const { return !homework.empty(); }
std::istream& read(std::istream&);
double grade() const;
private:
std::string n;
double midterm, final;
std::vector<double> homework;
};
bool compare(const Student_info&, const Student_info&);
#endif
double Student_info::grade() const
{
return ::grade(midterm, final, homework);
}
bool compare(const Student_info& x, const Student_info& y)
{
return x.name() < y.name();
}
Student_info::Student_info(): midterm(0), final(0) { }
Student_info::Student_info(std::istream& is) { read(is); }
#include <string>
std::istream& Student_info::read(std::istream& in)
{
in >> n >> midterm >> final;
::read_hw(in, homework);
return in;
}
int main(int argc, char* argv[])
{
using namespace std;
vector<Student_info> students;
Student_info record;
while (record.read(cin)) {
students.push_back(record);
}
sort(students.begin(), students.end(), compare);
// write the names and grades
for (vector<Student_info>::size_type i = 0; i != students.size(); ++i) {
... students[i].name() ...
}
return 0;
}