Advertisement
kqlul123

Untitled

Oct 29th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. // ConsoleApplication14.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4.  
  5. #include "stdafx.h"
  6. #include "iostream"
  7. using namespace std;
  8. const int Count = 6;
  9. class TMyClass
  10. {
  11. private:
  12. char c;
  13. double *d;
  14. long int arr[Count];
  15. float *mass;
  16. int n;
  17.  
  18. public:
  19. TMyClass(int nn = 3, float massmass = 3.1, char cc = 'w', double dd = 2.4, long int ararar = 100);
  20. TMyClass(TMyClass &obj);
  21. ~TMyClass();
  22. void input();
  23. void output();
  24. long int fff(int x);
  25. friend void input_F(TMyClass&);
  26. };
  27.  
  28. TMyClass::TMyClass(int nn, float massmass, char cc, double dd, long int ararar)
  29. {
  30.  
  31. n = nn;
  32. mass = new float[n];
  33. for (int i = 0; i < n; 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. n = obj.n;
  48. mass = new float[n];
  49. for (int i = 0; i < n; 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 << "n=";
  79. cin >> n;
  80. delete[]mass;
  81. mass = new float[n];
  82. cout << "Введите элементы динамического массива(float)" << endl;
  83. for (int i = 0; i < n; 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 << "n=";
  105. cin >> obj.n;
  106. delete[]obj.mass;
  107. obj.mass = new float[obj.n];
  108. cout << "Введите элементы динамического массива(float)" << endl;
  109. for (int i = 0; i < obj.n; 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 << "Статический массив:" << endl;
  141. for (int i = 0; i < Count; i++)
  142. {
  143. cout << "arr[" << i + 1 << "]=" << arr[i] << endl;
  144. }
  145. cout << "Дин.массив mass[" << n << "]" << endl;
  146. for (int i = 0; i < n; i++)
  147. {
  148. cout << mass[i] << " ";
  149.  
  150. }
  151. cout << endl;
  152. }
  153. int main()
  154. {
  155. setlocale(LC_ALL, "Russian");
  156. TMyClass a;
  157. cout << "Объект a - оригинал" << endl;
  158. a.input();
  159. a.output();
  160. TMyClass b(a);
  161. TMyClass *px, *py;
  162. px = new TMyClass;
  163. py = new TMyClass;
  164.  
  165.  
  166. cout << "Объект b(a) - копия объекта a" << endl;
  167. b.output();
  168. cout << "Объект py - ввод с помощью конструктора по умолчанию" << endl;
  169. py->output();
  170. cout << "Объект px - ввод через внешнюю функцию ввода" << endl;
  171. input_F(*px);
  172. px->output();
  173.  
  174. int x;
  175. cout << "Введите параметр x=";
  176. cin >> x;
  177. cout << "Метод fff для a" << endl;
  178. a.fff(x);
  179. cout << "Метод fff для b(a)" << endl;
  180. b.fff(x);
  181. cout << "Метод fff для px" << endl;
  182. px->fff(x);
  183. cout << "Метод fff для py" << endl;
  184. py->fff(x);
  185.  
  186. system("pause");
  187. return 0;
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement