/*
https://www.hackerrank.com/challenges/30-inheritance/problem
The key of this problem is how to make Subclss Constructors.
<<How?>>
Student(string firstName, string lastName, int id, vector<int> scroes) : Person(firstName,lastName,id)
*/
class Student : public Person{
private:
vector<int> testScores;
public:
/*
* Class Constructor
*
* Parameters:
* firstName - A string denoting the Person's first name.
* lastName - A string denoting the Person's last name.
* id - An integer denoting the Person's ID number.
* scores - An array of integers denoting the Person's test scores.
*/
Student(string firstName, string lastName, int id, vector<int> scroes) : Person(firstName,lastName,id)
{
this->testScores = scroes;
}
/*
* Function Name: calculate
* Return: A character denoting the grade.
*/
string calculate(){
int sum = 0, avg = 0;
int size = testScores.size();
for(int i=0;i<size;i++){
sum += testScores[i];
}
avg = sum/size;
if(avg >= 90 && avg <=100) {
return "O";
} else if (avg >= 80 && avg < 90) {
return "E";
} else if (avg >= 70 && avg < 80) {
return "A";
} else if (avg >= 55 && avg < 70) {
return "P";
} else if (avg >= 40 && avg < 55) {
return "D";
} else if (avg < 40) {
return "T";
} else {
return "error";
}
return "error";
}
};
댓글 없음:
댓글 쓰기