-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_022.cpp
More file actions
42 lines (41 loc) · 1.09 KB
/
problem_022.cpp
File metadata and controls
42 lines (41 loc) · 1.09 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
//Write a C++ program to create an array of pointers.
//Invoke functions using array objects.
#include<bits/stdc++.h>
using namespace std;
#define MAX 100
class Student{
string name;
float marks;
public:
void getStudentInfo(int i){
cout<<endl<<"Student "<<i<<" detials"<<endl;
cout<<"Enter name:";
cin.ignore(); // Consume the newline character left by the previous input
getline(cin,name);
cout<<"Enter marks:";
cin>>marks;
}
void displayStudentInfo(int i){
cout<<endl<<"Student "<<i<<" detials"<<endl;
cout<<"Name:"<<name<<endl;
cout<<"Marks:"<<marks<<endl;
}
};
int main()
{
Student st[MAX],*ptr;
ptr=st;
int class_size;
cout<<"Enter the number of students in the class:";
cin>>class_size;
for(int i=1;i<=class_size;i++)
{
(ptr+i)->getStudentInfo(i);
}
cout<<endl<<"--------------Display---------------"<<endl;
for(int i=1;i<=class_size;i++)
{
(ptr+i)->displayStudentInfo(i);
}
return 0;
}