Files
ooplab/lab2/5.cpp
Amneesh Singh ad185c994e labs 1-6: init
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
2022-12-24 14:03:08 +05:30

57 lines
759 B
C++

#include <iostream>
using namespace std;
class Time {
private:
uint h, m, s;
public:
Time() = default;
Time(uint, uint, uint);
Time operator+(Time);
void display();
};
Time::Time(uint h, uint m, uint s) {
if (m > 59 || s > 59)
exit(1);
this->h = h;
this->m = m;
this->s = s;
}
void Time::display() {
cout << "Hours: " << this->h << endl
<< "Minutes: " << this->m << endl
<< "Seconds: " << this->s << endl;
}
Time Time::operator+(Time op) {
Time t;
t.h = this->h + op.h;
t.m = this->m + op.m;
t.s = this->s + op.s;
t.m += t.s / 60;
t.s %= 60;
t.h += t.m / 60;
t.m %= 60;
return t;
}
int main() {
Time t;
Time a(64, 32, 7);
Time b(3, 59, 53);
t = a + b;
t.display();
return 0;
}