-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyclock.cpp
More file actions
39 lines (34 loc) · 885 Bytes
/
Copy pathmyclock.cpp
File metadata and controls
39 lines (34 loc) · 885 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <cstddef>
#include <iomanip>
#include "myclock.h"
void Clock::Reset(unsigned int h,unsigned int m,unsigned int am) {
m_hour = h % 12;
m_min = m % 60;
m_AM_PM = am % 2;
}
void Clock::ChangeAmPm() {
if (m_AM_PM == 0) {
m_AM_PM = 1;
}
else {
m_AM_PM = 0;
}
}
void Clock::AddMin(unsigned int mins) {
unsigned int add_min = mins + m_min;
unsigned int add_hour = add_min / 60;
m_min = add_min % 60;
unsigned int m_AM_PM_turns = (m_hour + add_hour)/12;
m_hour = (m_hour + add_hour)%12;
for(unsigned int i=0;i<m_AM_PM_turns;i++) {
ChangeAmPm();
}
}
void Clock::PrintTime() {
cout << setfill('0') << setw(2) << m_hour << ":" << setfill('0') << setw(2) << m_min << " " << ((m_AM_PM == 1)?"PM":"AM");
}