-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day12_Inheritance.cpp
80 lines (72 loc) · 1.89 KB
/
Day12_Inheritance.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
// THE PROBLEM
// ***************************
// You are given two classes, Person and Student, where Person is the base class and Student is the derived class.
// compute the average given the information and output that via a function call to the student->calculate function in the main.
// Solution Created By: Dustin Kaban
// Date: June 4th, 2020
// ***************************
#include <iostream>
#include <vector>
using namespace std;
class Person{
protected:
string firstName;
string lastName;
int id;
public:
Person(string firstName, string lastName, int identification){
this->firstName = firstName;
this->lastName = lastName;
this->id = identification;
}
void printPerson(){
cout<< "Name: "<< lastName << ", "<< firstName <<"\nID: "<< id << "\n";
}
};
class Student : public Person{
private:
vector<int> testScores;
public:
Student(string firstName, string lastName, int id, vector<int> scores) : Person(firstName, lastName, id)
{
this->testScores = scores;
}
/*
* Function Name: calculate
* Return: A character denoting the grade.
*/
// Write your function here
char calculate()
{
int avg = 0;
for(int i=0;i<testScores.size();i++)
{
avg += testScores[i];
}
avg = avg/testScores.size();
if(avg >= 90)
{
return 'O';
}
else if(avg >= 80)
{
return 'E';
}
else if(avg >= 70)
{
return 'A';
}
else if(avg >= 55)
{
return 'P';
}
else if(avg >= 40)
{
return 'D';
}
else
{
return 'T';
}
}
};