Question: Dynamic Array C++ practice: Creates a one-dimensional dynamic array to emulate a two-dimensional array and returns a pointer to the one-dimensional dynamic array. Please use
Dynamic Array C++ practice:
Creates a one-dimensional dynamic array to emulate a two-dimensional array and returns a pointer to the one-dimensional dynamic array. Please use the following functions:
- void set(int *arr, int rows, int columns, int desired_row, int desired_column, int val)
- void get(int *arr, int rows, int columns, int desired_row, int desired_column)
Input description:
First, input the number of rows (first) and columns (last) of the array to be created. Then input the row (first) and column (last) of the array to set the values, and then input the value. Finally, input the row (first) and column (last) of the array to get the values. This is a loop, and the program will not end until specific conditions (such as the output description below), otherwise it will repeat, and a new array will be re-created each time.
Output description:
Please follow the example expressions exactly. If the rows and columns of input exceed the size of the originally created array, or are unreasonable (negative numbers), "Desired indices are invalid" will be output and the program will end. If you enter an array within a reasonable range, the corresponding value will be output.
Here's the example of the input and output: (in the console screen)
Enter rows and column of 2D array:
2
3
Memory allocation is created for array
Enter desired rows and column of array to set the values:
1
2
Enter the value to set in the array:
10
Enter the desired rows and columns of array to get the values:
1
2
The value from the desired index is: 10
Enter rows and column of 2D array:
5
5
Memory allocation is created for array
Enter desired rows and column of array to set the values:
3
2
Enter the value to set in the array:
15
Enter the desired rows and columns of array to get the values:
1
2
The value from the desired index is: 12293
Enter rows and columns of 2D array:
4
5
Memory allocation is created for array
Enter the desired rows and columns of array to set the values:
1
6
Desired indices are invalid
-------------------------------------
Process exited after 37.08 seconds with return value 0
(end of input and output example in the console screen).
Reminder: code in C++
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
