Advertisement
Guest User

mat

a guest
Sep 16th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. class DynamicArray
  7. {
  8. int size;
  9. int* mas;
  10. public:
  11. DynamicArray()
  12. {
  13. size = 0;
  14. mas = nullptr;
  15. }
  16. DynamicArray(const DynamicArray& DynamicArray)
  17. {
  18. mas = new int[DynamicArray.size];
  19.  
  20. for (int i = 0; i < DynamicArray.size; i++)
  21. mas[i] = DynamicArray.mas[i];
  22.  
  23. size = DynamicArray.size;
  24. }
  25. ~DynamicArray()
  26. {
  27. size = 0;
  28. if (mas != nullptr)
  29. delete[] mas;
  30. }
  31. void display()
  32. {
  33. for (int i = 0; i < size; i++)
  34. cout << mas[i] << ' ';
  35. cout << endl;
  36. }
  37. void put(const int obi)
  38. {
  39. int sizesn = size + 1;
  40. int* massn = new int[sizesn];
  41.  
  42. for (int i = 0; i < size; i++)
  43. massn[i] = mas[i];
  44.  
  45. massn[size] = obi;
  46.  
  47. if (mas != nullptr)
  48. delete[] mas;
  49.  
  50. mas = massn;
  51. size = sizesn;
  52. }
  53. void retur(const int obj)
  54. {
  55. int sizesn = size - 1;
  56. int* massn = new int[sizesn];
  57.  
  58. for (int i = 0; i < obj; i++)
  59. massn[i] = mas[i];
  60.  
  61. for (int i = obj; i < sizesn; i++)
  62. massn[i] = mas[i + 1];
  63.  
  64. if (mas != nullptr)
  65. delete[] mas;
  66.  
  67. mas = massn;
  68. size = sizesn;
  69. }
  70. };
  71.  
  72. void main()
  73. {
  74. DynamicArray Func;
  75.  
  76. Func.put(222);
  77.  
  78. Func.display();
  79.  
  80. system("pause");
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement