Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- #include<ctime>
- #include<Windows.h>
- #include<iomanip>
- using namespace std;
- #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** arr_1;
- int pos;
- cout << "Enter number of column you want add" << endl;
- cin >> pos;
- if (pos > width)
- {
- cout << "Wrong choce!\n";
- return 0;
- }
- else
- {
- arr_1 = Create(height, width + 1);
- for (int i = 0; i < height; i++)
- {
- for (int j = 0; j < pos; j++)
- {
- arr_1[i][j] = arr[i][j];
- }
- }
- for (int i = 0; i < height; i++)
- {
- for (int j = 0; j < width - pos; j++)
- {
- arr_1[i][j + pos + 1] = arr[i][j + pos];
- }
- }
- width++;
- for (int i = 0; i < height; i++)
- {
- for (int j = pos; j < pos + 1; j++)
- {
- arr_1[i][j] = rand() % 100;
- }
- }
- Del(arr, height);
- arr = arr_1;
- return arr;
- }
- }
- int** Add_Row(int** arr, int& height, int width)
- {
- int** arr_2;
- int pos;
- cout << "Enter number of row you want add" << endl;
- cin >> pos;
- if (pos > height)
- {
- cout << "Wrong choice!\n";
- return 0;
- }
- else
- {
- arr_2 = Create(height + 1, width);
- for (int i = 0; i < pos; i++)
- {
- for (int j = 0; j < width; j++)
- {
- arr_2[i][j] = arr[i][j];
- }
- }
- for (int i = 0; i < height - pos; i++)
- {
- for (int j = 0; j < width; j++)
- {
- arr_2[i + pos + 1][j] = arr[i + pos][j];
- }
- }
- height++;
- for (int i = pos; i < pos + 1; i++)
- {
- for (int j = 0; j < width; j++)
- {
- arr_2[i][j] = rand() % 100;
- }
- }
- Del(arr, height - 1);
- arr = arr_2;
- return arr;
- return arr;
- }
- }
- int** Delete_Col(int** arr, int height, int& width)
- {
- int pos;
- int** arr_3;
- cout << "Enter number of column you want delete\n";
- cin >> pos;
- if (pos >= width)
- {
- cout << "Wrong choice!\n";
- return 0;
- }
- else
- {
- arr_3 = Create(height, width);
- for (int i = 0; i < height; i++)
- {
- for (int j = 0; j < pos; j++)
- {
- arr_3[i][j] = arr[i][j];
- }
- }
- for (int i = 0; i < height; i++)
- {
- for (int j = pos; j < width - 1; j++)
- {
- arr_3[i][j] = arr[i][j + 1];
- }
- }
- width--;
- Del(arr, height);
- arr = arr_3;
- return arr;
- }
- }
- int** Delete_Row(int** arr, int& height, int width)
- {
- int pos;
- int** arr_4;
- cout << "Enter number of row you want delete" << endl;
- cin >> pos;
- if (pos >= height)
- {
- cout << "Wrong choice!\n";
- return 0;
- }
- else
- {
- arr_4 = Create(height - 1, width);
- for (int i = 0; i < pos; i++)
- {
- for (int j = 0; j < width; j++)
- {
- arr_4[i][j] = arr[i][j];
- }
- }
- for (int i = pos; i < height - 1; i++)
- {
- for (int j = 0; j < width; j++)
- {
- arr_4[i][j] = arr[i + 1][j];
- }
- }
- height--;
- Del(arr, height);
- arr = arr_4;
- return arr;
- }
- }
- 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:
- arr = Add_Col(arr, height, width);
- Show(arr, height, width);
- break;
- case 2:
- arr = Add_Row(arr, height, width);
- Show(arr, height, width);
- break;
- case 3:
- arr = Delete_Col(arr, height, width);
- Show(arr, height, width);
- break;
- case 4:
- arr = Delete_Row(arr, height, width);
- Show(arr, height, width);
- break;
- default:
- cout << "Wrong choice\n";
- break;
- }
- Del(arr, height);
- }
Advertisement
Add Comment
Please, Sign In to add comment