-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCorridor.cpp
executable file
·149 lines (130 loc) · 2.91 KB
/
Corridor.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <iostream>
#include "Corridor.h"
void Corridor::initializeCorridorInsturments()
{
initializeLights();
initializeAirConditioner();
}
void Corridor::initializeLights()
{
for(int i = 0; i < noOfLights ; i++)
{
lights.push_back( new Light( i + 1, POWER_UNITS_PER_LIGHT));
if(cType == MAIN)
{
lights[i]->on();
powerConsumption += POWER_UNITS_PER_LIGHT;
}
}
}
void Corridor::initializeAirConditioner()
{
for(int i = 0; i < noOfACs ; i++)
{
airCons.push_back( new AirConditioner( i + 1, POWER_UNITS_PER_AC));
airCons[i]->on();
powerConsumption += POWER_UNITS_PER_AC;
}
}
int Corridor::powerConsumptionAtPresent()
{
return (powerConsumptionByLights() + powerConsumptionByAC());
}
int Corridor::powerConsumptionByLights()
{
int powerConsumed = 0;
for(unsigned int i = 0; i < lights.size(); i++)
{
powerConsumed += lights[i]->getUnit();
}
cout<<" Power Consumed By Lights : " << powerConsumed << endl;
return powerConsumed;
}
int Corridor::powerConsumptionByAC()
{
int powerConsumed = 0;
for(unsigned int i = 0; i < airCons.size(); i++)
{
powerConsumed += airCons[i]->getUnit();
}
cout<<" Power Consumed By ACs : " << powerConsumed << endl;
return powerConsumed;
}
void Corridor::switchOnLights()
{
cout<<"Entering switch On Lights" << endl;
controller = new PowerControl();
for(int i = 0; i < noOfLights ; i++)
{
lightOn = new LightOnCommand(lights[i]);
controller->setCommand(lightOn);
controller->execute();
powerConsumption += POWER_UNITS_PER_LIGHT;
}
}
void Corridor::switchOffLights()
{
controller = new PowerControl;
for(int i = 0; i < noOfLights ; i++)
{
lightOff = new LightOffCommand(lights[i]);;
controller->setCommand(lightOff);
controller->execute();
powerConsumption -= POWER_UNITS_PER_LIGHT;
}
}
void Corridor::switchOnACs()
{
controller = new PowerControl;
for(int i = 0; i < noOfACs ; i++)
{
acOn = new AirConditionerOnCommand(airCons[i]);
controller->setCommand(acOn);
controller->execute();
powerConsumption += POWER_UNITS_PER_AC;
}
}
void Corridor::switchOffACs()
{
controller = new PowerControl;
for(int i = 0; i < noOfACs ; i++)
{
acOff = new AirConditionerOffCommand(airCons[i]);
controller->setCommand(acOff);
controller->execute();
powerConsumption -= POWER_UNITS_PER_AC;
}
}
void Corridor::getLightsStatus()
{
for(unsigned int i = 0; i < lights.size() ; i++)
{
if(lights[i]->isOn())
{
cout<<" Light " << i + 1 << " is ON" <<endl;
}
else
{
cout<<" Light " << i + 1 << " is OFF" <<endl;
}
}
}
void Corridor::getACsStatus()
{
for(unsigned int i = 0; i < airCons.size() ; i++)
{
if(airCons[i]->isOn())
{
cout<<" AC " << i + 1 << " is ON" <<endl;
}
else
{
cout<<" AC " << i + 1 << " is OFF" <<endl;
}
}
}
void Corridor::getStatus()
{
getLightsStatus();
getACsStatus();
}