Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 =

  1. 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.

  2. 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.

  3. 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

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

Question

Describe the five elements of the listening process.

Answered: 1 week ago