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