-
Notifications
You must be signed in to change notification settings - Fork 1
/
9-7Student_info.cpp
42 lines (34 loc) · 998 Bytes
/
9-7Student_info.cpp
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
35
36
37
38
39
40
41
42
// source file for Student_info-related functions
#include "Student_info.h"
#include "grade.h"
using std::istream; using std::vector;
using std::cout; using std::endl;
bool compare(const Student_info& x, const Student_info& y)
{
return x.name() < y.name(); // Modified for class Student_info Ch. 9
}
// Modified for class Student_info Ch. 9
istream& Student_info::read(istream& is)
{
cout << "step0" << endl;
is >> n >> midterm >> final;
cout << "step1" << endl;
read_hw(is, homework);
cout << "step2" << endl;
finalGrade = ::grade(midterm, final, homework);
return is;
}
istream& Student_info::read_hw(istream& in, vector<double>& hw)
{
if (in) {
// get rid of previous contents
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;
}