-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClasses and Objects(problem 1).cpp
More file actions
53 lines (45 loc) · 1.14 KB
/
Classes and Objects(problem 1).cpp
File metadata and controls
53 lines (45 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
using namespace std;
class Student
{
int scores[5]; // instance variable to hold 5 exam scores
public:
void input() // function to read 5 integers and save them to "scores"
{
for(int i=0; i<5; i++)
{
cin >> scores[i];
}
}
int calculateTotalScore() // function to return the sum of the student's scores
{
int totalScore = 0;
for(int i=0; i<5; i++)
{
totalScore += scores[i];
}
return totalScore;
}
};
int main()
{
int n;
cin >> n;
Student students[n];
for(int i=0; i<n; i++) // reading inputs for all the students
{
students[i].input();
}
int kristenTotalScore = students[0].calculateTotalScore(); // getting the total score of Kristen
int count = 0;
for(int i=1; i<n; i++) // checking the scores of all other students
{
int totalScore = students[i].calculateTotalScore();
if(totalScore > kristenTotalScore)
{
count++;
}
}
cout << count; // printing the number of students who scored higher than Kristen
return 0;
}