Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class StudentArrayV4 { // version 4: dynamic array of object pointers public: StudentArrayV4( ); ~StudentArrayV4( ); void add( ); void write( ); private: Student** members

class StudentArrayV4 { // version 4: dynamic array of object pointers public: StudentArrayV4( ); ~StudentArrayV4( ); void add( ); void write( ); private: Student** members = nullptr; int number_of_students = 0; int physicalArraySize = 0; };

A constructor for this class can allocate a small array for the Student pointers and save the number as physicalArraySize; the value for number_of_students is initially zero. Write this constructor now; let the initial physical array size be three.

Students may be dynamically allocated and added to the array until the physical size limit is reached. At that point, a new pointer array of larger size is allocated, the pointers from the existing array are copied into it, and the existing array is then removed from memory. The physical size limit is increased accordingly, allowing successive additions to be made without additional work until the new physical size is reached. Write method add so that new array allocations are larger by three each time.

The destructor for this class will have to carefully free the memory we allocated. Remember that each Student in the array has been dynamically-allocated, so they must be freed. Additionally, the array itself was dynamically-allocated, so it must be freed (but only after freeing all students that it points to).

Help me write out the .cpp file

this is C++

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions