Advertisement
Jopa322

XDDDDDDDD 4 rofel

Nov 9th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "iostream"
  3. using namespace std;
  4. const int Count = 6;
  5. class TMyClass
  6. {
  7. private:
  8. int c;
  9. unsigned int *d;
  10. float arr[Count];
  11. char *mass;
  12. int q;
  13.  
  14. public:
  15. TMyClass(int cc = 3, float arrarr = 3.1, char massmass = 'w', int qq = 5, unsigned int dd = 10);
  16. TMyClass(TMyClass &obj);
  17. ~TMyClass();
  18. void input();
  19. void output();
  20. long int fff(int x);
  21. friend void input_F(TMyClass&);
  22. };
  23.  
  24.  
  25. TMyClass::TMyClass(int cc, float arrarr, char massmass, int qq, unsigned int dd)
  26. {
  27.  
  28. q = qq;
  29. mass = new char[q];
  30. for (int i = 0; i < q; i++)
  31. mass[i] = massmass;
  32. c = cc;
  33. d = new unsigned int;
  34. *d = dd;
  35. for (int i = 0; i < Count; i++)
  36. {
  37. arr[i] = arrarr;
  38. }
  39.  
  40. }
  41. TMyClass::TMyClass(TMyClass &obj)
  42. {
  43.  
  44. q = obj.q;
  45. mass = new char[q];
  46. for (int i = 0; i < q; i++)
  47. mass[i] = obj.mass[i];
  48. c = obj.c;
  49. d = new unsigned int;
  50. *d = *obj.d;
  51. for (int i = 0; i < Count; i++)
  52. {
  53. arr[i] = obj.arr[i];
  54. }
  55.  
  56. }
  57. TMyClass::~TMyClass()
  58. {
  59.  
  60. delete[]mass;
  61. delete d;
  62. }
  63.  
  64. void TMyClass::input()
  65. {
  66. cout << "Введите переменную(int)" << endl;
  67. cin >> c;
  68. cout << "Введите статический массив(float)" << endl;
  69. for (int i = 0; i < Count; i++)
  70. {
  71. cout << "arr[" << i + 1 << "]=";
  72. cin >> arr[i];
  73. }
  74. cout << "Введите количество элементов дин.массива" << endl;
  75. cout << "q=";
  76. cin >> q;
  77. delete[]mass;
  78. mass = new char[q];
  79. cout << "Введите элементы динамического массива(char)" << endl;
  80. for (int i = 0; i < q; i++)
  81. {
  82. cout << "mass[" << i + 1 << "]=";
  83. cin >> mass[i];
  84. }
  85. cout << endl;
  86. cout << "Введите указатель *b(unsigned int)" << endl;
  87. cin >> *d;
  88. }
  89.  
  90. void input_F(TMyClass&obj)
  91. {
  92. cout << "Введите переменную(int)" << endl;
  93. cin >> obj.c;
  94. cout << "Введите статический массив(float)" << endl;
  95. for (int i = 0; i < Count; i++)
  96. {
  97. cout << "arr[" << i + 1 << "]=";
  98. cin >> obj.arr[i];
  99. }
  100. cout << "Введите количество элементов дин.массива" << endl;
  101. cout << "q=";
  102. cin >> obj.q;
  103. delete[]obj.mass;
  104. obj.mass = new char[obj.q];
  105. cout << "Введите элементы динамического массива(char)" << endl;
  106. for (int i = 0; i < obj.q; i++)
  107. {
  108. cout << "mass[" << i + 1 << "]=";
  109. cin >> obj.mass[i];
  110. }
  111. cout << endl;
  112. cout << "Введите указатель *b(unsigned int)" << endl;
  113. cin >> *obj.d;
  114. }
  115.  
  116. long int TMyClass::fff(int x) //умножение элементов стат. массива на переданное число x
  117. {
  118. for (int i = 0; i < Count; i++)
  119. {
  120. arr[i] *= x;
  121. }
  122. for (int i = 0; i < Count; i++)
  123. {
  124. cout << arr[i] << " ";
  125. }
  126. cout << endl;
  127. return 0;
  128. }
  129.  
  130. void TMyClass::output()
  131. {
  132. cout << endl;
  133. cout << "Вывод значений:" << endl;
  134. cout << "Переменная типа int:" << endl;
  135. cout << c << endl;
  136. cout << "Указатель *b:" << endl;
  137. cout << *d << endl;
  138. cout << "Статический массив[" << Count << "]" << endl;
  139. for (int i = 0; i < Count; i++)
  140. {
  141. cout << arr[i] << " ";
  142. }
  143. cout << endl;
  144. cout << "Дин.массив mass[" << q << "]" << endl;
  145. for (int i = 0; i < q; i++)
  146. {
  147. cout << mass[i] << " ";
  148.  
  149. }
  150. cout << endl;
  151. }
  152.  
  153. class TChild :public TMyClass
  154. {
  155. public:
  156. int y;
  157. char *t;
  158. double m;
  159. TChild(int cc = 3, float arrarr = 3.1, char massmass = 'w', int qq = 5, unsigned int dd = 10, int yy = 4, char tt = 's', double mm = 100.23);
  160. TChild(TMyClass &obj, TChild &object);
  161. void output();
  162. };
  163.  
  164. TChild::TChild(int cc, float arrarr, char massmass, int qq, unsigned int dd, int yy, char tt, double mm) :TMyClass(cc, arrarr, massmass, qq, dd)
  165. {
  166. y = yy;
  167. m = mm;
  168. t = new char;
  169. *t = tt;
  170. }
  171.  
  172. TChild::TChild(TMyClass &obj, TChild &object) :TMyClass(obj)
  173. {
  174. y = object.y;
  175. t = new char;
  176. *t = *object.t;
  177. m = object.m;
  178. }
  179.  
  180. void TChild::output()
  181. {
  182. TMyClass::output();
  183. cout << "Переменная y типа int:" << endl;
  184. cout << y << endl;
  185. cout << "Указатель t типа char:" << endl;
  186. cout << *t << endl;
  187. cout << "Переменная m типа double:" << endl;
  188. cout << m << endl;
  189. }
  190.  
  191.  
  192. int main()
  193. {
  194. setlocale(LC_ALL, "Russian");
  195.  
  196. cout << "Объекты TMyClass" << endl;
  197.  
  198. TMyClass a(3, 2.1, 'g', 4, 13);
  199. cout << "Объект a - оригинал" << endl;
  200. a.output();
  201. TMyClass b(a);
  202. TMyClass *c;
  203. c = new TMyClass;
  204.  
  205. cout << "Объект b(a) - копия объекта a" << endl;
  206. b.output();
  207. cout << "Объект c" << endl;
  208. c->output();
  209.  
  210.  
  211. cout << endl;
  212. cout << "Объекты TChild" << endl;
  213. TChild d(3, 2.1, 'g', 4, 13, 15, 'j', 50.21);
  214. cout << "Объект d - оригинал:" << endl;
  215. cout << "Cобственный метод вывода:" << endl;
  216. d.output();
  217. cout << "Унаследованный метод вывода:" << endl;
  218. d.TMyClass::output();
  219. TChild f(d);
  220. cout << "Объект f(d) - копия объекта d:" << endl;
  221. cout << "Cобственный метод вывода:" << endl;
  222. f.output();
  223. cout << "Унаследованный метод вывода:" << endl;
  224. f.TMyClass::output();
  225. TChild *g;
  226. g = new TChild;
  227. cout << "Объект c:" << endl;
  228. cout << "Cобственный метод вывода:" << endl;
  229. g->output();
  230. cout << "Унаследованный метод вывода:" << endl;
  231. g->TMyClass::output();
  232. delete g;
  233.  
  234. cout << "Проверка наследования" << endl;
  235. TChild h;
  236. input_F(h);
  237. h.output();
  238.  
  239. system("pause");
  240. return 0;
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement