-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathCeilingFan.hpp
80 lines (72 loc) · 1.25 KB
/
CeilingFan.hpp
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
#ifndef CEILING_FAN_H
#define CEILING_FAN_H
#include <iostream>
#include <string>
#include <string_view>
class CeilingFan {
public:
enum class Speed { OFF, LOW, MEDIUM, HIGH };
CeilingFan (std::string_view l) : location(l) { }
void high();
void medium();
void low();
void off();
std::string getSpeedStr() const;
Speed getSpeed() const { return speed; }
private:
std::string location;
Speed speed = Speed::OFF;
};
inline
void
CeilingFan::high()
{
speed = Speed::HIGH;
std::cout << location << " ceiling fan set to high\n";
}
inline
void
CeilingFan::medium()
{
speed = Speed::MEDIUM;
std::cout << location << " ceiling fan set to medium\n";
}
inline
void
CeilingFan::low()
{
speed = Speed::LOW;
std::cout << location << " ceiling fan set to low\n";
}
inline
void
CeilingFan::off()
{
speed = Speed::OFF;
std::cout << location << " ceiling fan set to Off\n";
}
inline
std::string
CeilingFan::getSpeedStr() const
{
std::string result;
switch (speed) {
case Speed::HIGH:
result = "high";
break;
case Speed::MEDIUM:
result = "medium";
break;
case Speed::LOW:
result = "low";
break;
case Speed::OFF:
result = "off";
break;
default:
result = "error";
break;
}
return result;
}
#endif /* CEILING_FAN_H */