Skip to content

Instantly share code, notes, and snippets.

@p77u4n
Last active August 7, 2020 14:34
Show Gist options
  • Save p77u4n/b51fb27fb68d72a6c68164d5a8914239 to your computer and use it in GitHub Desktop.
Save p77u4n/b51fb27fb68d72a6c68164d5a8914239 to your computer and use it in GitHub Desktop.
Khang code
#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 identification,vector<int>scores) : Person(firstName, lastName,identification),testScores(scores){}
char calculate(){
int trungbinh=0;
for(int i=0;i<testScores.size();i++){
trungbinh =trungbinh + testScores[i];
}
trungbinh=trungbinh/testScores.size();
if(trungbinh>=90){return 'O';}
else if(trungbinh>=80){return 'E';}
else if(trungbinh>=70){return 'A';}
else if(trungbinh>=60){return 'P';}
else if(trungbinh>=50){return 'D';}
else if(trungbinh>=40){return 'T';}
}
};
int main() {
string firstName;
string lastName;
int id;
int numScores;
cin >> firstName >> lastName >> id >> numScores;
vector<int> scores;
for(int i = 0; i < numScores; i++){
int tmpScore;
cin >> tmpScore;
scores.push_back(tmpScore);
}
Student* s = new Student(firstName, lastName, id, scores);
s->printPerson();
cout << "Grade: " << s->calculate() << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment