-
Notifications
You must be signed in to change notification settings - Fork 0
/
HW33.cpp
117 lines (114 loc) · 2.55 KB
/
HW33.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
#include<stdio.h>
#pragma warning (disable : 4996)
#define LINE printf("------------------------------------------------------------------\n")
int menu(const char*);
unsigned short inputFanNumber(const char*);
void openFan(unsigned short*);
void offFan(unsigned short*);
void reverseFan(unsigned short*);
void displayFan(unsigned short*);
void myflush();
int main()
{
int m;
unsigned short fan=0;
while (1) {
m = menu("1. 환풍기 열기 / 2. 환풍기 닫기 / 3. 환풍구 전체 전환 / 4. 종료 : ");
if (m == 4) { break; }
switch (m) {
case 1:
openFan(&fan);
displayFan(&fan);
break;
case 2:
offFan(&fan);
displayFan(&fan);
break;
case 3:
reverseFan(&fan);
displayFan(&fan);
break;
default:;
}
}
return 0;
}
int menu(const char* msg)
{
int res;
printf("%s", msg);
scanf("%d",&res);
while (1) {
if ((res >= 1) && (res <= 4)) {break;}
myflush();
printf("* 잘못 입력하셨습니다. 다시 입력하세요.\n");
LINE;
printf("%s", msg);
scanf("%d", &res);
}
LINE;
return res;
}
unsigned short inputFanNumber(const char* msg)
{
int input;
printf("%s",msg);
scanf("%d", &input);
while (1) {
if ((input >= 1) && (input <= 8)) { break; }
myflush();
printf("* 잘못 입력하셨습니다. 다시 입력하세요.\n");
LINE;
printf("%s", msg);
scanf("%d", &input);
}
return input;
}
void openFan(unsigned short* fan)
{
printf("\t\tFan 열기 작업 실행 화면\n");
LINE;
unsigned short fanNumber, fanCondition, fann = 1;
fanNumber = inputFanNumber("* OPEN할 FAN 번호를 입력하시오(1-8) : ");
LINE;
fanCondition = *fan & (fann << (fanNumber - 1));
fann <<= (fanNumber - 1);
if (fanCondition) { printf("%s", "이미 열려있는 FAN입니다.\n"); LINE;}
else { *fan |= fann; }
}
void offFan(unsigned short* fan)
{
printf("\t\tFan 닫기 작업 실행 화면\n");
LINE;
unsigned short fanNumber, fanCondition, fann = 1;
fanNumber = inputFanNumber("* OPEN할 FAN 번호를 입력하시오(1-8) : ");
LINE;
fanCondition = *fan & (fann << (fanNumber - 1));
fann <<= (fanNumber - 1);
if (fanCondition) { *fan ^= fann; }
else { printf("%s", "이미 닫혀있는 FAN입니다.\n"); LINE;}
}
void reverseFan(unsigned short* fan)
{
*fan = ~*fan;
printf("전체 FAN의 상태가 전환되었습니다. (ON, OFF 상태 뒤바뀜)\n");
LINE;
}
void displayFan(unsigned short* fan)
{
unsigned char fanCondition;
for (int i = 8; i > 0; i--) {printf("%3d%s", i,"번FAN");}
printf("\n");
for (int i = 7; i >= 0; i--) {
fanCondition = 1;
if (*fan & fanCondition << i) { printf("%8s","ON"); }
else { printf("%8s","OFF"); }
}
printf("\n");
LINE;
printf("\n\n");
}
void myflush()
{
while (getchar() != '\n') { ; }
}