Advertisement
kqlul123

laba4

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