-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_019.cpp
More file actions
53 lines (50 loc) · 1.13 KB
/
problem_019.cpp
File metadata and controls
53 lines (50 loc) · 1.13 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
//Write a C++ program to display Names, Roll No., and grades of 3 students who have appeared in the examnation.
//Declare the class of name, Roll No. and grade. Create an array of class objects. Read and display the contents of the
//array.
#include<iostream>
#include<string>
using namespace std;
class Student{
public:
string name;
int rollNumber;
float grade;
void putData(string s,int r,float g);
void printData();
};
void Student::putData(string s,int r,float g){
name=s;
rollNumber=r;
grade=g;
}
void Student::printData(){
cout<<"Name:"<<name<<endl;
cout<<"Roll number:"<<rollNumber<<endl;
cout<<"Grade:"<<grade<<endl;
cout<<"------------------"<<endl;
}
int main()
{
string n;
float grade;
int roll;
Student s[3];
for(int i=0;i<3;i++){
cout<<"Student->"<<i+1<<endl;
cout<<"Enter Name:";
cin>>n;
cout<<"Enter Roll Number:";
cin>>roll;
cout<<"Enter Grade:";
cin>>grade;
s[i].putData(n,roll,grade);
}
cout<<"-----------------------------"<<endl;
cout<<"|"<<" STUDENT DETIALS "<<"|"<<endl;
cout<<"-----------------------------"<<endl;
for(int k=0;k<3;k++)
{
s[k].printData();
}
return 0;
}