-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSession14G.cpp
More file actions
72 lines (53 loc) · 1.04 KB
/
Session14G.cpp
File metadata and controls
72 lines (53 loc) · 1.04 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
62
63
64
65
66
67
68
69
70
71
72
#include<iostream>
#include<string>
using namespace std;
class Student{
int roll;
string name;
public:
Student(){
roll = 0;
name = "NA";
}
void setStudent(int roll, string name){
this->roll = roll;
this->name = name;
}
void showStudent(){
cout<<roll<<" belongs to "<<name<<"\n";
}
};
int main(){
/*
Student s1;
Student s2;
Student s3;
s1.setStudent(101,"John");
s2.setStudent(201,"Jennie");
s3.setStudent(301,"Jack");
s1.showStudent();
s2.showStudent();
s3.showStudent();*/
// Array of Objects
// Static Array Creation
/*
Student sArr[3]; // sArr[0], sArr[1], sArr[2]
sArr[0].setStudent(101,"John");
sArr[1].setStudent(201,"Jennie");
sArr[2].setStudent(301,"Jack");
for(int i=0;i<3;i++){
sArr[i].showStudent();
}
*/
// Array of Objects. Array is created dynamically
Student *sptr = new Student[3];
sptr[0].setStudent(101,"John");
sptr[1].setStudent(201,"Jennie");
sptr[2].setStudent(301,"Jack");
for(int i=0;i<3;i++){
sptr[i].showStudent();
}
// Array of Pointers
// Explore More !!
return 0;
}