Classes and Objects

  • + 0 comments
    #include <cmath>
    #include <cstdio>
    #include <iostream>
    using namespace std;
    
    class Student{
        private:
            int scores[5]{};
        public:
            void input(){
                for (int i{}; i<5; i++) {
                    std::cin >> scores[i];
                }
            }
            int calculateTotalScore(){
                int total{};
                for (int i{}; i<5; i++) {
                    total += scores[i];
                }
                return total;
            }
    };
    
    int main() {
        unsigned int n;
        std::cin >> n;
        Student st[n];
        int n_g{};
        for (size_t i{}; i<n; i++) {
            st[i].input();
            (st[i].calculateTotalScore()>st[0].calculateTotalScore()) ? n_g++ : false;     
        }
        std::cout << n_g;
        return 0;
    }