Advertisement
Tusohian

Inheritance in OOP (C++)

Jul 28th, 2017
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4.  
  5. class building
  6. {
  7.  
  8.     int room, sqft;
  9.  
  10. public:
  11.  
  12.     building()
  13.     {
  14.         room=sqft=0;
  15.     }
  16.  
  17.     building(int x, int y)
  18.     {
  19.         room=x;
  20.         sqft=y;
  21.     }
  22.  
  23.     input()
  24.     {
  25.         cout<<"Please Enter Room Number: ";
  26.         cin>>room;
  27.  
  28.         cout<<"Please Enter Size in Squire Feet: ";
  29.         cin>>sqft;
  30.     }
  31.  
  32.     display()
  33.     {
  34.         cout<<"Room Number: "<<room<<endl;
  35.         cout<<"Room Size: "<<sqft<<" Sqr ft"<<endl;
  36.     }
  37.  
  38. };
  39.  
  40.  
  41. class house:public building
  42. {
  43.     int bedroom;
  44.  
  45. public:
  46.  
  47.     house(int x, int y, int z):building(x,y)
  48.     {
  49.         bedroom=z;
  50.     }
  51.  
  52.     display()
  53.     {
  54.      building::display();
  55.      cout<<"Bedroom Number: "<<bedroom<<endl;
  56.     }
  57.  
  58. };
  59.  
  60.  
  61. class office:public building{
  62.     int ext;
  63. public:
  64.     office(int x, int y, int z):building(x,y)
  65.     {
  66.     ext=z;
  67.     }
  68.  
  69.     display()
  70.     {
  71.      building::display();
  72.      cout<<"Ext : "<<ext<<endl;
  73.     }
  74.  
  75. };
  76.  
  77.  
  78. int main()
  79. {
  80.     house h(6,1500,4);
  81.     h.display();
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement