-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFILE8.cpp
More file actions
61 lines (56 loc) · 1.43 KB
/
Copy pathFILE8.cpp
File metadata and controls
61 lines (56 loc) · 1.43 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
54
55
56
57
58
59
60
61
/*
Arrays are user defined data types whose members are of the same type. For practical applications such as designing a larga database, arrays are very useful.
Arrays of class objects are used in a manner similar to other basic data types.
This is a program that will define a class Student with the roll number and marks as the data members.
The average marks obtained by the students are calculated and displayed along with the student details.
*/
#include <iostream>
using namespace std;
class Student
{
private:
int rollno;
int marks;
public:
void getinfo(void)
{
cout << "Enter the Roll number: ";
cin >> rollno;
cout << "Enter the marks: ";
cin >> marks;
}
void display(void)
{
cout << rollno << " " << marks << endl;
}
int getmarks(void)
{
return marks;
}
}; // End of class Student
int main()
{
Student stulist[100];
float total, average;
int no, i;
total = 0.0;
/*
It will prompt you to enter the number of students for whom details will be supplied.
You will also be prompted to enter the roll number and marks of the students.
*/
cout << "Enter the number of students: ";
cin >> no;
for (i=0; i<no; i++)
{
stulist[i].getinfo();
total = total + stulist[i].getmarks(); // Adding the marks
}
cout << "Rollno Marks " << endl;
for (i=0; i<no; i++)
{
stulist[i].display();
}
average = total / no; // Find the average
cout << "Average marks: " << average << endl;
return 0;
} // End of function main