#include <bits/stdc++.h>
using namespace std;
class Time{
int hours, minutes;
public:
Time(){}
Time(int hrs, int min){
hours = hrs;
minutes = min;
if(hours > 23) hours = 23;
if(minutes > 59) minutes = 59;
}
void show(){
cout<<this->hours<<":";
if(this->minutes < 10) cout<<0;
cout<<this->minutes<<endl;
}
Time add(int m){
this->minutes += m;
while(minutes >= 60){
this->minutes -= 60;
this->hours++;
}
while(this->hours > 23) this->hours -= 24;
return *this;
}
};
int main(){
Time time[4] = {Time(23, 59), Time(24, 67), Time(0, 0), Time(3, 0)};
for(int i = 0; i < 4; i++) time[i].show();
cout<<endl;
time[0].add(2).show();
time[1].add(1).show();
time[2].add(60).show();
time[3].add(2881).show();
return 0;
}
Comments
Leave a comment