-
Notifications
You must be signed in to change notification settings - Fork 0
/
student.cpp
68 lines (68 loc) · 1.42 KB
/
student.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
using namespace std;
class stud
{
char usn[20], name[30];
float marks[3];
int i;
public:
float avg;
void read(int);
void calc(int);
void disp();
};
void stud::read(int i)
{
cout << "\nEnter USN no of student "<<i+1<<": ";
cin >> usn;
cout << "\nEnter name: ";
cin >> name;
for (int j = 0; j < 3; j++) {
cout << "\nEnter the marks of subject " << j + 1 << ": ";
cin >> marks[j];
}
}
void stud::calc(int n)
{
int sum = 0, min = marks[0];
for (i = 0; i < n; i++) {
sum += marks[i];
if (min >= marks[i])
min = marks[i];
}
avg = float(sum - min) / 2;
}
void stud::disp()
{
cout << "USN: " << usn << endl;
cout << "Name: " << name << endl;
cout << "Marks: ";
for (int i = 0; i < 3; i++) {
cout << marks[i] << " ";
}
cout <<"\nAverage="<< avg << "\n"<<endl;
}
int main()
{
int n, topper, i;
float max = 0;
cout << "\nEnter the number of students: ";
cin >> n;
stud s[n];
for (i = 0; i < n; i++) {
s[i].read(i);
s[i].calc(n);
}
cout<<"\nStudent details- \n";
for (i = 0; i < n; i++)
s[i].disp();
for (i = 0; i < n; i++) {
if (max < s[i].avg) {
max = s[i].avg;
topper = i;
}
}
cout << "\nThe toppers is student " << i + 1 << ": ";
cout << "\nDetails:-\n";
s[topper].disp();
}