summaryrefslogtreecommitdiff
path: root/CPP/cpp_book/chap5/grade.cpp
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2025-09-06 09:37:14 +0200
committerCarlos Maiolino <[email protected]>2025-09-06 09:37:14 +0200
commit2c9056a23e1a55fd21a8e314c903d9325bffd62e (patch)
treea73ba1c7bb60dd89c9e70769dd510e59a49a56a1 /CPP/cpp_book/chap5/grade.cpp
parentee8a08bfa24d9a3d09273fdebe8d73ac38c545f9 (diff)
Move CPP code here
Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'CPP/cpp_book/chap5/grade.cpp')
-rw-r--r--CPP/cpp_book/chap5/grade.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/CPP/cpp_book/chap5/grade.cpp b/CPP/cpp_book/chap5/grade.cpp
new file mode 100644
index 0000000..0a08217
--- /dev/null
+++ b/CPP/cpp_book/chap5/grade.cpp
@@ -0,0 +1,27 @@
+#include <vector>
+#include "student_info.h"
+#include "median.h"
+#include "grade.h"
+
+double grade(double midterm, double final, double homework)
+{
+ return (midterm * 0.2 +
+ final * 0.4 +
+ homework * 0.4);
+}
+
+/* Overloads above grade() */
+double grade(double midterm, double final, const std::vector<double>& hw)
+{
+ if (hw.size() == 0)
+ throw std::domain_error("Student has no homework");
+
+ return grade(midterm, final, median(hw));
+}
+
+double grade(const StudentInfo& s)
+{
+ return grade(s.midterm, s.final, s.homework);
+}
+
+