labs 1-6: init

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2022-12-24 14:03:08 +05:30
commit ad185c994e
26 changed files with 2250 additions and 0 deletions

56
lab2/5.cpp Normal file
View File

@@ -0,0 +1,56 @@
#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;
}