Create a base class called building that stores the number of floors, rooms and area. Create a derived class called house that inherits building and store number of bedrooms and bathrooms. Create another derived class called office that inherits house and store number of window. now show everything creating office class object.
#include<iostream>
using namespace std;
class building
{
  int rooms;
  int floors;
  int area;
public:
  void set_rooms(int num);
  int get_rooms();
  void set_floors(int num);
  int get_floors();
  void set_area(int num);
  int get_area();
};
class house : public building
{
  int bedrooms;
  int baths;
public:
  void set_bedrooms(int num);
  int get_bedrooms();
  void set_baths(int num);
  int get_baths();
};
class office : public house
{
  int window;
public:
  void set_window(int num);
  int get_window();
};
int building :: set_rooms(int num)
{
  rooms = num;
}
void building:: set_floors(int num)
{
  floors = num;
}
void building :: set_area(int num)
{
  area=num;
}
int building :: get_rooms()
{
  return rooms;
}
int building :: get_floors()
{
  return floors;
}
int building :: get_area()
{
  return area;
}
void house :: set_bedrooms(int num)
{
  bedrooms = num;
}
void house ::set_baths(int num)
{
  baths=num;
}
int house :: get_bedrooms()
{
  return bedrooms;
}
int house::get_baths()
{
  return baths;
}
void office :: set_window(int num)
{
  window = num;
}
int office :: get_window()
{
  return window;
}
int main()
{
  house h;
  office o;
  h.set_rooms(12);
  h.set_floors(3);
  h.set_area(4500);
  h.set_bedrooms(5);
  h.set_baths(3);
  cout<<"house has" << h.get_bedrooms();
  cout<< "bedrooms\n";
  o.set_rooms(200);
  o.window(180);
  o.set_offices(5);
  o.set_area(25000);
  cout<<"school has "<<o.get_window();
  cout<<"windows\n";
  cout<<"Its area is" <<o.get_area();
  return 0;
}
Comments
Leave a comment