62 lines
1023 B
C++
62 lines
1023 B
C++
#include "time.h"
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
|
|
//init hour, minute, second to 0
|
|
Time::Time() {
|
|
hour = 0;
|
|
minute = 0;
|
|
second = 0;
|
|
}
|
|
|
|
Time::Time(int h, int m, int s) {
|
|
hour = h;
|
|
minute = m;
|
|
second = s;
|
|
}
|
|
|
|
int Time::getHour() const {
|
|
return hour;
|
|
}
|
|
int Time::getMinute() const {
|
|
return minute;
|
|
}
|
|
int Time::getSecond() const {
|
|
return second;
|
|
}
|
|
|
|
void Time::setHour(int h) {
|
|
hour = h;
|
|
}
|
|
void Time::setMinute(int m) {
|
|
minute = m;
|
|
}
|
|
void Time::setSecond(int s) {
|
|
second = s;
|
|
}
|
|
|
|
void Time::PrintAMPM() const {
|
|
int hh = hour;
|
|
std::string ampm = "am";
|
|
|
|
if (hh == 0) {
|
|
hh = 12;
|
|
} else if (hh == 12) {
|
|
ampm = "pm";
|
|
} else if (hh > 12) {
|
|
hh -= 12;
|
|
ampm = "pm";
|
|
}
|
|
|
|
std::cout << hh << ":";
|
|
|
|
if (minute < 10) {
|
|
std::cout << "0" << minute << ":";
|
|
} else {
|
|
std::cout << minute << ":";
|
|
}
|
|
|
|
std::cout << std::setfill('0') << std::setw(2) << second;
|
|
std::cout << " " << ampm << std::endl;
|
|
}
|