/********************************************************************************************
example 4 -- 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)
        out << '0';
    out << hour << ':';
    if (minute < 10)
        out << '0';
    out << minute << ':';
    if (second < 10)
        out << '0';
    out << 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;
}