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
|
#include <iostream>
#include <iomanip>
using namespace std;
#include <stdexcept>
#include "alarmClock.h"
alarmClock::alarmClock()
{
setTime(int hour = 12, int minute = 0, int second = 0, char am = 'AM');
}
alarmClock::alarmClock(int hour, int minute, int second, char am)
{
setTime(hour, minute, second, am);
}
void alarmClock::setTime( int hour, int minute, int second, char am)
{
setHour(hour);
setMin(minute);
setSecond(second);
setAM(am);
}
void alarmClock::setHour( int hr)
{
if (hr >=0 && hr < 12)
hour = hr;
else
throw invalid_argument("Hour must be 0-11");
}
void alarmClock::setMin(int min )
{
if (min >=0 && min < 60)
minute = min;
else
throw invalid_argument("Minute must be 0-59");
}
void alarmClock::setSecond( int sec)
{
if (sec >=0 && sec < 60)
second = sec;
else
throw invalid_argument("Second must be 0-59");
}
void alarmClock::setAM( char am)
{
if(am == 'AM')
am == 'AM';
else
am == 'PM';
}
alarmClock& alarmClock::operator++()
{
if(second != 59)
++second;
else
{
second = 0;
if(minute != 59)
++minute;
else
{
minute = 0;
setHour(hour + 1);
}
return *this;
}
int alarmClock::getHour()
{
return hour;
}
int alarmClock::getMinute()
{
return minute;
}
int alarmClock::getSecond()
{
return second;
}
bool alarmClock::getAm()
{
return am;
}
void alarmClock::displayTime()
{
cout << setfill('0') << setw(2) << hour << ":" << setfill('0') << setw(2)
<< minute << ":" << setfill('0') << setw(2) << second << " " << setAM << endl;
}
void alarmClock::setAlarm()
{
char dot = ":"
cout << "Please, enter the alarm time in the form 12:00:00 AM:"
cin >> alHour;
cin.get(dot);
cin >> alMinute;
cin.get(dot);
cin >> alSecond;
getAM(am);
bool alarmOff = false;
}
void alarmClock::displayAlarm()
{
cout << "Alarm time was set on " << setfill('0') << setw(2) << alHour << ":" << setfill('0') << setw(2)
<< alMinute << ":" << setfill('0') << setw(2) << alSecond << " " << setAM << endl;
}
void alarmClock::wakeUp()
{
if(hour == alHhour && minute == alMinute && second == alSecond)
cout << "WAKE UP!!!" << endl;)
}
|