Zer-0-ne

class TIME_PRIYA

Oct 17th, 2017
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class TIME
  6. {
  7. int hours;
  8. int minutes;
  9. int seconds;
  10. public:
  11. TIME()
  12. {
  13. hours=0;
  14. minutes=0;
  15. seconds=0;
  16. }
  17. void get()
  18. {
  19. cin>> hours>> minutes>> seconds ;
  20. }
  21. void disp()
  22. {
  23. cout<< hours << ":" << minutes << ":"<< seconds ;
  24. }
  25. void sum(TIME t1,TIME t2)
  26. {
  27. seconds=t1.seconds+t2.seconds;
  28. minutes=seconds/60;
  29. seconds=seconds%60;
  30. minutes=minutes+t1.minutes+t2.minutes;
  31. hours=minutes/60;
  32. minutes=minutes%60;
  33. hours=hours+t1.hours+t2.hours;
  34. }
  35. };
  36.  
  37. int main()
  38. {
  39. TIME t1,t2,t3;
  40. cout<< "Initially when the objects are created, values stored in data members : " ;
  41. t1.disp(); // Or t2.disp(); Or t3.disp() ;
  42. cout<< "\nEnter the first time : " ;
  43. t1.get() ;
  44. cout<< "Enter the second time : " ;
  45. t2.get() ;
  46. cout<< "The resultant sum is : " ;
  47. t3.sum(t1,t2) ;
  48. t3.disp() ;
  49.  
  50. return 0;
  51. }
Add Comment
Please, Sign In to add comment