-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDevice.cpp
121 lines (106 loc) · 3.15 KB
/
Device.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
//Jeff Henebury
//implementation of the Device class
//this is the base class form which all the other devices (vacuum, lights, etc.) inherit from
#include "Device.h"
#include <iostream>
using namespace std;
Device::Device()
{
deviceSound = "Click! I'm a generic device!"; //will be overloaded for each device
power = false; //start with power turned off
DeviceSchedule;
//for vacuum and lights, list of rooms
rooms.push_back("Living Room");
rooms.push_back("Dining Room");
rooms.push_back("Bedroom");
rooms.push_back("Kitchen");
}
Device ::~Device()
{
}
void Device::doAction() //mimics the device doing its thing
{
cout <<"\n" << deviceSound << endl;
}
void Device::getSchedule()
{
DeviceSchedule.printWeeklySchedule();
}
bool Device::validateScheduleInput(int millTime)
{//making sure that the input time is in military time
if (millTime >= 0 && millTime <= 2400) {
return true;
}
else
{
return false;
}
}
void Device::setSchedule()
{
//get the schedule in military time, error check for bad input
std::cout << "Let's set the schedule for your device." <<
"Please use military time(i.e., '1750' for 5:30 PM\n";
//do full week for now, give option for single day if there's time...
int dayTurnOnTime;
std::cout << "\nTurn-on time during the day: ";
cin >> dayTurnOnTime;
if (!validateScheduleInput(dayTurnOnTime)) {
cout << "Sorry, that isn't in military time (0-2400). Please try again.\n";
return;
}
std::cout << "\nTurn-off time during the day: ";
int dayTurnOffTime;
cin >> dayTurnOffTime;
if (!validateScheduleInput(dayTurnOffTime)) {
cout << "Sorry, that isn't in military time (0-2400). Please try again.\n";
return;
}
std::cout << "\nTurn-on time during the evening: ";
int nightTurnOnTime;
cin >> nightTurnOnTime;
if (!validateScheduleInput(nightTurnOnTime)) {
cout << "Sorry, that isn't in military time (0-2400). Please try again.\n";
return;
}
std::cout << "\nTurn-off time during the evening: ";
int nightTurnOffTime;
cin >> nightTurnOffTime;
if (!validateScheduleInput(nightTurnOffTime)) {
cout << "Sorry, that isn't in military time (0-2400). Please try again.\n";
return;
}
DeviceSchedule.setWeeklySchedule(dayTurnOnTime, dayTurnOffTime, nightTurnOnTime, nightTurnOffTime);
std::cout << "\nThank you! Printing the schedule:";
DeviceSchedule.printWeeklySchedule();
}
void Device::getPowerStatus() {
if (power) {
cout << "The device is powered ON.\n";
}
else {
cout << "The device is powered OFF.\n";
}
}
void Device::onOrOff()
{
int inp;
cout << "Would you like the Device:\n1.ON\n2.OFF\n";
cout << "Please enter 1 or 2: ";
cin >> inp;
if (inp == 1) { //on, so true
cout << "\nYou have powered the device ON.\n";
power = true; //turn power on
doAction();
}
else {
cout << "You have powered the device OFF.\n";
power = false; //turn power off
}
}
void Device::TestMorningOn() {
//int morningTimeOn = DeviceSchedule.Sunday.turnOnTime_day;
//cout << "TEST #2 with method TestMorningOn, Sunday morning on time: " << morningTimeOn << endl;
int morningTimeOn = DeviceSchedule.weeklySchedule[0].turnOnTime_day;
cout << "TEST #2 with method TestMorningOn, Sunday morning on time: " << morningTimeOn << endl;
}