#include <iostream>
#include <vector>
#include <string>
using namespace std;
ZU-044
class SmartDevice {
protected:
string deviceName;
bool isOn;
public:
SmartDevice(string name):deviceName(name), isOn(false) {}
virtual void turnOn() {
isOn = true;
Farid Sariyev
cout << deviceName << " is turned ON." << endl;
}
virtual void turnOff() {
isOn = false;
cout << deviceName << " is turned OFF." << endl;
}
virtual void status() {
cout << deviceName << " is currently "
<< (isOn ? "ON" : "OFF") << endl;
}
virtual ~SmartDevice() {}
};
class SmartLight : public SmartDevice {
private:
int brightness;
public:
SmartLight(string name) : SmartDevice(name), brightness(50) {}
void setBrightness(int level) {
if (level >= 0 && level <= 100) {
brightness = level;
cout << deviceName << " brightness set to "
<< brightness << "%" << endl;
}
}
void status() override {
SmartDevice::status();
cout << "Brightness: " << brightness << "%" << endl;
}
};
class SmartThermostat : public SmartDevice {
private:
double temperature;
public:
SmartThermostat(string name) : SmartDevice(name), temperature(22.0) {}
void setTemperature(double temp) {
temperature = temp;
cout << deviceName << " set to " << temperature << "°C" << endl;
}
void status() override {
SmartDevice::status();
cout << "Temperature: " << temperature << "°C" << endl;
}
};
class SecuritySystem : public SmartDevice {
private:
bool isArmed;
public:
SecuritySystem(string name) : SmartDevice(name), isArmed(false) {}
void arm() {
isArmed = true;
cout << deviceName << " is ARMED." << endl;
}
void disarm() {
isArmed = false;
cout << deviceName << " is DISARMED." << endl;
}
void status() override {
SmartDevice::status();
cout << "Security Status: "
<< (isArmed ? "ARMED" : "DISARMED") << endl;
}
};
class SmartHomeSystem {
private:
vector<SmartDevice*> devices;
public:
void addDevice(SmartDevice* device) {
devices.push_back(device);
}
void controlAllDevices(bool state) {
for (auto& device : devices) {
state ? device->turnOn() : device->turnOff();
}
}
void showAllDevicesStatus() {
for (auto& device : devices) {
device->status();
cout<<" "<<endl;
}
}
};
int main()
{
SmartHomeSystem home;
SmartLight* livingRoomLight = new SmartLight("Living Room Light");
[Link](livingRoomLight);
SmartThermostat* homeThermostat = new SmartThermostat("Home Thermostat");
[Link](homeThermostat);
SecuritySystem* mainSecurity = new SecuritySystem("Main Security");
[Link](mainSecurity);
[Link](true);
cout << endl;
livingRoomLight->setBrightness(75);
homeThermostat->setTemperature(24.5);
mainSecurity->arm();
cout << "\nFinal Home System Status:" << endl;
[Link]();
delete livingRoomLight;
delete homeThermostat;
delete mainSecurity;
return 0;
}