Question
Dynamic String Array C++ PROGRAMS : For this project, use pointer notation rather than array notation rather than array notation. For example, use *(ptr +
Dynamic String Array
C++ PROGRAMS : For this project, use pointer notation rather than array notation rather than array notation. For example, use *(ptr + i) instead of ptr[i] where ptr is a pointer to a string.
The logic similar to what the vector C++ object uses.
In main, create a loop that asks for a user choice and prints the following menu:
Please choose from the following menu choices 1) Insert a new element to the end of the list. 2) Insert a new element at the beginning of the list. 3) Insert an element into the list at a given index. 4) Remove an element from the end of the list. 5) Remove an element from the list at a given index. 6) Sort the list. 7) Print the contents of the list. 8) Exit.
Implement each option in the menu. Use the following function prototypes for your design:
void printMenu(); void printList(string *p, int size); string *expand(string *p, int &size); bool insertAtZero(string *p, string item, int count); bool insertAt(string *p, string item, int index, int count); bool insertAtEnd(string *p, string item, int count); bool removeFromEnd(string *p, int count); bool removeFrom(string *p, int index, int count); void sort(string *p, int count);
Note, size is the current size of the dynamic array which may be empty, or (partially) filled; and count is the number of elements currently in the list. When the list is empty, count = 0. When the list is full, count = size; otherwise it is somewhere in between.
For your insertAt function (option 3 in the menu), make sure the index given is not greater than the count of integers currently in the list. If the index is out of bounds, return false. Otherwise, return true and update the count of elements in the list.
For your removeFrom function, make sure the index is valid. If the index is not valid, return false. If the removal succeeds, return true and update the count of elements in the list.
For your sort function, you can use any sorting algorithm you like. Be sure to use pointer notation rather than array notation for your algorithm.
You may combine insertAtZero and insertAt if you wish, since you could just pass an index of 0 into insertAt to accomplish the same task.
Use the example shown in class with the int array for hints. This code is posted on the Canvas Knowledge Building page for Module 09. Remember to expand the array when the size is equal to the count.
Make sure you use "new" to dynamically allocate your arrays. If you allocate them on the stack by declaring them normally the addresses will not be valid when the functions return.
Note that expand() returns the pointer to the newly expanded array. This means that expand should be called from main so the pointer to the array in main can be updated.
Don't forget to free up your dynamic pointers when the program completes to avoid memory leaks.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started