Vladislav_Bezruk

Untitled

Oct 19th, 2021
631
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Building {
  6.     protected:
  7.         string address;
  8.         string purpose;
  9.         float area;
  10.         float price;
  11.        
  12.     public:
  13.         Building() {}
  14.        
  15.         Building(string _address, string _purpose, float _area, float _price) : address(_address), purpose(_purpose), area(_area), price(_price) {}
  16.        
  17.         void set() {
  18.             cout << "address: "; cin >> address;
  19.             cout << "purpose: "; cin >> purpose;
  20.             cout << "area: "; cin >> area;
  21.             cout << "price: "; cin >> price;
  22.         }
  23.        
  24.         void get() {
  25.             cout << "address: " << address << endl;
  26.             cout << "purpose: " << purpose << endl;
  27.             cout << "area: " << area << endl;
  28.             cout << "price: " << price << endl;
  29.         }
  30. };
  31.  
  32. class House : public Building{
  33.     int apartCount;
  34.        
  35.     public:
  36.         House() {}
  37.        
  38.         House(string _address, string _purpose, float _area, float _price, int _apartCount) : Building(_address, _purpose, _area, _price), apartCount(_apartCount) {}
  39.        
  40.         void set() {
  41.             cout << "Enter info about house: " << endl;
  42.             Building :: set(); //клас Building     
  43.             cout << "number of apartments: "; cin >> apartCount;
  44.             cout << endl;
  45.         }
  46.        
  47.         void get() {
  48.             cout << "Info about house: " << endl;
  49.             Building :: get(); //клас Building
  50.             cout << "number of apartments: " << apartCount << endl;
  51.             cout << endl;
  52.         }
  53. };
  54.  
  55. class CountryHouse : public Building {
  56.     float croftArea;
  57.     int treeCount;
  58.    
  59.     public:
  60.         CountryHouse() {}
  61.        
  62.         CountryHouse(string _address, string _purpose, float _area, float _price, float _croftArea, int _treeCount) : Building(_address, _purpose, _area, _price), croftArea(_croftArea), treeCount(_treeCount) {}
  63.        
  64.         void set() {
  65.             cout << "Enter info about country house: " << endl;
  66.             Building :: set(); //клас Building     
  67.             cout << "area of croft: "; cin >> croftArea;
  68.             cout << "number of trees: "; cin >> treeCount;
  69.             cout << endl;
  70.         }
  71.        
  72.         void get() {
  73.             cout << "Info about country house: " << endl;
  74.             Building :: get(); //клас Building
  75.             cout << "area of croft: " << croftArea << endl;
  76.             cout << "number of trees: " << treeCount << endl;
  77.             cout << endl;
  78.         }
  79. };
  80.  
  81. int main() {
  82.    
  83.     House house;
  84.  
  85.     house.set(); //клас House
  86.    
  87.     house.get(); //клас House
  88.    
  89.     CountryHouse cHouse;
  90.    
  91.     cHouse.set(); //клас CountryHouse
  92.    
  93.     cHouse.get(); //клас CountryHouse
  94.    
  95.     return 0;
  96. }
RAW Paste Data