Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- #include <string>
- #include <cstring>
- #include <math.h>
- #include <cstdlib>
- #include <fstream>
- #include <windows.h>
- #include <ctime>
- #include <iostream>
- #include <conio.h>
- #include <string>
- #include <cstring>
- #include <math.h>
- #include <cstdlib>
- #include <fstream>
- #include <windows.h>
- using namespace std;
- class MyTime
- {
- protected:
- int x;
- int y;
- public:
- //void show();
- //void set (int, int);
- //MyTime (int, int);
- //MyTime (int);
- //MyTime();
- MyTime operator+ (const MyTime) const;
- friend MyTime operator*(const MyTime, const MyTime);
- friend ostream & operator<<(ostream & os, const MyTime & t);
- MyTime operator++()
- {int a, b;
- a=x+1;
- b=y+1;
- int c;
- if (b>59)
- {c=(b-(b%60))/60;
- a=a+c;
- }
- x=a;
- y=b;
- return MyTime (x, y);
- } ;
- ~MyTime ()
- {
- cout<<"Object was exterminated"<<endl;
- }
- friend MyTime summa (MyTime, MyTime);
- void virtual set(int a, int b)
- {
- x = a;
- y = b;
- };
- void virtual show()
- {
- cout << "hour=" << x << " minute=" << y << endl;
- };
- MyTime(int a, int b)
- {
- int c;
- if (b>59)
- {
- c = (b - (b % 60)) / 60;
- a = a + c;
- }
- x = a;
- y = b;
- cout << "Object was created" << endl;
- }
- MyTime(int a)
- {
- y = a;
- cout << "Object was created" << endl;
- };
- MyTime()
- {
- x = 11;
- y = 38;
- cout << "Object was created" << endl;
- };
- };
- MyTime MyTime::operator+(const MyTime t) const
- {
- return MyTime(x+t.x, y+t.y);
- }
- MyTime operator*(const MyTime t1, const MyTime t2)
- {
- return MyTime (t1.x*t2.x, t1.y*t2.y);
- }
- ostream & operator<<(ostream & os, const MyTime & t)
- {
- os<<"hour=" << t.x << " minute=" << t.y;
- return os;
- }
- class NMyTime: public MyTime
- {
- private:
- string str;
- public:
- NMyTime (int x, int y, string str_): str(str_), MyTime(x,y)
- {
- cout <<"Object was created"<<endl;
- }
- ~NMyTime ()
- {
- cout<<"Object was exterminated"<<endl;
- };
- void virtual show()
- {
- cout<<"hour="<<x<<" minute="<<y<<" name "<<str<<endl;
- };
- NMyTime& operator+(const NMyTime &NT)
- {
- x+=NT.x;
- y+=NT.y;
- str+=NT.str;
- int c;
- if (y>59)
- {c=(y-(y%60))/60;
- y=y%60;
- x=x+c;
- }
- return *this;
- }
- };
- int main ()
- {
- int a, b;
- int n, k, m;
- string str_;
- int q=5;
- MyTime *arr[5];
- for (int i=0; i<15; i++)
- {
- cout<<" 1 - create object \n 2 - show object \n 3 - exterminate object \n 4 - leave the cicle \n 5 - show all objects"<< endl;
- cin>>n;
- if (n==1)
- {
- cout<<" 1 - create object MyTime \n 2 - create object NMyTime "<<endl;
- cin>>k;
- if (k==1)
- {
- cout<<"enter the number of the element"<<endl;
- cin>>m;
- cout<<"hours= ";
- cin>>a;
- cout<<"minute= ";
- cin>>b;
- arr[m]=new MyTime (a,b);
- }
- else if (k==2)
- {
- cout<<"enter the number of the element"<<endl;
- cin>>m;
- cout<<"hours= ";
- cin>>a;
- cout<<"minute= ";
- cin>>b;
- cout<<"name ";
- cin>>str_;
- arr[m]=new NMyTime (a,b,str_);
- } }
- else if (n==2)
- {
- int l;
- cout<<"enter the number of the showing element"<<endl;
- cin>>l;
- cout<<"\n"<<"Time"<<endl;
- arr[l]->show();
- }
- else if (n==3)
- {
- int o;
- cout<<"enter the number of the exterminating element"<<endl;
- cin>>o;
- delete arr[o];
- for (int j=0; j=5; j++)
- {
- if ( j!=4)
- {
- arr[j]=arr[j+1];
- }
- else if (j==4)
- {arr[j]=arr[j];
- }
- }
- q--;
- }
- else if (n==4)
- {break;
- }
- else if (n==5)
- {
- for (int t=0; t<q; t++)
- {
- cout<<"---"<<endl;
- arr[t]->show();
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement