Question: 2. Two-dimensional dynamic arrays The concept of dynmamic array that you implemented in Problem 1 above can be extended to a multi-dimension arrayin this problem,

 2. Two-dimensional dynamic arrays The concept of dynmamic array that you

2. Two-dimensional dynamic arrays The concept of dynmamic array that you implemented in Problem 1 above can be extended to a multi-dimension arrayin this problem, you will implement a dynamic 2-D Just like a one dimensional array name is a pointer, a 2-D array name is aso a peinter, but it is a different type of pointer. To extract the values from latter, you have to deference twice-hence it can also be a called a double-referenced pointer. For example you declare an ordinary pointer as int *p A double-referenced pointer will be declared as int "P2D To dereference the (iun element of a one dirmensional array, you can use * (p+1), where is0,1,2 To dereference the 1) row and (+1) column of a 2-D aray, you can use "(P_2D[)+j).where ij41.2m Additionally, in order to create a dynamic 2-D array, you will need to manually create al of the arrays pointed to by the first array. For example, if nunRows was the number of rows in your 2-D array, you can create the first dimension by typing To create nunColumns number of columns in your 2-D aray, you would need to use a for loop lke this p 2D(i) . new int [nunCo12]; - Now you have a numRows xnunCols large 2-D array ready to fill with integers Whenever you want to delete the 2.D array, you will need to make sure you take care of all of the inner arrays, before removing the single outer array. For example, do remove P 2D we would type the following to remove all of the inner arrays for (int -O: cnumRows: ) delete t1 p 2DI4 Only then could we safely remove the array p 2D by typing delete t1 P 2D Using the example code presented in Problem 1, make the Sollowing modifications a. Prompt for and read the size of a 2-D array, read both number of rows and b. Create the array numlist dynamically (using the new operator) of the sire c. You will first need to allocate memory for the whole 2-D array using a double columns, for the two dimensions pecified by the user referenced pointer. Then, in a loop, allocate memory for each row, one row a d. Read in the values for the array using pointer notation. It is a two dimensional array, so you will need a nested loop. Also, remember you will need to dereference twice to assign values to the array elements e. Print out the values in the odd rows of the array using pointer notation. For example, print row 1, row 3, row 5 and so on and so forth. You can assume that row count starts from 0 f Finally, delete the entire dynamic array once you are done with it Complete the requested changes, and then save the file as Lab128.Cpp, making sure to compile and run the program to verify that it produces the correct results. Be sure to review the code to make sure you understand what it is doing. Note that you will submit this file to Blackboard

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!