diff options
| author | Carlos Maiolino <[email protected]> | 2025-09-06 09:37:14 +0200 |
|---|---|---|
| committer | Carlos Maiolino <[email protected]> | 2025-09-06 09:37:14 +0200 |
| commit | 2c9056a23e1a55fd21a8e314c903d9325bffd62e (patch) | |
| tree | a73ba1c7bb60dd89c9e70769dd510e59a49a56a1 /CPP/cpp_book/chap5/grades.cpp | |
| parent | ee8a08bfa24d9a3d09273fdebe8d73ac38c545f9 (diff) | |
Move CPP code here
Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'CPP/cpp_book/chap5/grades.cpp')
| -rw-r--r-- | CPP/cpp_book/chap5/grades.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/CPP/cpp_book/chap5/grades.cpp b/CPP/cpp_book/chap5/grades.cpp new file mode 100644 index 0000000..acbc1e0 --- /dev/null +++ b/CPP/cpp_book/chap5/grades.cpp @@ -0,0 +1,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; +} |
