blob: 3c8f19a36f12bc6a6a6ef487c6b89f6565b730cb (
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include <iomanip> // IO Manipulators
#include <ios>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdexcept>
#include "grade.h"
#include "student_info.h"
using std::cin; using std::string;
using std::cout; using std::endl;
int
main(void)
{
std::vector<StudentInfo> students;
StudentInfo record;
string::size_type maxlen = 0;
while (read_student(cin, record)) {
maxlen = std::max(maxlen, record.name.size());
students.push_back(record);
}
sort(students.begin(), students.end(), compare_students);
for (std::vector<StudentInfo>::size_type i = 0;
i != students.size();
i++) {
cout << students[i].name
<< string(maxlen + 1 - students[i].name.size(), ' ');
try {
double final_grade = grade(students[i]);
std::streamsize prec = cout.precision();
cout << std::setprecision(3) << final_grade
<< std::setprecision(prec);
} catch (std::domain_error& e){
cout << e.what();
}
cout << endl;
}
return 0;
}
|