-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSession10B.cpp
More file actions
153 lines (125 loc) · 3.11 KB
/
Session10B.cpp
File metadata and controls
153 lines (125 loc) · 3.11 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include<iostream>
#include<string>
using namespace std;
/*
Geometry Box
Encapsulation -> Leads to Data Hiding
private
Abstraction
Show only the useful details and hide consfidential data
Inheritance
Product (Parent)
Children
Mobile
Shoe
Laptop
*/
// Object to Object
class Product{
public:
Product(){
cout<<"Product Object Constructed\n";
}
// Attributes: Property of Object
int pid;
string name;
int price;
string brandName;
void showProductDetails(){
cout<<"******************\n";
cout<<"=="<<pid<<"\t"<<name<<"==\n";
cout<<"Price:\t"<<price<<"\n";
cout<<"Brand:\t"<<brandName<<"\n";
cout<<"******************\n";
}
void setProductDetails(int pid, string name, int price, string brandName){
//this->pid belongs to Object
// pid belongs to function/method
this->pid = pid;
this->name = name;
this->price = price;
this->brandName = brandName;
}
};
class Mobile : public Product{
public:
// Attributes: Property of Object
// int pid;
// string name;
// int price;
// string brandName;
string os;
int ram;
int storage;
Mobile(){
cout<<"Mobile Object Constructed\n";
}
void setMobileDetails(int pid, string name, int price, string brandName, string os, int ram, int storage){
//this->pid belongs to Object
// pid belongs to function/method
// this->pid = pid;
// this->name = name;
// this->price = price;
// this->brandName = brandName;
setProductDetails(pid, name, price, brandName);
this->os = os;
this->ram = ram;
this->storage = storage;
}
void showMobileDetails(){
// cout<<"=="<<pid<<"\t"<<name<<"==\n";
// cout<<"Price:\t"<<price<<"\n";
// cout<<"Brand:\t"<<brandName<<"\n";
showProductDetails();
cout<<"OS:\t"<<os<<"\n";
cout<<"RAM:\t"<<ram<<"\n";
cout<<"Storage:\t"<<storage<<"\n";
}
};
class Shoe : public Product{
public:
// Attributes: Property of Object
// int pid;
// string name;
// int price;
// string brandName;
int size;
string color;
Shoe(){
cout<<"Shoe Object Constructed\n";
}
void setShoeDetails(int pid, string name, int price, string brandName, int size, string color){
//this->pid belongs to Object
// pid belongs to function/method
// this->pid = pid;
// this->name = name;
// this->price = price;
// this->brandName = brandName;
setProductDetails(pid, name, price, brandName);
this->size = size;
this->color = color;
}
void showShoeDetails(){
// cout<<"=="<<pid<<"\t"<<name<<"==\n";
// cout<<"Price:\t"<<price<<"\n";
// cout<<"Brand:\t"<<brandName<<"\n";
showProductDetails();
cout<<"Size:\t"<<size<<"\n";
cout<<"Color:\t"<<color<<"\n";
}
};
int main(int argc, char const *argv[]){
// Static Object Construction
// Where Object is constructed in Stack
//Mobile m1;
// Dynamic Object Construction
Mobile* mptr = new Mobile();
//m1.setMobileDetails(101, "iPhoneX", 70000, "Apple", "iOS", 4, 128);
//m1.showMobileDetails();
mptr->setMobileDetails(101, "iPhoneX", 70000, "Apple", "iOS", 4, 128);
mptr->showMobileDetails();
Shoe *sptr = new Shoe();
sptr->setShoeDetails(201, "AlphaBounce", 5000, "Adidas", 7, "black");
sptr->showShoeDetails();
return 0;
}