blob: a55338b0f8e612024341ae7f44608c4f9914dc3d (
plain)
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
|
#include "student_info.h"
bool compare_students(const StudentInfo& a, const StudentInfo& b)
{
return a.name < b.name;
}
std::istream& read_homework(std::istream& in, std::vector<double>& hw)
{
if (in) {
hw.clear(); // Empty the vector.
double x;
/*
* Loop invariant:
* - 'homework' contains all the homework grades read so far
*/
while (in >> x)
hw.push_back(x);
in.clear(); // Clear the stream in case
// it will be used again.
}
return in;
}
std::istream& read_student(std::istream& is, StudentInfo& s)
{
/* Read and store student's name, midterm and final */
is >> s.name >> s.midterm >> s.final;
read_homework(is, s.homework);
return is;
}
|