Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Building {
- protected:
- string address;
- string purpose;
- float area;
- float price;
- public:
- Building() {}
- Building(string _address, string _purpose, float _area, float _price) : address(_address), purpose(_purpose), area(_area), price(_price) {}
- void set() {
- cout << "address: "; cin >> address;
- cout << "purpose: "; cin >> purpose;
- cout << "area: "; cin >> area;
- cout << "price: "; cin >> price;
- }
- void get() {
- cout << "address: " << address << endl;
- cout << "purpose: " << purpose << endl;
- cout << "area: " << area << endl;
- cout << "price: " << price << endl;
- }
- };
- class House : public Building{
- int apartCount;
- public:
- House() {}
- House(string _address, string _purpose, float _area, float _price, int _apartCount) : Building(_address, _purpose, _area, _price), apartCount(_apartCount) {}
- void set() {
- cout << "Enter info about house: " << endl;
- Building :: set(); //клас Building
- cout << "number of apartments: "; cin >> apartCount;
- cout << endl;
- }
- void get() {
- cout << "Info about house: " << endl;
- Building :: get(); //клас Building
- cout << "number of apartments: " << apartCount << endl;
- cout << endl;
- }
- };
- class CountryHouse : public Building {
- float croftArea;
- int treeCount;
- public:
- CountryHouse() {}
- CountryHouse(string _address, string _purpose, float _area, float _price, float _croftArea, int _treeCount) : Building(_address, _purpose, _area, _price), croftArea(_croftArea), treeCount(_treeCount) {}
- void set() {
- cout << "Enter info about country house: " << endl;
- Building :: set(); //клас Building
- cout << "area of croft: "; cin >> croftArea;
- cout << "number of trees: "; cin >> treeCount;
- cout << endl;
- }
- void get() {
- cout << "Info about country house: " << endl;
- Building :: get(); //клас Building
- cout << "area of croft: " << croftArea << endl;
- cout << "number of trees: " << treeCount << endl;
- cout << endl;
- }
- };
- int main() {
- House house;
- house.set(); //клас House
- house.get(); //клас House
- CountryHouse cHouse;
- cHouse.set(); //клас CountryHouse
- cHouse.get(); //клас CountryHouse
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment