blob: acbc1e0536fabce2e01ff87c0a0b6d2d98f73f3b (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#include <iomanip> // IO Manipulators
#include <ios>
#include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <stdexcept>
#include "grade.h"
#include "student_info.h"
#include "approval.h"
using std::cin; using std::string;
using std::cout; using std::endl;
int
main(void)
{
std::list<StudentInfo> students, fail;
StudentInfo record;
string::size_type maxlen = 0;
while (read_student(cin, record)) {
maxlen = std::max(maxlen, record.name.size());
students.push_back(record);
}
students.sort(compare_students);
for (std::list<StudentInfo>::iterator i = students.begin();
i != students.end();
i++) {
cout << i->name
<< string(maxlen + 1 - i->name.size(), ' ');
try {
double final_grade = grade(*i);
std::streamsize prec = cout.precision();
cout << std::setprecision(3) << final_grade
<< std::setprecision(prec);
cout << " - Student "
<< (fgrade(*i) ? "Failed" : "Approved");
} catch (std::domain_error& e){
cout << e.what();
}
cout << endl;
}
fail = extract_fails(students);
std::cout << "Failed students: " << std::endl;
for (std::list<StudentInfo>::iterator i = fail.begin();
i != fail.end();
i++) {
std::cout << i->name << std::endl;
}
return 0;
}
|