#include <iostream>
using namespace std;
class time {
private:
int hrs; //HOURS
int mins; //MINUTES
int secs; //SECONDS
public:
time(): hrs(0), mins(0), secs(0)
{ }
time(int h, int m, int s): hrs(h), mins(m), secs(s)
{ }
void showtime();
time sumtime(time, time);
};
void time::showtime() {
cout << hrs <<":"<< mins <<":"<< secs << endl;
}
time time::sumtime(time tt1, time tt2) {
time tt;
tt.secs = (tt1.secs + tt2.secs) % 60;
int temp;
temp = (tt1.secs + tt2.secs) / 60;
tt.mins = 0;
tt.mins = (tt1.mins + tt2.mins + temp) % 60;
tt.hrs = 0;
temp = (tt1.mins + tt2.mins + temp) / 60;
tt.hrs = (tt1.hrs + tt2.hrs) + temp;
return tt;
}
int main() {
time t1(1,23,46);
time t2(23,45,34);
time t3;
t3 = t3.sumtime(t1, t2);
t3.showtime();
return 0;
}
Comments
Leave a comment