Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdafx.h>
- #include <conio.h>
- #include <string>
- #include <cstring>
- #include <math.h>
- #include <cstdlib>
- #include <fstream>
- #include <ctime>
- #include <iostream>
- #include <conio.h>
- #include <string>
- #include <cstring>
- #include <math.h>
- #include <cstdlib>
- #include <fstream>
- #include <windows.h>
- using namespace std;
- template <typename T>
- class MyTime
- {
- protected:
- T x;
- T y;
- public:
- MyTime(T a, T b)
- {
- set_x(a);
- set_y(b);
- }
- MyTime(T a)
- {
- y = 0;
- set_x(a);
- }
- MyTime()
- {
- x = 1;
- y = 0;
- }
- void virtual set_x(T a)
- {
- x = a;
- }
- void virtual set_y(T b)
- {
- y = b;
- }
- void virtual show()
- {
- cout << "hour=" << x << " minute=" << y << endl;
- }
- MyTime operator*(int a)
- {
- return MyTime(x*a, y*a);
- }
- virtual MyTime& operator+=(const MyTime &T2)
- {
- x += T2.x;
- y += T2.y;
- return *this;
- }
- MyTime& operator++()
- {
- ++x;
- ++y;
- return *this;
- }
- MyTime& operator++(int)
- {
- x++;
- y++;
- return *this;
- }
- friend void operator<<(ostream & os, const MyTime<T> &MT)
- {
- os << "hour=" << MT.x << " minute=" << MT.y << endl;
- }
- ~MyTime()
- {
- cout << "Object was exterminated" << endl;
- }
- };
- int main()
- {
- double a, b;
- string str_;
- cout << "Enter hour: " << endl;
- cin >> a;
- cout << "Enter minute: " << endl;
- cin >> b;
- cout << "Enter name: " << endl;
- cin >> str_;
- MyTime<int> T1(a, b);
- MyTime<int> T2(a);
- MyTime<int> T3;
- cout << "Time T1: " << endl;
- cout << T1;
- cout << "Time T2: " << endl;
- cout << T2;
- cout << "Time T3: " << endl;
- cout << T3;
- cout << "Time 2*T1: " << endl;
- cout << T1 * 2;
- cout << "Time T1+T2: " << endl;
- T1 += T2;
- cout << T1;
- cout << "Time T1 (prefics increment): " << endl;
- ++T1;
- cout << T1;
- cout << "Time T1 (postfics increment): " << endl;
- T1++;
- cout << T1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement