object oriented inheritance

EXAMPLE OF INHERITANCE
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//Base class
class Hotel
{
   public:
   	void setName(string hotel_name){
		name = hotel_name;
               }
	void setLocation(string hotel_location){
		location = hotel_location;
		}
	double setRate(double hotel_rate){
		rate = hotel_rate;
		}
         void setReview(string hotel_review)  {
		review = hotel_review;
		}
		
	void setAttraction(string hotel_attraction)  {
		attraction  = hotel_attraction;
		}
	void setRoomtype(string hotel_roomtype){
		roomtype = hotel_roomtype;
		}
      
  protected:
    string name;
    string location;
    double rate;
    string attraction;
    string review;
    string roomtype;
    
};



//---------------Derived class #1-------------------------------
class Hotel_name: public Hotel
{
	public:
		string getName()
		{
			return(name);
		}
};

//---------------Derived class #2-------------------------------
class Hotel_location: public Hotel
{
   public:
      string getLocation()
      {
      	return(location);
	  }
};

//---------------Derived class #3-------------------------------
class Hotel_rate: public Hotel
{
	public:
		double getRate()
		{
			return(rate);
		}
};

//---------------Derived class #4-------------------------------
class Hotel_attraction: public Hotel
{
	public:
		string getAttraction()
		{
			return(attraction);
		}
};

//---------------Derived class #5-------------------------------
class Hotel_review: public Hotel
{
   public:
      string getReview()
      { 
        return(review); 
      }
};

//---------------Derived class #6------------------------------
class Hotel_roomtype: public Hotel
{
	public:
		string getRoomtype()
		{
			return(roomtype);
		}
	
};

//-------------------------------------------------------------------

//main function
int main(void)
{
	Hotel_name        hotel_name1;
        Hotel_location    hotel_loc1;
        Hotel_rate        hotel_rate1;
        Hotel_attraction  hotel_attr1;
	Hotel_review      hotel_rev1;
	Hotel_roomtype    hotel_type1;
	
	hotel_name1.setName("The Garden Hotel & Residences - St Giles Hotels");
	hotel_loc1.setLocation("Kuala Lumpur");
	hotel_rate1.setRate(441);
	hotel_attr1.setAttraction("MidValley Megamall");
	hotel_rev1.setReview("5stars Hotel");
	hotel_type1.setRoomtype("Deluxe/Family Suite");
	
//----------------------hotel2-------------------------------------

	Hotel_name        hotel_name2;
        Hotel_location    hotel_loc2;
        Hotel_rate        hotel_rate2;
        Hotel_attraction  hotel_attr2;
	Hotel_review      hotel_rev2;
	Hotel_roomtype    hotel_type2;
	
	hotel_name2.setName("Sunway Resort Hotel and Spa");
	hotel_loc2.setLocation("Bandar Sunway, Petaling Jaya");
	hotel_rate2.setRate(200);
	hotel_attr2.setAttraction("Sunway Pyramid Shopping Mall , Sunway Lagoon");
	hotel_rev2.setReview("5stars Hotel");
	hotel_type2.setRoomtype("Studio/Suite");

//----------------------hotel3-------------------------------------

	Hotel_name        hotel_name3;
        Hotel_location    hotel_loc3;
        Hotel_rate        hotel_rate3;
        Hotel_attraction  hotel_attr3;
	Hotel_review      hotel_rev3;
	Hotel_roomtype    hotel_type3;
	
	hotel_name3.setName("Empire Hotel Subang");
	hotel_loc3.setLocation("Subang Jaya");
	hotel_rate3.setRate(279);
	hotel_attr3.setAttraction("Empire Shopping mall");
	hotel_rev3.setReview("5stars Hotel");
	hotel_type3.setRoomtype("Studio/Suite");
	
//----------------------hotel4-------------------------------------

	Hotel_name        hotel_name4;
        Hotel_location    hotel_loc4;
        Hotel_rate        hotel_rate4;
        Hotel_attraction  hotel_attr4;
	Hotel_review      hotel_rev4;
	Hotel_roomtype    hotel_type4;

	hotel_name4.setName("Renaissance Kuala Lumpur Hotel");
	hotel_loc4.setLocation("Kuala Lumpur");
	hotel_rate4.setRate(362);
	hotel_attr4.setAttraction("Kuala Lumpur Tower");
	hotel_rev4.setReview("5stars Hotel");
	hotel_type4.setRoomtype("Deluxe/Suite/Studio");
	
//----------------------hotel5-------------------------------------

	Hotel_name        hotel_name5;
        Hotel_location    hotel_loc5;
        Hotel_rate        hotel_rate5;
        Hotel_attraction  hotel_attr5;
	Hotel_review      hotel_rev5;
	Hotel_roomtype    hotel_type5;
	
	hotel_name5.setName("Hotel Pullman Putrajaya Lakeside Hotels");
	hotel_loc5.setLocation("Putrajaya");
	hotel_rate5.setRate(250);
	hotel_attr5.setAttraction("Masjid Putra, Putra Square");
	hotel_rev5.setReview("5stars Hotel");
	hotel_type5.setRoomtype("Deluxe/Suite");
	
//----------------------hotel6-------------------------------------

	Hotel_name        hotel_name6;
        Hotel_location    hotel_loc6;
        Hotel_rate        hotel_rate6;
        Hotel_attraction  hotel_attr6;
	Hotel_review      hotel_rev6;
	Hotel_roomtype    hotel_type6;
	
	hotel_name6.setName("Mandarin Oriental Hotels");
	hotel_loc6.setLocation("Kuala Lumpur");
	hotel_rate6.setRate(300);
	hotel_attr6.setAttraction("Suria KLCC");
	hotel_rev6.setReview("5stars Hotel");
	hotel_type6.setRoomtype("Family Suite/Suite");

//-----------------displaying the output----------------------------
   
   cout<<"Hotel name         : "<<hotel_name1.getName()<<endl;
   cout<<"Hotel location     : "<<hotel_loc1.getLocation()<<endl;
   cout<<"Starting rate      : RM"<<hotel_rate1.getRate()<<endl;
   cout<<"Nearest Attraction : "<<hotel_attr1.getAttraction()<<endl;
   cout<<"Hotel Review       : "<<hotel_rev1.getReview()<<endl;
   cout<<"Room type          : "<<hotel_type1.getRoomtype()<<endl<<endl;
   
   cout<<"Hotel name         : "<<hotel_name2.getName()<<endl;
   cout<<"Hotel location     : "<<hotel_loc2.getLocation()<<endl;
   cout<<"Starting rate      : RM"<<hotel_rate2.getRate()<<endl;
   cout<<"Nearest Attraction : "<<hotel_attr2.getAttraction()<<endl;
   cout<<"Hotel Review       : "<<hotel_rev2.getReview()<<endl;
   cout<<"Room type          : "<<hotel_type2.getRoomtype()<<endl<<endl;
   
   cout<<"Hotel name         : "<<hotel_name3.getName()<<endl;
   cout<<"Hotel location     : "<<hotel_loc3.getLocation()<<endl;
   cout<<"Starting rate      : RM"<<hotel_rate3.getRate()<<endl;
   cout<<"Nearest Attraction : "<<hotel_attr3.getAttraction()<<endl;
   cout<<"Hotel Review       : "<<hotel_rev3.getReview()<<endl;
   cout<<"Room type          : "<<hotel_type3.getRoomtype()<<endl<<endl;
   
   cout<<"Hotel name         : "<<hotel_name4.getName()<<endl;
   cout<<"Hotel location     : "<<hotel_loc4.getLocation()<<endl;
   cout<<"Starting rate      : RM"<<hotel_rate4.getRate()<<endl;
   cout<<"Nearest Attraction : "<<hotel_attr4.getAttraction()<<endl;
   cout<<"Hotel Review       : "<<hotel_rev4.getReview()<<endl;
   cout<<"Room type          : "<<hotel_type4.getRoomtype()<<endl<<endl;
   
   cout<<"Hotel name         : "<<hotel_name5.getName()<<endl;
   cout<<"Hotel location     : "<<hotel_loc5.getLocation()<<endl;
   cout<<"Starting rate      : RM"<<hotel_rate5.getRate()<<endl;
   cout<<"Nearest Attraction : "<<hotel_attr5.getAttraction()<<endl;
   cout<<"Hotel Review       : "<<hotel_rev5.getReview()<<endl;
   cout<<"Room type          : "<<hotel_type5.getRoomtype()<<endl<<endl;

   cout<<"Hotel name         : "<<hotel_name6.getName()<<endl;
   cout<<"Hotel location     : "<<hotel_loc6.getLocation()<<endl;
   cout<<"Starting rate      : RM"<<hotel_rate6.getRate()<<endl;
   cout<<"Nearest Attraction : "<<hotel_attr6.getAttraction()<<endl;
   cout<<"Hotel Review       : "<<hotel_rev6.getReview()<<endl;
   cout<<"Room type          : "<<hotel_type6.getRoomtype()<<endl<<endl;
 
   
  
   return 0;
}
Last edited on
Do you have a question?

And no: that's not useful inheritance.
Topic archived. No new replies allowed.