Classes and Objects

  • + 0 comments

    Easy C++ code || Class and Objects || With Proper guidlines

    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    class Student {
        private:
        int score1, score2, score3, score4, score5;
        
        public:
        void input(int score1, int score2, int score3, int score4, int score5) {
            this->score1 = score1;
            this->score2 = score2;
            this->score3 = score3;
            this->score4 = score4;
            this->score5 = score5;
        }
        
        int calculateTotalScore() {
            return this->score1+this->score2+this->score3+this->score4+this->score5;
        }
    };
    
    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 
        int n;
        cin >> n;
        int s1, s2, s3, s4, s5;
        cin >> s1 >> s2 >> s3 >> s4 >> s5;
        Student Kristen;
        Kristen.input(s1, s2, s3, s4, s5);
        int KristenScore = Kristen.calculateTotalScore();
        int cnt = 0;
        n--;
        while (n-- > 0) {
            Student others;
            cin >> s1 >> s2 >> s3 >> s4 >> s5;
            others.input(s1, s2, s3, s4, s5);
            if(others.calculateTotalScore() > KristenScore) cnt++;
        }  
        cout << cnt;
        return 0;
    }