(a) In this task we consider ptr as a 2D matrix. Whereas, number of rows would be fixed but make number of columns variables. To do this, instead of using arrays of fixed column size allocated on stack, you will make each element of array to have nColumns (passed as argument to the function) elements and store them on heap using new operator. Next, initialize the values of these arrays randomly using for loop and ptr. Finally display the sum of each individual array. You are not allowed to access the array using original variable name. (b) In the previous task we make number of columns of a 2D matrix variables. Here we will make number of rows variables as well. Thus we will have a way of defining a generic 2D matrix according to user choice. Now your goal is to write a function that receives three arguments: (i) an alias to a 2D pointer; (ii)number of rows; and (iii) number of columns; Now your goal is to first allocate the memory for rows and then for columns dynamically using new operator. (c) In this function, your goal is to write code for deallocating a dynamically allocated 2D matrix. Your function will receive three arguments: (i) a 2D pointer; (ii) number of rows; and (iii) number of columns. Complete the code to properly deallocate.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question

(a) In this task we consider ptr as a 2D matrix. Whereas, number of rows would be fixed but make number of columns variables. To do this, instead of using arrays of fixed column size allocated on stack, you will make each element of array to have nColumns (passed as argument to the function) elements and store them on heap using new operator. Next, initialize the values of these arrays randomly using for loop and ptr. Finally display the sum of each individual array.
You are not allowed to access the array using original variable name.

(b) In the previous task we make number of columns of a 2D matrix variables. Here we will make number of rows variables as well. Thus we will have a way of defining a generic 2D matrix according to user choice. Now your goal is to write a function that receives three arguments: (i) an alias to a 2D pointer; (ii)number of rows; and (iii) number of columns; Now your goal is to first allocate the memory for rows and then for columns dynamically using new operator.

(c) In this function, your goal is to write code for deallocating a dynamically allocated 2D matrix. Your function will receive three arguments: (i) a 2D pointer; (ii) number of rows; and (iii) number of columns. Complete the code to properly deallocate.

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Randomized Select Algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning