Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Property { //Базовый класс
- public:
- double worth;
- Property() { //Конструктор по умолчанию
- worth = 0;
- }
- Property (double _worth) { //Конструктор с входным параметром worth
- worth = _worth;
- }
- virtual double Taxes() = 0; //Чисто виртуальная функция считающая налоги
- };
- class Appartment : public Property {
- public:
- Appartment(double _worth) : Property(_worth) {} //Конструктор для Apprtment
- double Taxes() { //Переопределение ф-и считающей налоги для Appartment
- return worth / 1000;
- }
- };
- class Car : public Property {
- public:
- Car(double _worth) : Property(_worth) {} //Конструктор для Car
- double Taxes() { //Переопределение ф-и считающей налоги для Car
- return worth / 200;
- }
- };
- class CountryHouse : public Property {
- public:
- CountryHouse(double _worth) : Property(_worth) {} //Конструктор для CountryHouse
- double Taxes() { //Переопределение ф-и считающей налоги для CountryHouse
- return worth / 500;
- }
- };
- int main()
- {
- Property* props[7]; //Создаём массив указателей Property
- props[0] = new Appartment(10000);
- props[1] = new Appartment(22000);
- props[2] = new Appartment(15000);
- props[3] = new Car(250000);
- props[4] = new Car(15000);
- props[5] = new CountryHouse(5000);
- props[6] = new CountryHouse(12000);
- for (int i = 0; i < 7; i++) {
- cout << props[i]->Taxes() << endl;
- }
- delete[] props; //Освобождаем память
- return 0;
- }
Add Comment
Please, Sign In to add comment