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.
Wondering why in order to make an array of Student data type, we need the pointer of variable.
Student*s=newStudent[n];// an array of n students
#include<cmath>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>#include<cassert>usingnamespacestd;// Write your Student class hereclassStudent{private:intscores[5];public:voidinput(){for(inti=0;i<5;i++){cin>>scores[i];}}intcalculateTotalScore(){intresult=0;for(inti=0;i<5;i++){result+=scores[i];}returnresult;}};intmain(){intn;// number of studentscin>>n;Student*s=newStudent[n];// an array of n studentsfor(inti=0;i<n;i++){s[i].input();}// calculate kristen's scoreintkristen_score=s[0].calculateTotalScore();// determine how many students scored higher than kristenintcount=0;for(inti=1;i<n;i++){inttotal=s[i].calculateTotalScore();if(total>kristen_score){count++;}}// print resultcout<<count;return0;}
Cookie support is required to access HackerRank
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 →
Wondering why in order to make an array of Student data type, we need the pointer of variable.