time.h
class time{
private:
int hours;
int minutes;
int second;
public:
time();
time(int h, int m, int s);
void normalize();
void reset(int h, int m, int s);
void advance(int h, int m, int s);
void print();
};
time.cpp
#include <iostream>
#include "time.h"
using namespace std;
time::time()
{
hours = 0;
minutes = 0;
second = 0;
}
time::time(int h, int m, int s)
{
hours = h;
minutes = m;
second = s;
}
void time::normalize()
{
minutes += second / 60;
second %= 60;
hours += minutes / 60;
minutes %= 60;
hours %= 24;
}
void time::reset(int h, int m, int s)
{
hours = h;
minutes = m;
second = s;
normalize();
}
void time::advance(int h, int m, int s)
{
hours += h;
minutes += m;
second += s;
normalize();
}
void time::print()
{
cout << hours << ':' << minutes << ':' << second << endl;
}
main.cpp
#include <iostream>
#include "time.h"
using namespace std;
int main()
{
int h, m, s;
time t1;
t1.print();
cout << "Enter The Hours : ";
cin >> h;
cout << "Enter The Minutes : ";
cin >> m;
cout << "Enter The Seconds : ";
cin >> s;
t1.reset(h, m, s);
t1.print();
t1.advance(70, 100, 400);
cout << "After the increase :\\n";
t1.print();
}