You are viewing a single comment's thread. Return to all comments →
`#include
using namespace std;
class Student { private: int scores[5]; public: void input(); int calculateTotalScore(); };
void Student::input() { for(int i = 0; i < 5; i++) { cin >> scores[i]; } }
int Student::calculateTotalScore() { int sum = 0; for(int i = 0; i < 5; i++) { sum += scores[i]; } return sum; }
int main() { int n; cin >> n; Student a[n]; for(int i = 0; i < n; i++) { a[i].input(); } int cnt = 0; for(int j = 1; j < n; j++) { if(a[j].calculateTotalScore() > a[0].calculateTotalScore()) cnt++; } cout << cnt; return 0; } `
Seems like cookies are disabled on this browser, please enable them to open this website
Classes and Objects
You are viewing a single comment's thread. Return to all comments →
`#include
using namespace std;
class Student { private:
int scores[5]; public: void input(); int calculateTotalScore(); };
void Student::input() { for(int i = 0; i < 5; i++) { cin >> scores[i]; } }
int Student::calculateTotalScore() { int sum = 0; for(int i = 0; i < 5; i++) { sum += scores[i]; } return sum; }
int main() { int n; cin >> n; Student a[n]; for(int i = 0; i < n; i++) { a[i].input(); } int cnt = 0; for(int j = 1; j < n; j++) { if(a[j].calculateTotalScore() > a[0].calculateTotalScore()) cnt++; } cout << cnt; return 0; } `