-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path30_objArr_pointer.cpp
58 lines (51 loc) · 1.17 KB
/
30_objArr_pointer.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
#include<iostream>
using namespace std;
class Student {
int id , section;
public:
void setdata(int a , int b){
id=a;
section=b;
}
void display(){
cout<<"ID of the student is : "<<id<<endl;
cout<<"Section is : "<<section<<endl;
}
};
class P {
int a;
public:
P& setdata(int a){
this->a=a;
return *this;
}
void display(){
cout<<"Value of a is : "<<a<<endl;
}
};
int main ()
{
P a;
a.setdata(5);
a.display();
int size=3;
// int* ptr=&size;
// int* ptr= new int [5]; --> give space to store 5 integer
Student *ptr = new Student[size]; //creating an array of objects
Student *Temptr = ptr; //creating an array of objects
int p,q;
for(int i=0;i<size;i++){
cout<<"Enter value of p : ";
cin>>p;
cout<<"Enter value of q : ";
cin>>q;
// (*ptr).setdata(p,q);
ptr->setdata(p,q);
ptr++;
}
for(int i=0;i<size;i++){
Temptr->display();
Temptr++;
}
return 0;
}