Question: c++ question MyClass has an internal 2-D array of dynamically allocated doubles, pointed to by the member named data : class MyClass { private: double

c++ question

MyClass has an internal 2-D array of dynamically allocated doubles, pointed to by the member named data:

class MyClass { private: double **data; int width, height; // other stuff } 

Assume width and height are set by constructors and mutators, and the class deals with them and all other data management correctly. Here is the method we are interested in analyzing:

void MyClass::allocateDynArray(int newHeight, int newWidth) { int row; if ( !valid( newHeight, newWidth ) ) return; height = newHeight; width = newWidth; // delete and NULLs the data deallocateDynArray(); data = new double*[height]; for ( row = 0; row < height; row++ ) data[row] = new double[width]; setArrayToAllZeros(); } 

Check the true statements (there will be one and possible more):

A. A destructor is essential for this class.
B. The invocation of deallocateDynArray() needs to be repositioned to a different place in the code in order to avoid a potential crash or memory leak.
C. It's fine as is.
D. We have to set data = NULL before we do our error return near the top
E. setArrayToAllZeros() needs parameters to know what bounds to use for its (likely) internal loops.

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!