Advertisement
kolioi

53. Time Calculation C++

Jan 5th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Time
  6. {
  7. public:
  8.     Time(int h, int m, int s) :
  9.         hours(h), minutes(m), seconds(s)
  10.     {}
  11.  
  12.     int to_hours() const
  13.     {
  14.         return hours + minutes / 60 + seconds / 3600;
  15.     }
  16.  
  17.     int to_minutes() const
  18.     {
  19.         return hours * 60 + minutes + seconds / 60;
  20.     }
  21.  
  22.     int to_seconds() const
  23.     {
  24.         return hours * 3600 + minutes * 60 + seconds;
  25.     }
  26.  
  27. private:
  28.     int hours, minutes, seconds;
  29. };
  30.  
  31. int main()
  32. {
  33.     int hours, minutes, seconds;
  34.     cin >> hours >> minutes >> seconds;
  35.  
  36.     Time t(hours, minutes, seconds);
  37.  
  38.     cout << t.to_hours() << endl << t.to_minutes() << endl << t.to_seconds() << endl;
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement