Classes and Objects

  • + 0 comments
    1. 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; }