-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent_info.cpp
More file actions
50 lines (39 loc) · 1.08 KB
/
Student_info.cpp
File metadata and controls
50 lines (39 loc) · 1.08 KB
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
43
44
45
46
47
48
49
50
/*
From Acellerated C++
Student_info.cpp
Stephen King
8/12/17
*/
#include "Student_info.h"
using std::istream; using std::vector; using std::endl;
// Predicate used to sort Students
bool less_than(const Student_info& x, const Student_info& y)
{
return x.name < y.name;
}
// Read homework grades into hw vector
istream& read_hw(istream& in, vector<double>& hw)
{
// use input stream to read grades into hw
if (in) {
// Empty Vector of any previous results
hw.clear();
// Read homework grades until EOF or invalid data
double x;
while (in >> std::dec >> x)
hw.push_back(x);
// Clear Error state for next read attempt
in.clear();
}
return in;
}
// Read and store the students name and grades
istream& read(istream& in, Student_info&s)
{
// Read Students name, midterm and final grades
in >> s.name >> s.midterm >> s.final;
//std::cout << endl << "Name = " << s.name;
// Read Students homework grades
read_hw(in, s.homework);
return in;
}