Alarm clock multiple issues

Hello, I have an alarm clock assignment. I tried for days, but I don't ave enough knowledge to make it.
Here is a part of the assignment:
Include 2 constructors. One constructor should be the default constructor that will initialize the object to 12:00:00 AM. The second constructor should take parameters for hours, minutes, seconds, and AM/PM. Both constructors will provide the private members with the time. In addition, have both constructors set the alarm clock as off. (You will need a Boolean variable that determines whether the alarm is on or off). The function or method you use to set the alarm will set the alarm on.
(I need an advice for setting the alarm to off and on)

Allow the clock to increment to the next second. (Hint: You need to take into account things like if the clock's time is 11:59:59 AM and you increment by a second, the time will be 12:00:00 PM. You may need to consider some iterated if statements.) - This is completely impossible for me.
Here is my code so far. I am still working on it, but I need some advice on the major mistakes that I have.
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
#ifndef ALARMCLOCK_H
#define ALARMCLOCK_H

class alarmClock
{
public:
	alarmClock();
	alarmClock(int, int, int, char);
	
	void setTime( int, int, int, char);
	void setHour( int);
	void setMin(int );
	void setSecond( int);
	void setAM( char);
	
	alarmClock& operator++ ();
			
	int getHour();
	int getMinute();
	int getSecond();
	bool getAM();
	
	void displayTime();
	void setAlarm();
	void displayAlarm();
	void wakeUp();
	
	
		
private:
	int hour, minute, second;
	int alHour, alMinute, alSecond;
	char am;
	bool alarmOff;	
	
}

#endif 


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;)
	}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include "alarmClock.h"
#include "alarmClock.cpp"

using namespace std;

int main()
{
	int counter = 0;
	alarmClock Time;
	alarmClock Alarm;
	Time.displayTime();
	for(int i = 0; i < counter; i++) 
	{ second++;}
      
	Alarm.setAlarm();
	Alarm.displayAlarm();
	Alarm.wakeUp();

}
Last edited on
Topic archived. No new replies allowed.