#include<iostream>
#include<time.h>
#include<iomanip>
#include<stdlib.h>
using namespace std;
int** Create(int row, int col)
{
    int** arr;
    arr = new int * [row];
    for (int i = 0; i < row; i++)
    {
        arr[i] = new int[col];
    }
    return arr;
}
void Fill(int** arr, int height, int width)
{
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            arr[i][j] = rand() % 100;
        }
    }
}
void Show(int** arr, int height, int width)
{
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            cout << setw(3) << arr[i][j] << " ";
        }
        cout << "\n";
    }
    cout << "\n";
}
void Del(int** arr, int row)
{
    for (int i = 0; i < row; i++)
    {
        delete[]arr[i];
    }
    delete[]arr;
}
int** Add_Col(int** arr, int height, int& width, int pos)
{
    pos = 0;
    int** arr_1;
    arr_1 = Create(height, width + 1);
    for (int i = 0; i < height; i++)
    { 
        for (int j = 0; j < width; j++)
        {
            if (j < pos)
                arr_1[i][j] = arr[i][j];
            else if (j > pos)
                arr_1[i][j + 1] = arr[i][j];
            else
                arr_1[i][j] = rand() % 100;
        }
    }
    width++;
    Del(arr, height);
    arr = arr_1;
    return arr;
}
int** Add_Row(int** arr, int& height, int width, int pos)
{
    int** arr_2;
    arr_2 = Create(height + 1, width);
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            if (i < pos)
                
                arr_2[i][j] = arr[i][j];
            
            else if (i == pos)
            
                arr_2[i][j] = rand() % 100;
            
            else
                arr_2[i + 1][j] = arr[i][j];
        }
    }
    height++;
    Del(arr, height - 1);
    arr = arr_2;
    return arr;
}
void Delete_Col(int** arr, int height, int width, int pos)
{
    for (int i = 0; i < height; i++)
    {
        for (int j = pos; j < width; j++)
        {
            arr[i][j] = arr[i][j + 1];
        }
    }
}
void Delete_Row(int** arr, int height, int width, int pos)
{
   
    for (int i = 0; i < height; i++)
    {
        
            
            for (int j = 0; j < width; j++)
            {
                if (i == pos)
                arr[i][j] = arr[i+1][j];
            }
        
    }
}
int main()
{
    srand(time(NULL));
    int width, height;
    int choice;
    int pos;
    cout << "Enter width\n"; cin >> width;
    cout << "Enter hight\n"; cin >> height;
    int** arr;
    arr = Create(height, width);
    Fill(arr, height, width);
    Show(arr, height, width);
    cout << "Enter you choice\n1 - Add column\n2 - Add row\n3 - Delete column\n4 - Delete row\n";
    cin >> choice;
    switch (choice)
    {
    case 1:
        cout << "Enter number of column you want add" << endl;
        cin >> pos;
        if (pos >= width)
            cout << "Wrong choice!\n";
        else 
        {
            Add_Col(arr, height, width, pos);
            Show(arr, height, width);
        }
        break;
    case 2:
        cout << "Enter number of row you want add" << endl;
        cin >> pos;
        if (pos >= height)
            cout << "Wrong choice!\n";
        else 
        {
            Add_Row(arr, height, width, pos);
            Show(arr, height, width);
        }
        break;
    case 3:
        cout << "Enter number of column you want delete" << endl;
        cin >> pos;
        if (pos >= width)
            cout << "Wrong choice!\n";
        else 
        {
            Delete_Col(arr, height, width, pos);
            width--;
            Show(arr, height, width);
        }
        break;
    case 4:
        cout << "Enter number of row you want delete" << endl;
        cin >> pos;
        if (pos >= height)
            cout << "Wrong choice!\n";
        else 
        {
            Delete_Row(arr, height, width, pos);
            height--;
            Show(arr, height, width);
        }
        break;
    default:
        cout << "Wrong choice\n";
        break;
    }
    Del(arr, height);
}