-
Notifications
You must be signed in to change notification settings - Fork 24
/
GradedActivity.h
68 lines (59 loc) · 1.28 KB
/
GradedActivity.h
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
62
63
64
65
66
67
68
#ifndef GRADEDACTIVITY_H
#define GRADEDACTIVITY_H
class GradedActivity
{
protected:
double score;
public:
GradedActivity()
{
score = 0.0;
}
GradedActivity(double s)
{
score = s;
}
// final keyword ensures that the function does not get overridden in a child class
virtual void setScore(double s) final
{
score = s;
}
double getScore() const
{
return score;
}
// virtual functions may be overriden by the child class.
// they also make any function that overrides it virtual.
virtual char getLetterGrade() const;
// virtual destructor allows the child class destructor to execute
virtual ~GradedActivity()
{
// clean up
}
};
char GradedActivity::getLetterGrade() const
{
char letterGrade;
if (score > 89)
{
letterGrade = 'A';
}
else if (score > 79)
{
letterGrade = 'B';
}
else if (score > 69)
{
letterGrade = 'C';
}
else if (score > 59)
{
letterGrade = 'D';
}
else
{
letterGrade = 'F';
}
return letterGrade;
}
#endif