Advertisement
Jopa322

Untitled

Nov 2nd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. #include "stdafx.;h"
  2. #include "iostream"
  3. using namespace std;
  4. const int M = 5;
  5. class TMyClass
  6. {
  7. private:
  8. int a;
  9. unsigned int *b;
  10. float arr[M];
  11. char *mass;
  12. int n;
  13.  
  14. public:
  15. TMyClass(int nn = 5, char massmass = 'a', int aa = 2, unsigned int bb = 10, char arrarr = 'b');
  16. TMyClass(TMyClass &obj);
  17. ~TMyClass();
  18. void input();
  19. void output();
  20. double fff();
  21. friend void input_F(TMyClass&);
  22. };
  23. class TChild :public TMyClass
  24. {
  25. char* d;
  26. double f;
  27. int j;
  28. public:
  29. TChild(int nn = 5, char massmass = 'a', int aa = 2, unsigned int bb = 10, char arrarr = 'b', char dd = 's', double ff=50, int jj=60);
  30. ~TChild();
  31. void input();
  32. void output();
  33. };
  34.  
  35. TMyClass::TMyClass(int nn, char massmass, int aa, unsigned int bb, char arrarr)
  36. {
  37. n = nn;
  38. mass = new char[n];
  39. for (int i = 0; i < n; i++)
  40. mass[i] = massmass;
  41. a = aa;
  42.  
  43. b = new unsigned int;
  44. *b = bb;
  45.  
  46. for (int i = 0; i < M; i++)
  47. {
  48. arr[i] = arrarr;
  49. }
  50. }
  51. TMyClass::TMyClass(TMyClass &obj)
  52. {
  53. n = obj.n;
  54. mass = new char[n];
  55. for (int i = 0; i < n; i++)
  56. mass[i] = obj.mass[i];
  57. a = obj.a;
  58. b = new unsigned int;
  59. *b = *obj.b;
  60. for (int i = 0; i < M; i++)
  61. {
  62. arr[i] = obj.arr[i];
  63. }
  64. }
  65. TMyClass::~TMyClass()
  66. {
  67.  
  68. delete[]mass;
  69. delete b;
  70. }
  71. TChild::TChild(int nn, char massmass, int aa, unsigned int bb, char arrarr, char dd, double ff, int jj):TMyClass(dd,ff,jj)
  72. {
  73. d = new char;
  74. *d = dd;
  75. f = ff;
  76. j = jj;
  77. }
  78. TChild::~TChild()
  79. {
  80. delete d;
  81. }
  82.  
  83. void TMyClass::input()
  84. {
  85. cout << "Введите переменную типа int" << endl;
  86. cin >> a;
  87. cout << "Введите статический массив" << endl;
  88. for (int i = 0; i < M; i++)
  89. {
  90. cout << "arr[" << i + 1 << "]=";
  91. cin >> arr[i];
  92. }
  93. cout << "Введите количество элементов дин.массива" << endl;
  94. cout << "n=";
  95. cin >> n;
  96. delete[]mass;
  97. mass = new char[n];
  98. cout << "Введите эелементы массива" << endl;
  99. for (int i = 0; i < n; i++)
  100. {
  101. cin >> mass[i];
  102. }
  103. cout << endl;
  104. cout << "Введите указатель *b" << endl;
  105. cin >> *b;
  106. }
  107.  
  108. void input_F(TMyClass&obj)
  109. {
  110. cout << "Введите переменную типа int" << endl;
  111. cin >> obj.a;
  112. cout << "Введите статический массив" << endl;
  113. for (int i = 0; i < M; i++)
  114. {
  115. cin >> obj.arr[i];
  116. }
  117. cout << "Введите количество элементов дин.массива" << endl;
  118. cout << "n=";
  119. cin >> obj.n;
  120. delete[]obj.mass;
  121. obj.mass = new char[obj.n];
  122. cout << "Введите эелементы массива" << endl;
  123. for (int i = 0; i <obj.n; i++)
  124. {
  125. cout << "mass[" << i + 1 << "]=";
  126. cin >> obj.mass[i];
  127. }
  128. cout << endl;
  129.  
  130. cout << "Введите указатель *b" << endl;
  131.  
  132. cin >> *obj.b;
  133. }
  134.  
  135. double TMyClass::fff()
  136. {
  137. double srA;
  138. int k = 0;
  139. int sum = 0;
  140. for (int i = 0; i < n; i++)
  141. {
  142. if (mass[i] <= 70)
  143. {
  144. k++;
  145. sum += mass[i];
  146. cout << "SUM=" << sum << endl;
  147. }
  148. }
  149. if (k>0)cout << "Ср.а не превышиющих 70:«" << sum / k << endl;
  150. else cout << "Числе не превышиющих 70 нет" << endl;
  151.  
  152. return 0;
  153. }
  154.  
  155. void TMyClass::output()
  156. {
  157. cout << endl;
  158. cout << "Вывод значений:" << endl;
  159. cout << "Переменная типа int:" << endl;
  160. cout << a << endl;
  161. cout << "Указатель *b:" << endl;
  162. cout << *b << endl;
  163. cout << "Статический массив:" << endl;
  164. for (int i = 0; i < M; i++)
  165. {
  166. cout << arr[i] << " ";
  167. }
  168. cout << endl;
  169. cout << "Дин.массив mass[" << n << "]" << endl;
  170. for (int i = 0; i < n; i++)
  171. {
  172. cout << mass[i] << " ";
  173. }
  174. cout << endl;
  175. }
  176. int main()
  177. {
  178. setlocale(LC_ALL, "RUS");
  179. TMyClass a;
  180. cout << " a - оригинальный " << endl;
  181. a.input();
  182. a.output();
  183. TMyClass b(a);
  184. TMyClass *c;
  185. c = new TMyClass;
  186.  
  187. cout << "b(a) - копия а" << endl;
  188. b.output();
  189. cout << " c " << endl;
  190. c->output();
  191.  
  192.  
  193. system("pause");
  194. return 0;
  195.  
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement