/* Copyright © 2007 Ankur Banerjee. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. http://www.fsf.org/licensing/licenses/lgpl.html /
/ Constructors – Time /
#include <iostream.h>
#include <conio.h>
class time
{
int h, m, s;
public:
time()
{
h = m = s = 0;
}
time (int hh, int mm, int ss)
{
h = hh;
m = mm;
s = ss;
}
void disp()
{
cout<<endl<<“Added time duration is “<<h<<” : “
<<m<<” : “<<s;
}
time add(time time1, time time2)
{
time time3;
time3.s = (time1.s + time2.s) % 60;
time3.m = ((time1.m + time2.m) % 60) + ((time1.s + time2.s) / 60);
time3.h = (time1.h + time2.h) + ((time1.m + time2.m) / 60);
return time3;
}
} ;
void main()
{
clrscr();
int h, m, s;
cout<<“Enter time durations in HH MM SS format”<<endl
<<“Enter time duration 1 : “<<endl;
cin>>h>>m>>s;
time t1(h, m, s);
cout<<“Enter time duration 2 : “<<endl;
cin>>h>>m>>s;
time t2(h, m, s);
time t3 = t1.add(t1, t2);
t3.disp();
getch();
}
/ Output */
Enter time durations in HH MM SS format
Enter time duration 1 : 5 14 9
Enter time duration 2 : 4 6 53
Added time duration is 9 : 21 : 2