Advertisement
Khristina

Задача №7 Илия

May 22nd, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdafx.h>
  3. #include <conio.h>
  4. #include <string>
  5. #include <cstring>
  6. #include <math.h>
  7. #include <cstdlib>
  8. #include <fstream>
  9. #include <ctime>
  10. #include <iostream>
  11. #include <conio.h>
  12. #include <string>
  13. #include <cstring>
  14. #include <math.h>
  15. #include <cstdlib>
  16. #include <fstream>
  17. #include <windows.h>
  18. using namespace std;
  19.  
  20. template <typename T>
  21. class MyTime
  22. {
  23. protected:
  24.     T x;
  25.     T y;
  26. public:
  27.     MyTime(T a, T b)
  28.     {
  29.         set_x(a);
  30.         set_y(b);
  31.     }
  32.     MyTime(T a)
  33.     {
  34.         y = 0;
  35.         set_x(a);
  36.     }
  37.     MyTime()
  38.     {
  39.         x = 1;
  40.         y = 0;
  41.     }
  42.  
  43.     void virtual set_x(T a)
  44.     {
  45.         x = a;
  46.     }
  47.     void virtual set_y(T b)
  48.     {
  49.         y = b;
  50.     }
  51.     void virtual show()
  52.     {
  53.         cout << "hour=" << x << " minute=" << y << endl;
  54.     }
  55.  
  56.  
  57.  
  58.     MyTime operator*(int a)
  59.     {
  60.         return MyTime(x*a, y*a);
  61.     }
  62.  
  63.     virtual MyTime& operator+=(const MyTime &T2)
  64.     {
  65.         x += T2.x;
  66.         y += T2.y;
  67.         return *this;
  68.     }
  69.  
  70.     MyTime& operator++()
  71.     {
  72.         ++x;
  73.         ++y;
  74.         return *this;
  75.     }
  76.  
  77.     MyTime& operator++(int)
  78.     {
  79.         x++;
  80.         y++;
  81.         return *this;
  82.     }
  83.  
  84.     friend void operator<<(ostream & os, const MyTime<T> &MT)
  85.     {
  86.         os << "hour=" << MT.x << " minute=" << MT.y << endl;
  87.     }
  88.  
  89.     ~MyTime()
  90.     {
  91.         cout << "Object was exterminated" << endl;
  92.     }
  93. };
  94.  
  95.  
  96. int main()
  97. {
  98.     double a, b;
  99.     string str_;
  100.  
  101.     cout << "Enter hour: " << endl;
  102.     cin >> a;
  103.     cout << "Enter minute: " << endl;
  104.     cin >> b;
  105.     cout << "Enter name: " << endl;
  106.     cin >> str_;
  107.     MyTime<int> T1(a, b);
  108.     MyTime<int> T2(a);
  109.     MyTime<int> T3;
  110.     cout << "Time T1: " << endl;
  111.     cout << T1;
  112.     cout << "Time T2: " << endl;
  113.     cout << T2;
  114.     cout << "Time T3: " << endl;
  115.     cout << T3;
  116.  
  117.     cout << "Time 2*T1: " << endl;
  118.     cout << T1 * 2;
  119.     cout << "Time T1+T2: " << endl;
  120.     T1 += T2;
  121.     cout << T1;
  122.  
  123.     cout << "Time T1 (prefics increment): " << endl;
  124.     ++T1;
  125.     cout << T1;
  126.     cout << "Time T1 (postfics increment): " << endl;
  127.     T1++;
  128.     cout << T1;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement