Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PROJECT #1 One problem with dynamic arrays is that once the array is created using the new operator the size cannot be changed. For example,

PROJECT #1

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. This project asks you to create a class called DynamicStringArray that includes member functions that allow it.

The class should have the following private member variables:

dynamicArray that references a dynamic array of type string

. size that holds the number of entries in the array.

The class should have the following public methods:

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

A function sizeIs 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 dynamicArrays bounds.

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

printDynamicArray() that displays the elements of the dynamicArray Instructions:

You will be given 3 files:

DynamicStringArray.h (Do not modify)

DynamicStringArray.cpp (to be competed)

main.cpp (Do not modify)

You need to submit only DynamicStringArray.cpp When the main.cpp is run, the program should present the following input/output to the user

image text in transcribed

**Main.cpp** PROGRAM :

//***********************************************// // Do not change the this main program !!!!! //***********************************************// #include "DynamicStringArray.h" #include #include using namespace std; int main() { int op; string str; DynamicStringArray List; //DynamicStringArray=NULL size=0 cout>> choose an option from the menu  Enter your option from the menu:"; cin>>op; if(op5) { cout> Enter a string to add to the list: "; cin>> str; List.addEntry (str); break; case 2: cout>> Enter a string to remove from the list: "; cin>> str; List.deleteEntry(str); break; case 3: List.printDynamicArray(); break; case 4: break; } } while(op!=4); cout 

**DynamicStringArray.h** PROGRAM :

//***********************************************// // Please do not change the this file !!!!! //***********************************************// #ifndef DYNAMICSTRINGARRAY _H #define DYNAMICSTRINGARRAY _H #include #include using namespace std; class DynamicStringArray { public: DynamicStringArray(); int sizeIs(); string* getDynamicArray (); void addEntry (string); bool deleteEntry (string); string* getEntry(int ); ~DynamicStringArray (); void printDynamicArray(); private: string *dynamicArray; int size; }; #endif // DYNAMICSTRINGARRAY _H

***DynamicStringArray.cpp***

// Write the implementation of every method of the class // DynamicStringArray defined in DynamicStringArray.h #include "DynamicStringArray .h" //default constructor DynamicStringArray ::DynamicStringArray (){ //write code body of DynamicStringArray () } int DynamicStringArray ::sizeIs(){ //write code body of sizeIs () } void DynamicStringArray ::addEntry (string str){ //write code body of addEntry () }; bool DynamicStringArray::deleteEntry (string str){ //write code body of deleteEntry () } string* DynamicStringArray::getEntry(int index){ //write code body of deleteEntry () } //destructor DynamicStringArray ::~DynamicStringArray (){ //write code body of ~DynamicStringArray () } void DynamicStringArray ::printDynamicArray(){ //write code body of printDynamicArray () }

*PLEASE MAKE SURE THE CODE RUNS AND THE FORMAT IS IN C++*

WILL GIVE A THUMBS UP RATING:)

-->>> choose an option from the menu 1. Add an entry to the list of string.. 2.Delete an entry to the list of string. 3.Display the list entries... 4. End Program.. >> Enter your option from the menu:1 >>> Enter a string to add to the list: live >> Enter your option from the menu:1 >>> Enter a string to add to the list: nice >> Enter your option from the menu:1 >>> Enter a string to add to the list: beautifull >> Enter your option from the menu:3 The list content: live || nice || beautifull || >> Enter your option from the menu:1 >>> Enter a string to add to the list: enjoy >> Enter your option from the menu:3 The list content: live || nice || beautifull || enjoy >> Enter your option from the menu:2 >>> Enter a string to remove from the list: NICE WICE is not in the list >> Enter your option from the menu: 3 The list content: live | nice || beautifull || enjoy | >> Enter your option from the menu:2 >>> Enter a string to remove from the list: nice >> Enter your option from the menu:3 The list content: live || beautifull || enjoy | >> Enter your option from the menu:4 End of Program. Bye

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

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions