Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C++ Compiler.
- Code, Compile, Run and Debug C++ program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <iostream>
- #include <cstring>
- #include <cmath>
- using namespace std;
- // Online C++ compiler to run C++ program online
- class Clock
- {
- private:
- int hour;
- int min;
- int sec;
- public:
- Clock()
- {
- this->hour=0;
- this->min=0;
- this->sec=0;
- }
- Clock(int hour,int min,int sec)
- {
- this->hour=hour;
- this->min=min;
- this->sec=sec;
- }
- void info()
- {
- cout<<hour<<":"<<min<<":"<<sec<<endl;
- }
- int miliseconds()
- {
- return 1000*(3600* this->hour + 60* this->min + this->sec);
- }
- friend Clock operator+(const Clock &a,const Clock &b)
- {
- Clock c;
- c.hour=a.hour+b.hour;
- c.min=a.min+b.min;
- c.sec=a.sec+b.sec;
- return c;
- }
- friend Clock operator-(const Clock &a,const Clock &b)
- {
- Clock c;
- c.hour=a.hour-b.hour;
- c.min=a.min-b.min;
- c.sec=a.sec-b.sec;
- return c;
- }
- friend ostream &operator<<(ostream &o,const Clock &c)
- {
- o<<c.hour<<":"<<c.min<<":"<<c.sec<<endl;
- return o;
- }
- int getHour()
- {
- return hour;
- }
- int getMin()
- {
- return min;
- }
- int getSec()
- {
- return sec;
- }
- void setHours(int h)
- {
- this->hour=h;
- }
- void setMin(int m)
- {
- this->min=m;
- }
- void setSec(int s)
- {
- this->sec=s;
- }
- ~Clock(){}
- };
- void rectify(Clock &c)
- {
- if(c.getSec()>=60)
- {
- c.setSec(c.getSec()-60);
- c.setMin(c.getMin()+1);
- }
- else if(c.getMin()>=60)
- {
- c.setMin(c.getMin()-60);
- c.setHours(c.getHour()+1);
- }
- else if(c.getHour()>=12)
- {
- c.setHours(c.getHour()-12);
- }
- else if(c.getSec()<0)
- {
- c.setSec(c.getSec()+60);
- c.setMin(c.getMin()-1);
- }
- else if(c.getMin()<0)
- {
- c.setMin(c.getMin()+60);
- c.setHours(c.getHour()-1);
- }
- else if(c.getHour()<0)
- {
- c.setHours(c.getHour()+12);
- }
- }
- int main() {
- int hour,min,sec;
- cin>>hour>>min>>sec;
- Clock a(hour,min,sec);
- rectify(a);
- cin>>hour>>min>>sec;
- Clock b(hour,min,sec);
- rectify(b);
- a.info();
- cout<<a.miliseconds()<<endl;
- b.info();
- cout<<b.miliseconds()<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement