fork download
  1. #include<iostream>
  2. using namespace std;
  3. class Time
  4. {
  5. int h,m;
  6. public:
  7. Time()
  8. {
  9. h=0;
  10. m=0;
  11. }
  12. Time(int a,int b)
  13. {
  14. h=a;
  15. m=b;
  16. }
  17. Time operator +(Time x)
  18. {
  19. Time temp;
  20. temp.h=h+x.h;
  21. temp.m=m+x.m;
  22. if (temp.m>59)
  23. {
  24. temp.m-=60;
  25. temp.h++;
  26. }
  27. return temp;
  28. }
  29. void print()
  30. {
  31. cout<<h<<" hrs "<<m<<" mins\n";
  32. }
  33. };
  34.  
  35. int main()
  36. {
  37. Time a(1,10),b(2,50),c;
  38. c=a+b;
  39. cout<<"\nSum= ";
  40. c.print();
  41. return 0;
  42. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
Sum= 4 hrs 0mins