SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,kenrick Mock
Chapter:
Pointers And Dynamic Arrays
Exercise:
Programming Projects
Question:6 | ISBN:9780132846813 | Edition: 5

Question

One problem with dynamic arrays is that once the array is created using the new operator the size cannot be changed. For example, you might want to add or delete entries from the array similar to the behavior of a vector . This project asks you to create a class called DynamicStringArray that includes member functions that allow it to emulate the behavior of a vector of strings. The class should have the following:

• A private member variable called dynamicArray that references a dynamic

array of type string.

• A private member variable called size that holds the number of entries in

the array.

• A default constructor that sets the dynamic array to NULL and sets size to 0.

• A function that returns size .

• A function named addEntry that takes a string as input. The function should

create a new dynamic array one element larger than dynamicArray , copy all elements from dynamicArray into the new array, add the new string onto the end of the new array, increment size, delete the old dynamicArray , and then set dynamicArray to the new array.

• A function named deleteEntry that takes a string as input. The function

should search dynamicArray for the string. If not found, it returns false . If

found, it creates a new dynamic array one element smaller than dynamicArray. It should copy all elements except the input string into the new array, delete dynamicArray , decrement size, and return true.

• A function named getEntry that takes an integer as input and returns the

string at that index in dynamicArray . It should return NULL if the index is out of dynamicArray ’s bounds.

• A copy constructor that makes a copy of the input object’s dynamic array.

• Overload the assignment operator so that the dynamic array is properly copied to the target object.

• A destructor that frees up the memory allocated to the dynamic array.

Embed your class in a suitable test program.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.