Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ question MyClass has an internal 2-D array of dynamically allocated doubles,

ID: 3806956 • Letter: C

Question

c++ question

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

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:

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.

Explanation / Answer

anything allocated with new is created on the heap and must be de-allocated with delete.

A. true.

B. true

C.false(its not fine)

D. true(its a good practice but not necessary)

E.false (doesnot need parameters it can directly initialize all the values pointed by instance memeber data to 0)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote