-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ04_Student.cpp
53 lines (51 loc) · 1.03 KB
/
Q04_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
#include <iostream>
#include <iomanip>
using namespace std;
class STUDENT
{
private:
string name;
int roll;
int totalmarks;
public:
void getData(int i)
{
cout << "\nSTUDENT " << (i + 1) << endl;
cout << "Enter the student name:";
cin >> name;
cout << "Enter the student roll number:";
cin >> roll;
cout << "Enter the student Total marks:";
cin >> totalmarks;
}
friend float AvgMark(int n, STUDENT s[]);
};
float AvgMark(int n, STUDENT s[])
{
s[n];
float sum = 0;
float avg;
for (int i = 0; i < n; i++)
{
sum = sum + s[i].totalmarks;
}
avg = sum / (float)n;
return avg;
}
int main()
{
int n, average;
cout << "Enter the number of students:";
cin >> n;
cout << endl;
STUDENT s[n];
for (int i = 0; i < n; i++)
{
s[i].getData(i);
cout << endl;
}
cout << endl;
average = AvgMark(n, s);
cout << "The Average marks obtained by " << n << " student is:" << average;
return 0;
}