0% found this document useful (0 votes)
152 views1 page

Smart Home System C++ Implementation

The document contains C++ code for a smart home system that includes classes for various smart devices such as SmartLight, SmartThermostat, and SecuritySystem, all derived from a base class SmartDevice. It allows for controlling the devices, adjusting their settings, and displaying their statuses. The main function demonstrates the creation of these devices, their addition to the smart home system, and controlling their states.

Uploaded by

Fərit Sarıyev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views1 page

Smart Home System C++ Implementation

The document contains C++ code for a smart home system that includes classes for various smart devices such as SmartLight, SmartThermostat, and SecuritySystem, all derived from a base class SmartDevice. It allows for controlling the devices, adjusting their settings, and displaying their statuses. The main function demonstrates the creation of these devices, their addition to the smart home system, and controlling their states.

Uploaded by

Fərit Sarıyev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#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;
}

You might also like