Advertisement
endreweast

Practic 2.3

Dec 16th, 2015
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 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.         time operator-(time t)
  37.         {
  38.             time test(hours - t.getHours(), minutes - t.getMinutes(), seconds - t.getSeconds());
  39.             return test;
  40.         }
  41.         time operator*(time t)
  42.         {
  43.             time test1(hours * t.getHours(), minutes * t.getMinutes(), seconds * t.getSeconds());
  44.             return test1;
  45.         }
  46. };
  47.  
  48. int main()
  49. {
  50.         time a(5, 25, 34);
  51.         time b(3, 24, 10);
  52.         time result = a + b;
  53.         result.display();
  54.         time test = a - b;
  55.         test.display();
  56.         time test1= result * test;
  57.         test1.display();
  58.         system("pause");
  59.         return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement