fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class Time
  5. {
  6. int hour,minute,second;
  7. public:
  8. Time()
  9. {
  10. hour=0;
  11. minute=0;
  12. second=0;
  13. }
  14. Time(int a,int b,int c)
  15. {
  16. hour=a;
  17. minute=b;
  18. second=c;
  19. }
  20. void add(Time c1, Time c2)
  21. {
  22. second=c1.second+c2.second;
  23. minute=c1.minute+c2.minute+second/60;
  24. second%=60;
  25. hour=c1.hour+c2.hour+minute/60;
  26. minute%=60;
  27. }
  28. void display()
  29. {
  30. cout<<hour<<" hour "<<minute<<" minute "<<second<<" second";
  31. }
  32. };
  33.  
  34. int main()
  35. {
  36. int h,m,s;
  37. cout<<"\nEnter the 1st hour , min and sec : ";
  38. cin>>h>>m>>s;
  39. Time c1(h,m,s);
  40.  
  41. cout<<"\nEnter the 2nd hour , min , sec : ";
  42. cin>>h>>m>>s;
  43. Time c2(h,m,s);
  44.  
  45. Time c3;
  46. c3.add(c1,c2);
  47. cout<<"\nThe time is : ";
  48. c3.display();
  49.  
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
Enter the 1st hour , min and sec : 
Enter the 2nd hour , min , sec : 
The time is : -3761846 hour -4 minute 8 second