diff options
Diffstat (limited to 'CPP/cpp_book/chap5/grade.cpp')
| -rw-r--r-- | CPP/cpp_book/chap5/grade.cpp | 27 |
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); +} + + |
