AlezM

KP

Sep 30th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Property { //Базовый класс
  6. public:
  7.     double worth;
  8.  
  9.     Property() { //Конструктор по умолчанию
  10.         worth = 0;
  11.     }
  12.     Property (double _worth) { //Конструктор с входным параметром worth
  13.         worth = _worth;
  14.     }
  15.  
  16.     virtual double Taxes() = 0; //Чисто виртуальная функция считающая налоги
  17. };
  18.  
  19. class Appartment : public Property {
  20. public:
  21.     Appartment(double _worth) : Property(_worth) {} //Конструктор для Apprtment
  22.  
  23.     double Taxes() { //Переопределение ф-и считающей налоги для Appartment
  24.         return worth / 1000;
  25.     }
  26. };
  27.  
  28. class Car : public Property {
  29. public:
  30.     Car(double _worth) : Property(_worth) {} //Конструктор для Car
  31.  
  32.     double Taxes() { //Переопределение ф-и считающей налоги для Car
  33.         return worth / 200;
  34.     }
  35. };
  36.  
  37. class CountryHouse : public Property {
  38. public:
  39.     CountryHouse(double _worth) : Property(_worth) {} //Конструктор для CountryHouse
  40.  
  41.     double Taxes() { //Переопределение ф-и считающей налоги для CountryHouse
  42.         return worth / 500;
  43.     }
  44. };
  45.  
  46. int main()
  47. {
  48.     Property* props[7]; //Создаём массив указателей Property
  49.  
  50.     props[0] = new Appartment(10000);
  51.     props[1] = new Appartment(22000);
  52.     props[2] = new Appartment(15000);
  53.     props[3] = new Car(250000);
  54.     props[4] = new Car(15000);
  55.     props[5] = new CountryHouse(5000);
  56.     props[6] = new CountryHouse(12000);
  57.  
  58.     for (int i = 0; i < 7; i++) {
  59.         cout << props[i]->Taxes() << endl;
  60.     }
  61.  
  62.     delete[] props; //Освобождаем память
  63.  
  64.     return 0;
  65. }
Add Comment
Please, Sign In to add comment