-
Notifications
You must be signed in to change notification settings - Fork 1
/
Lab_solution_37.cpp
110 lines (94 loc) · 2.38 KB
/
Lab_solution_37.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include <string>
using namespace std;
class Device
{
public:
std::string getModel()
{
return m_model;
}
int getSystemID()
{
return m_systemID;
}
void setModel(std::string const model) { m_model = model; }
void setSystemID(int systemID) { m_systemID = systemID; }
protected:
std::string m_model;
private:
int m_systemID = 0;
};
class Client
{
public:
void init()
{
cout << "Init Client" << "\n";
}
void connect()
{
cout << "Connect Client" << "\n";
m_isConnected = true;
}
void shutdown()
{
cout << "Shutdown Client" << "\n";
m_isConnected = false;
}
bool getConnStatus()
{
return m_isConnected;
}
void setConnStatus(bool isConnected) { m_isConnected = isConnected; }
private:
bool m_isConnected = false;
};
class Lightbulb : public Device, public Client
{
public:
bool getBrightness()
{
return m_brightness;
}
private:
int m_brightness;
};
class Thermostat : public Device, public Client
{
public:
bool getClimState()
{
return m_climState;
}
private:
bool m_climState;
};
class Irrigation : public Device, public Client
{
public:
bool getMonitorInterval()
{
return m_monitorInterval;
}
private:
bool m_monitorInterval;
};
int main()
{
// Device** devices = new Device*[3];
Device* devices[3];
for(int i=0; i<3; i++)
{
devices[i] = new Device();
}
Lightbulb* myLightbulb = static_cast<Lightbulb*>(devices[0]);
Thermostat* myThermostat = static_cast<Thermostat*>(devices[1]);
Irrigation* myIrrigation = static_cast<Irrigation*>(devices[2]);
std::cout << "LightBulb Brightness: " << myLightbulb->getBrightness() << "\n";
std::cout << "Thermostat Clim State: " << myThermostat->getClimState() << "\n";
std::cout << "Irrigation Monitor Interval: " << myIrrigation->getMonitorInterval() << "\n";
static_cast<Client*>(myLightbulb)->connect();
static_cast<Client*>(myThermostat)->connect();
static_cast<Client*>(myIrrigation)->connect();
}