From 2c9056a23e1a55fd21a8e314c903d9325bffd62e Mon Sep 17 00:00:00 2001 From: Carlos Maiolino Date: Sat, 6 Sep 2025 09:37:14 +0200 Subject: Move CPP code here Signed-off-by: Carlos Maiolino --- CPP/cpp_book/chap3/grades.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 CPP/cpp_book/chap3/grades.cpp (limited to 'CPP/cpp_book/chap3/grades.cpp') diff --git a/CPP/cpp_book/chap3/grades.cpp b/CPP/cpp_book/chap3/grades.cpp new file mode 100644 index 0000000..3c8f19a --- /dev/null +++ b/CPP/cpp_book/chap3/grades.cpp @@ -0,0 +1,48 @@ +#include // IO Manipulators +#include +#include +#include +#include +#include +#include +#include "grade.h" +#include "student_info.h" + +using std::cin; using std::string; +using std::cout; using std::endl; + +int +main(void) +{ + std::vector 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::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; +} -- cgit v1.2.3