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.
**For Those Wants To Execute This Code Without Using Vector **
#include<iostream>usingnamespacestd;// Define the Student classclassStudent{private:intscores[5];// Array to hold scores (fixed size for 5 subjects)public:// Function to read scores from inputvoidinput(){for(inti=0;i<5;i++){cin>>scores[i];}}// Function to calculate the total scoreintcalculateTotalScore(){inttotalScore=0;for(inti=0;i<5;i++){totalScore+=scores[i];}returntotalScore;}};intmain(){intn;// Number of studentscin>>n;Student*students=newStudent[n];// Dynamically allocate array of students// Input scores for each studentfor(inti=0;i<n;i++){students[i].input();}// Calculate Kristen's total score (first student)intkristenScore=students[0].calculateTotalScore();// Count how many students scored higher than Kristenintcount=0;for(inti=1;i<n;i++){if(students[i].calculateTotalScore()>kristenScore){count++;}}// Output the resultcout<<count<<endl;// Clean up dynamic memorydelete[]students;return0;}
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 →
**For Those Wants To Execute This Code Without Using Vector **