/******************************************************************************************** example 5 -- miltime.cpp Developing the military time class ********************************************************************************************/ #include "miltime.h" #include <iostream> using namespace std; //------- Enhanced Default Constructor ------- miltime::miltime(const int h, const int m, const int s) { hour=0; minute = 0; second = 0; addSecond(s); addMinute(m); addHour(h); } //------- Print the object in "pretty" format ------- void miltime::print(ostream& out) const { if (hour < 10) cout << '0'; cout << hour << ':'; if (minute < 10) cout << '0'; cout << minute << ':'; if (second < 10) cout << '0'; cout << second; }; //------- "managed" addition functions ------- void miltime::addHour(const int h) { hour = (hour + h) % 24; } void miltime::addMinute(const int m) { addHour((minute + m) / 60); minute = (minute + m) % 60; } void miltime::addSecond(const int s) { addMinute((second + s)/60); second = (second + s) % 60; } void miltime::addSame(const miltime& mt) { addHour(mt.hour); addMinute(mt.minute); addSecond(mt.second); }