Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a c++ program that will: - Create a dynamic array of integers (int) starting size 2 + This will be used to store user

Write a c++ program that will: - Create a dynamic array of integers (int) starting size 2 + This will be used to store user input elements.

- Create a menu interface with the options: Print Elements, Add Element, Delete Element, Return Size, and Exit. This will be how the user interacts with the array.

+ Print Elements: + This option will print all the elements currently stored in the array.

+ Add Element: + This option asks the user to input a number to store into the array, then inserts the number in the correct position of the array such that all elements are in ascending order. + If the array does not have room to add another element, the array should be expanded to 2 times its current size before adding the element. + Print a message of the new size of the array whenever it is expanded. + There should be no gaps between elements in the array.

+ Delete Element: + This option should ask the user for a number to remove from the array. + If the specified number does not exist inside the array or if the array is empty, an appropriate error message should be displayed. + Anytime an element is deleted from the beginning or middle of the array, all other elements in the array should be shifted over to fill the empty gap. + If the number of elements is less than half the size of the array, the array should be shrunk down by half times its current size. + Print a message with the new size of the array whenever its shrunk.

+Return Size: + This option prints the current size of the array along with the number of elements stored within it.

+Descend +This option should rearrange all the elements in the array into a descending order. It should also add all future elements in a descending order. - After the Descend option is selected, its menu option should change to print Ascend. - If the option Ascend is selected again the array should be rearranged in ascending order and continue its normal adding operation in ascending order.

+ Exit: + This option deallocates all dynamic variables and ends the program.

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

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions