We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
using namespace std;
class Student{
private:
int q1,q2,q3,q4,q5;
public:
void input(){
cin >> q1 >> q2 >> q3 >> q4 >> q5;
}
int calculateTotalScore(){
int score;
score += q1+q2+q3+q4+q5;
return score;
}};
int main() {
int n; // number of students
cin >> n;
Student *s = new Student[n];
for(int i = 0; i < n; i++){
s[i].input();
}
int kristen_score = s[0].calculateTotalScore();
int count = 0;
for(int i = 1; i < n; i++){
int total = s[i].calculateTotalScore();
if(total > kristen_score){
count++;
}
}
cout << count;
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Classes and Objects
You are viewing a single comment's thread. Return to all comments →
include
using namespace std; class Student{ private: int q1,q2,q3,q4,q5; public: void input(){ cin >> q1 >> q2 >> q3 >> q4 >> q5; } int calculateTotalScore(){ int score; score += q1+q2+q3+q4+q5; return score; }}; int main() { int n; // number of students cin >> n; Student *s = new Student[n]; for(int i = 0; i < n; i++){ s[i].input(); } int kristen_score = s[0].calculateTotalScore(); int count = 0; for(int i = 1; i < n; i++){ int total = s[i].calculateTotalScore(); if(total > kristen_score){ count++; } } cout << count; return 0; }