(Solved) : Write Function Makes Brand New Empty Strarray Size 0 Capacity Cap Header Strarray Makeempt Q43936488 . . .
-
Write a function that makes a brand new empty str_array of size0 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 ofsize 0 and capacity 50, and calling make_empty() returns a newstr_array object of size 0 and capacity 10.
-
To avoid memory leaks, programmers must remember to always calldeallocate when they are finished using a str_array:
void deallocate(str_array& arr)
deallocate(arr) calls delete[] on the underlying array, and alsosets the array pointer to nullptr. Setting the array pointer tonullptr prevents memory corruption in cases when deallocate iscalled 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. Forexample, if arrs size is 5 and its capacity is 15, pct_used(arr)should return 0.333333.
Language is C++
Expert Answer
Answer to Write a function that makes a brand new empty str_array of size 0 and capacity cap. It should have this header: str_arr…
OR