Question: Write a function that makes a brand new empty str_array of size 0 and capacity cap. It should have this header: str_array make_empty(int cap =

Write a function that makes a brand new empty str_array of size 0 and capacity cap. It should have this header:

str_array make_empty(int cap = 10)

For example, calling make_empty(50) returns a new str_array of size 0 and capacity 50, and calling make_empty() returns a new str_array object of size 0 and capacity 10.

To avoid memory leaks, programmers must remember to always call deallocate when they are finished using a str_array:

void deallocate(str_array& arr)

deallocate(arr) calls delete[] on the underlying array, and also sets the array pointer to nullptr. Setting the array pointer to nullptr prevents memory corruption in cases when deallocate is called more than once on the same array.

Implement this function:

// Returns the percentage of the array that is in use. double pct_used(const str_array& arr)

This returns the size of the array divided by its capacity. For example, if arrs size is 5 and its capacity is 15, pct_used(arr) should return 0.333333.

Language is C++


Step by Step Solution

3.55 Rating (148 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To address the task I will guide you through implementing the required C functions to manage a dynamic string array structure strarray Each step will ... View full answer

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 Programming Questions!