Advertisement
Khristina

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

May 22nd, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.31 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <string>
  5. #include <cstring>
  6. #include <math.h>
  7. #include <cstdlib>
  8. #include <fstream>
  9. #include <windows.h>
  10. #include <ctime>
  11. #include <iostream>
  12. #include <conio.h>
  13. #include <string>
  14. #include <cstring>
  15. #include <math.h>
  16. #include <cstdlib>
  17. #include <fstream>
  18. #include <windows.h>
  19. using namespace std;
  20.  
  21.  
  22.  
  23. class MyTime
  24. {
  25. protected:
  26. int x;
  27. int y;
  28. public:
  29. //void show();
  30. //void set (int, int);
  31. //MyTime (int, int);
  32. //MyTime (int);
  33. //MyTime();
  34. MyTime operator+ (const MyTime) const;
  35. friend MyTime operator*(const MyTime, const MyTime);
  36. friend ostream & operator<<(ostream & os, const MyTime & t);
  37. MyTime operator++()
  38. {int a, b;
  39. a=x+1;
  40. b=y+1;
  41. int c;
  42. if (b>59)
  43. {c=(b-(b%60))/60;
  44. a=a+c;
  45. }
  46. x=a;
  47. y=b;
  48. return MyTime (x, y);
  49. }   ;
  50. ~MyTime ()
  51. {
  52. cout<<"Object was exterminated"<<endl;
  53. }
  54.  
  55. friend MyTime summa (MyTime, MyTime);
  56.  
  57.  
  58.  
  59. void virtual set(int a, int b)
  60. {
  61.     x = a;
  62.     y = b;
  63. };
  64.  
  65. void virtual show()
  66. {
  67.     cout << "hour=" << x << " minute=" << y << endl;
  68.  
  69. };
  70.  
  71. MyTime(int a, int b)
  72. {
  73.     int c;
  74.     if (b>59)
  75.     {
  76.         c = (b - (b % 60)) / 60;
  77.         a = a + c;
  78.     }
  79.     x = a;
  80.     y = b;
  81.     cout << "Object was created" << endl;
  82. }
  83. MyTime(int a)
  84. {
  85.     y = a;
  86.     cout << "Object was created" << endl;
  87. };
  88.  
  89. MyTime()
  90. {
  91.     x = 11;
  92.     y = 38;
  93.     cout << "Object was created" << endl;
  94. };
  95.  
  96.  
  97. };
  98.  
  99.  
  100. MyTime MyTime::operator+(const MyTime t) const
  101. {
  102. return MyTime(x+t.x, y+t.y);
  103. }
  104.  
  105. MyTime operator*(const MyTime t1, const MyTime t2)
  106. {
  107. return MyTime (t1.x*t2.x, t1.y*t2.y);
  108.  
  109. }
  110.  
  111. ostream & operator<<(ostream & os, const MyTime & t)
  112. {
  113. os<<"hour=" << t.x << " minute=" << t.y;
  114. return os;
  115. }
  116.  
  117. class NMyTime: public MyTime
  118. {
  119. private:
  120. string str;
  121.  
  122. public:
  123.  
  124. NMyTime (int x, int y, string str_): str(str_), MyTime(x,y)
  125. {
  126. cout <<"Object was created"<<endl;
  127. }
  128.  
  129. ~NMyTime ()
  130. {
  131. cout<<"Object was exterminated"<<endl;
  132. };
  133. void virtual show()
  134. {
  135. cout<<"hour="<<x<<" minute="<<y<<" name "<<str<<endl;
  136. };
  137.  
  138. NMyTime& operator+(const NMyTime &NT)
  139. {
  140. x+=NT.x;
  141. y+=NT.y;
  142. str+=NT.str;
  143. int c;
  144. if (y>59)
  145. {c=(y-(y%60))/60;
  146. y=y%60;
  147. x=x+c;
  148. }
  149. return *this;
  150. }
  151.  
  152.  
  153. };
  154.  
  155. int main ()
  156. {
  157. int a, b;
  158. int n, k, m;
  159. string str_;
  160. int q=5;
  161. MyTime *arr[5];
  162.  
  163. for (int i=0; i<15; i++)
  164. {
  165. cout<<" 1 - create object \n 2 - show object \n 3 - exterminate object \n 4 - leave the cicle \n 5 - show all objects"<< endl;
  166. cin>>n;
  167. if (n==1)
  168. {
  169. cout<<" 1 - create object MyTime \n 2 - create object NMyTime "<<endl;
  170. cin>>k;
  171. if (k==1)
  172. {
  173. cout<<"enter the number of the element"<<endl;
  174. cin>>m;
  175. cout<<"hours= ";
  176. cin>>a;
  177. cout<<"minute= ";
  178. cin>>b;
  179. arr[m]=new MyTime (a,b);
  180.  
  181. }
  182. else if (k==2)
  183. {
  184. cout<<"enter the number of the element"<<endl;
  185. cin>>m;
  186. cout<<"hours= ";
  187. cin>>a;
  188. cout<<"minute= ";
  189. cin>>b;
  190. cout<<"name ";
  191. cin>>str_;
  192. arr[m]=new NMyTime (a,b,str_);
  193.  
  194. }       }
  195.  
  196. else if (n==2)
  197. {
  198. int l;
  199. cout<<"enter the number of the showing element"<<endl;
  200. cin>>l;
  201. cout<<"\n"<<"Time"<<endl;
  202. arr[l]->show();
  203. }
  204. else if (n==3)
  205. {
  206. int o;
  207. cout<<"enter the number of the exterminating element"<<endl;
  208. cin>>o;
  209. delete arr[o];
  210. for (int j=0; j=5; j++)
  211. {
  212. if ( j!=4)
  213. {
  214. arr[j]=arr[j+1];
  215.  
  216. }
  217. else if (j==4)
  218. {arr[j]=arr[j];
  219. }
  220.  
  221. }
  222. q--;
  223. }
  224. else if (n==4)
  225. {break;
  226. }
  227.  
  228. else if (n==5)
  229. {
  230. for (int t=0; t<q; t++)
  231. {
  232. cout<<"---"<<endl;
  233. arr[t]->show();
  234. }
  235. }
  236. }
  237.  
  238. return 0;
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement