Vla_DOS

Untitled

May 21st, 2022
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.42 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. #include<ctime>
  4. #include<Windows.h>
  5. #include<iomanip>
  6. using namespace std;
  7.  
  8. #include<iostream>
  9. #include<time.h>
  10. #include<iomanip>
  11. #include<stdlib.h>
  12. using namespace std;
  13.  
  14. int** Create(int row, int col)
  15. {
  16.     int** arr;
  17.     arr = new int* [row];
  18.     for (int i = 0; i < row; i++)
  19.     {
  20.         arr[i] = new int[col];
  21.     }
  22.     return arr;
  23. }
  24.  
  25. void Fill(int** arr, int height, int width)
  26. {
  27.     for (int i = 0; i < height; i++)
  28.     {
  29.         for (int j = 0; j < width; j++)
  30.         {
  31.             arr[i][j] = rand() % 100;
  32.         }
  33.     }
  34. }
  35.  
  36. void Show(int** arr, int height, int width)
  37. {
  38.     for (int i = 0; i < height; i++)
  39.     {
  40.         for (int j = 0; j < width; j++)
  41.         {
  42.             cout << setw(3) << arr[i][j] << " ";
  43.         }
  44.         cout << "\n";
  45.     }
  46.     cout << "\n";
  47. }
  48.  
  49. void Del(int** arr, int row)
  50. {
  51.     for (int i = 0; i < row; i++)
  52.     {
  53.         delete[]arr[i];
  54.     }
  55.     delete[]arr;
  56. }
  57. int** Add_Col(int** arr, int height, int& width)
  58. {
  59.     int** arr_1;
  60.     int pos;
  61.     cout << "Enter number of column you want add" << endl;
  62.     cin >> pos;
  63.     if (pos > width)
  64.     {
  65.         cout << "Wrong choce!\n";
  66.         return 0;
  67.     }
  68.     else
  69.     {
  70.         arr_1 = Create(height, width + 1);
  71.         for (int i = 0; i < height; i++)
  72.         {
  73.             for (int j = 0; j < pos; j++)
  74.             {
  75.                 arr_1[i][j] = arr[i][j];
  76.             }
  77.         }
  78.         for (int i = 0; i < height; i++)
  79.         {
  80.             for (int j = 0; j < width - pos; j++)
  81.             {
  82.                 arr_1[i][j + pos + 1] = arr[i][j + pos];
  83.             }
  84.  
  85.         }
  86.         width++;
  87.         for (int i = 0; i < height; i++)
  88.         {
  89.             for (int j = pos; j < pos + 1; j++)
  90.             {
  91.                 arr_1[i][j] = rand() % 100;
  92.             }
  93.  
  94.         }
  95.         Del(arr, height);
  96.         arr = arr_1;
  97.         return arr;
  98.     }
  99. }
  100.  
  101. int** Add_Row(int** arr, int& height, int width)
  102. {
  103.     int** arr_2;
  104.     int pos;
  105.     cout << "Enter number of row you want add" << endl;
  106.     cin >> pos;
  107.     if (pos > height)
  108.     {
  109.         cout << "Wrong choice!\n";
  110.         return 0;
  111.     }
  112.     else
  113.     {
  114.         arr_2 = Create(height + 1, width);
  115.         for (int i = 0; i < pos; i++)
  116.         {
  117.             for (int j = 0; j < width; j++)
  118.             {
  119.                 arr_2[i][j] = arr[i][j];
  120.             }
  121.         }
  122.         for (int i = 0; i < height - pos; i++)
  123.         {
  124.             for (int j = 0; j < width; j++)
  125.             {
  126.                 arr_2[i + pos + 1][j] = arr[i + pos][j];
  127.             }
  128.         }
  129.         height++;
  130.         for (int i = pos; i < pos + 1; i++)
  131.         {
  132.             for (int j = 0; j < width; j++)
  133.             {
  134.                 arr_2[i][j] = rand() % 100;
  135.             }
  136.         }
  137.         Del(arr, height - 1);
  138.         arr = arr_2;
  139.         return arr;
  140.  
  141.         return arr;
  142.     }
  143. }
  144.  
  145. int** Delete_Col(int** arr, int height, int& width)
  146. {
  147.     int pos;
  148.     int** arr_3;
  149.     cout << "Enter number of column you want delete\n";
  150.     cin >> pos;
  151.     if (pos >= width)
  152.     {
  153.         cout << "Wrong choice!\n";
  154.         return 0;
  155.     }
  156.     else
  157.     {
  158.         arr_3 = Create(height, width);
  159.         for (int i = 0; i < height; i++)
  160.         {
  161.             for (int j = 0; j < pos; j++)
  162.             {
  163.                 arr_3[i][j] = arr[i][j];
  164.             }
  165.         }
  166.         for (int i = 0; i < height; i++)
  167.         {
  168.             for (int j = pos; j < width - 1; j++)
  169.             {
  170.                 arr_3[i][j] = arr[i][j + 1];
  171.             }
  172.         }
  173.         width--;
  174.         Del(arr, height);
  175.         arr = arr_3;
  176.         return arr;
  177.     }
  178. }
  179.  
  180. int** Delete_Row(int** arr, int& height, int width)
  181. {
  182.     int pos;
  183.     int** arr_4;
  184.     cout << "Enter number of row you want delete" << endl;
  185.     cin >> pos;
  186.     if (pos >= height)
  187.     {
  188.         cout << "Wrong choice!\n";
  189.         return 0;
  190.     }
  191.     else
  192.     {
  193.         arr_4 = Create(height - 1, width);
  194.         for (int i = 0; i < pos; i++)
  195.         {
  196.             for (int j = 0; j < width; j++)
  197.             {
  198.                 arr_4[i][j] = arr[i][j];
  199.             }
  200.  
  201.         }
  202.         for (int i = pos; i < height - 1; i++)
  203.         {
  204.             for (int j = 0; j < width; j++)
  205.             {
  206.                 arr_4[i][j] = arr[i + 1][j];
  207.             }
  208.         }
  209.         height--;
  210.         Del(arr, height);
  211.         arr = arr_4;
  212.         return arr;
  213.     }
  214. }
  215.  
  216.  
  217. int main()
  218. {
  219.     srand(time(NULL));
  220.     int width, height;
  221.     int choice;
  222.     int pos;
  223.     cout << "Enter width\n"; cin >> width;
  224.     cout << "Enter hight\n"; cin >> height;
  225.     int** arr;
  226.     arr = Create(height, width);
  227.     Fill(arr, height, width);
  228.     Show(arr, height, width);
  229.     cout << "Enter you choice\n1 - Add column\n2 - Add row\n3 - Delete column\n4 - Delete row\n";
  230.     cin >> choice;
  231.     switch (choice)
  232.     {
  233.     case 1:
  234.         arr = Add_Col(arr, height, width);
  235.         Show(arr, height, width);
  236.         break;
  237.     case 2:
  238.  
  239.         arr = Add_Row(arr, height, width);
  240.         Show(arr, height, width);
  241.         break;
  242.     case 3:
  243.  
  244.         arr = Delete_Col(arr, height, width);
  245.         Show(arr, height, width);
  246.         break;
  247.  
  248.     case 4:
  249.  
  250.         arr = Delete_Row(arr, height, width);
  251.         Show(arr, height, width);
  252.         break;
  253.  
  254.     default:
  255.         cout << "Wrong choice\n";
  256.         break;
  257.     }
  258.     Del(arr, height);
  259.  
  260. }
Advertisement
Add Comment
Please, Sign In to add comment