#include #include using namespace std; class Device // Родительский класс { private: string creationPlace; // Три члена родительского класса int * guaranteeTime; // В годах string brand; public: void setPlace(const string &n) // Сеттеры { creationPlace = n; } void setGuarantee(int &n) { if(guaranteeTime) *guaranteeTime = n; } void setBrand(const string &n) { brand = n; } string getPlace() // Геттеры { return creationPlace; } string getBrand() { return brand; } int getGuarantee() { if(guaranteeTime) return *guaranteeTime; return 0; } virtual void switchState() = 0; //чистые виртуальные функции virtual void changeVolume(float) = 0; Device() // Коструктор для создания динамического члена guaranteeTime { guaranteeTime = new int; }; virtual ~Device() //Виртуальный деструктор { delete guaranteeTime; }; }; class Monitor : public Device //наследуем Монитор от класса Device { private: int * Brightness; // Яркость монитора 0 - 255 bool State = false; // Включен / Выключен , изначально монитор выключен float Volume; // Громкость звука ( на соверменных мониторах есть динакмики) от 0 до 100 public: void changeVolume(float n) override // Перегруженный метод абстрактного класса { if(n >= 0 && n <= 100) Volume = n; } void switchState() override // Перегруженный метод абстрактного класса { State ^= true; //Переключаем режим, если был выключен - станет включен и наоборот } Monitor() // Констуктор по умолчанию, создает динамическйи член яркость экрана { Brightness = new int; } virtual ~Monitor() final //Деструктор класса монитор { delete Brightness; }; void setBrightness(int n) { if(Brightness && n >= 0 && n <= 255) *Brightness = n; } bool getState() { return State; }; int getBrightness() { if(Brightness) return *Brightness; return 0; } float getVolume() { return Volume; } Monitor& operator=(const Monitor &m) // Оператор присваивания { if(this == &m) // Если присваемваем объект самому себе return *this; *Brightness = *m.Brightness; Volume = m.Volume; State = m.State; return *this; } Monitor(const Monitor &m) : Volume(m.Volume), State(m.State) // Конструктор копирования { Brightness = new int; *Brightness = *m.Brightness; } }; int main() { Monitor LG; cout << LG.getBrightness() << endl; LG.setBrightness(55); cout << LG.getBrightness() << endl << endl; Monitor SSG(LG); // Констуктор копирования вызывается здесь cout << SSG.getBrightness() << endl; SSG.setBrand("SmartEurope"); cout << SSG.getBrand(); return 0; }