-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path11-5grade.cpp
More file actions
61 lines (49 loc) · 1.33 KB
/
11-5grade.cpp
File metadata and controls
61 lines (49 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdexcept>
#include <vector>
#include "grade.h"
#include "median.h"
#include "Student_info.h"
#include "analysis.h"
using std::domain_error; using std::vector;
using std::remove_copy;
double grade(double midterm, double final, double homework)
{
return 0.2 * midterm + 0.4 * final + 0.4 * homework;
}
double grade(double midterm, double final, const vector<double>& hw)
{
if (hw.size() == 0)
return grade(midterm, final, 0);
return grade(midterm, final, median(hw));
}
double agrade(double midterm, double final, const vector<double>& hw)
{
if (hw.size() == 0)
return grade(midterm, final, 0);
return grade(midterm, final, average(hw));
}
double ograde(double midterm, double final, const vector<double>& hw)
{
vector<double> nonzero;
if (hw.size() == 0)
return grade(midterm, final, 0);
remove_copy(hw.begin(), hw.end(), back_inserter(nonzero), 0);
return grade(midterm, final, median(nonzero));
}
// Modified for class Student_info Ch. 9
double Student_info::grade() const
{
return ::grade(midterm, final, homework);
}
double Student_info::agrade() const
{
return ::agrade(midterm, final, homework);
}
double Student_info::ograde() const
{
return ::ograde(midterm, final, homework);
}
//bool fgrade(const Student_info& s)
//{
// return grade(s) < 60;
//}