-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnergyControlManager.cpp
134 lines (112 loc) · 2.62 KB
/
EnergyControlManager.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
#pragma once
#include "EnergyControlManager.h"
#include <limits>;
using std::cin;
using std::cout;
using std::endl;
using std::string;
void EnergyControlManager::setDeviceOnOff(int roomNumber) {
Room *room = module.getRoom(roomNumber);
string name;
int id;
bool value;
system("cls");
room->showVerbose();
while (true) {
cout << "설정하고 싶은 기기의 이름, 번호, 값(ON=1, OFF=0)을 순서대로 "
"입력하세요('나가기'로 뒤로가기)>>";
cin >> name;
if (name == "나가기")
break;
cin >> id >> value;
cin.clear();
cin.ignore(100, '\n');
bool res = room->setDeviceOnOff(name, id - 1, value);
if (res) {
system("cls");
room->inspect();
room->showVerbose();
} else {
cout << "입력이 잘못되었습니다." << endl;
}
}
}
void EnergyControlManager::addDevice(int roomNumber) {
Room *room = module.getRoom(roomNumber);
string name;
system("cls");
room->showVerbose();
while (true) {
cout << "추가하기 원하는 장비(조명,에어컨,TV, 컴퓨터,실험장비)의 이름을 "
"입력하세요(뒤로 가려면 '나가기')>>";
getline(cin, name);
if (name == "나가기")
break;
bool res = room->addDevice(name);
if (res) {
system("cls");
room->inspect();
room->showVerbose();
} else {
cout << "입력이 잘못되었습니다." << endl;
}
}
}
void EnergyControlManager::inRoom(int roomNumber) {
int input;
Room *room = module.getRoom(roomNumber);
system("cls");
room->inspect();
room->showVerbose();
while (true) {
cout << "1. 기기 추가하기 2. 기기 전원관리하기(뒤로 가려면 '-1')>>";
cin >> input;
cin.ignore();
switch (input) {
case 1:
addDevice(roomNumber);
system("cls");
room->showVerbose();
break;
case 2:
setDeviceOnOff(roomNumber);
system("cls");
room->showVerbose();
break;
case -1:
return;
default:
cout << "입력이 잘못되었습니다." << endl;
cin.clear();
cin.ignore(100, '\n');
break;
}
}
}
void EnergyControlManager::run() {
int roomNumber;
module.inspect();
system("cls");
module.show();
while (true) {
cout << "이동하고싶은 호실 번호를 입력하세요(종료하려면 '-1')>>";
cin >> roomNumber;
cin.ignore();
if (roomNumber == -1)
return;
if (cin.fail()) {
cout << "입력이 잘못되었습니다." << endl;
cin.clear();
cin.ignore(100, '\n');
continue;
}
if (roomNumber < 101 || roomNumber > 116) {
cout << "입력이 잘못되었습니다." << endl;
continue;
}
inRoom(roomNumber);
system("cls");
module.inspect();
module.show();
}
}