From 4ff0e42f65d8bba3d21bed53bfe1251d8db5c13f Mon Sep 17 00:00:00 2001 From: Carlos Maiolino Date: Fri, 20 Feb 2026 16:17:14 +0100 Subject: extra code --- CPP/cpp_book/chap6/grades.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 CPP/cpp_book/chap6/grades.cpp (limited to 'CPP/cpp_book/chap6/grades.cpp') diff --git a/CPP/cpp_book/chap6/grades.cpp b/CPP/cpp_book/chap6/grades.cpp new file mode 100644 index 0000000..acbc1e0 --- /dev/null +++ b/CPP/cpp_book/chap6/grades.cpp @@ -0,0 +1,63 @@ +#include // IO Manipulators +#include +#include +#include +#include +#include +#include +#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 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::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::iterator i = fail.begin(); + i != fail.end(); + i++) { + std::cout << i->name << std::endl; + } + + return 0; +} -- cgit v1.2.3