-
Notifications
You must be signed in to change notification settings - Fork 7
/
nestedClass.cpp
50 lines (48 loc) · 1.22 KB
/
nestedClass.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
#include<bits/stdc++.h>
using namespace std;
class Student {
int rollNo;
string name;
class Address {
int houseNo;
string apartment;
int pincode;
string state;
public:
void setAddress(int houseNo, string apartment, int pincode, string state) {
this->houseNo = houseNo;
this->apartment = apartment;
this->pincode = pincode;
this->state = state;
}
void getAddress() {
cout << "House No: " << houseNo << endl;
cout << "Apartment: " << apartment << endl;
cout << "Pincode: " << pincode << endl;
cout << "State: " << state << endl;
}
};
Address address;
public:
void setData(int rollNo, string name, int houseNo, string apartment, int pincode, string state) {
this->rollNo = rollNo;
this->name = name;
address.setAddress(houseNo, apartment, pincode, state);
}
void getData() {
cout << "Student name: " << name << endl;
cout << "RollNo: " << rollNo << endl;
cout << "Address: ";
address.getAddress();
}
};
int main() {
/*
--> A class inside a class is called nested class.
--> A nested class is a member and as such has the same access rights as other members
-->
*/
Student s1;
s1.setData(1, "Jinesh", 22, "HouseApartments", 113111, "Maharashtra");
s1.getData();
}