summaryrefslogtreecommitdiff
path: root/CPP/cpp_book/chap6/grade.cpp
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2026-02-20 16:17:14 +0100
committerCarlos Maiolino <[email protected]>2026-02-20 16:17:14 +0100
commit4ff0e42f65d8bba3d21bed53bfe1251d8db5c13f (patch)
tree9ac61873e2676c3f392bd26063afeb16897c3902 /CPP/cpp_book/chap6/grade.cpp
parentfd313dd5ad9ac067a31f2b1760b85bd305567131 (diff)
extra codeHEADmaster
Diffstat (limited to 'CPP/cpp_book/chap6/grade.cpp')
-rw-r--r--CPP/cpp_book/chap6/grade.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/CPP/cpp_book/chap6/grade.cpp b/CPP/cpp_book/chap6/grade.cpp
new file mode 100644
index 0000000..0a08217
--- /dev/null
+++ b/CPP/cpp_book/chap6/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);
+}
+
+