Advertisement
endreweast

Practic 1.3

Dec 16th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class time
  6. {
  7. private:
  8.         int hours, minutes, seconds;
  9. public:
  10.         time()
  11.         {
  12.                 hours = minutes = seconds = 0;
  13.         }
  14.  
  15.         time(int h, int m, int s)
  16.         {
  17.                 hours = h;
  18.                 minutes = m;
  19.                 seconds = s;
  20.         }
  21.  
  22.         int getHours() { return hours; }
  23.         int getMinutes() { return minutes; }
  24.         int getSeconds() { return seconds; }
  25.  
  26.         void display()
  27.         {
  28.                  cout << "Time: " << hours << ":" << minutes << ":" << seconds << endl;
  29.         }
  30.  
  31.         time operator+(time t)
  32.         {
  33.                 time result(hours + t.getHours(), minutes + t.getMinutes(), seconds + t.getSeconds());
  34.                 return result;
  35.         }
  36. };
  37.  
  38. int main()
  39. {
  40.         time a(2, 12, 20);
  41.         time b(3, 24, 33);
  42.         time result = a + b;
  43.         result.display();
  44.         system("pause");
  45.         return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement