Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Youre to write a program thatll prompt the user to enter the number of elements for an array. Then the user will supply the integer

Youre to write a program thatll prompt the user to enter the number of elements for an array. Then the user will supply the integer values. The objective is to display the array the user entered, sort the array from least to greatest, and then display the revised array. This will all be done using pointers and dynamic memory.

Sample run:

$ ./a.out Enter the number of elements: 7 Enter 7 ints for the array: [1]: 7 [2]: 10 [3]: -3 [4]: 4 [5]: 2 [6]: -1 [7]: 12 The array you entered is: 7 10 -3 4 2 -1 12 The sorted array is: -3 -1 2 4 7 10 12 Releasing memory...

Main function will be responsible for getting the number of elements from the user. Then it will call the AllocArray function which will allocate a block space of memory (dynamic) and return the address of the location and store it to a pointer. It will then call the function InitArray which will prompt the user to fill the array with integer values. After, main will call the DispArray function to display the array the user entered. Then main will call the SortArray function, which will sort the array from least to greatest. Another call to DispArray will be made to show the updated results. Main should take care of releasing the memory allocated. Main function should be written in its own file called main.cpp

The functions below should be written in a file called DynMem.cpp

AllocArray will accept as argument an int value that has the number of elements the user desires. It will allocate a block space of memory and return the address.

InitArray will accept as argument an int pointer and an int value of the number of elements. It will prompt the user to enter a value to fill the array. It will return nothing.

DispArray will accept as argument an int pointer and an int value of the number of elements. It will display the array to the monitor. It will return nothing.

SortArray will accept as argument an int pointer and an int value of the number of elements. It will sort the contents of the array from least to greatest. It will return nothing.

Create a file called DynMem.h where you will only place the function prototypes.

As usual, make sure you're clear on how information is getting passed around before writing any code. An excellent way to get started is to first sketch out the program with a structure chart, that way you'll have a better idea of the function call hierarchy, as well as the data flow among the functions. You can save your code in the HW19 subdirectory with the files main.cpp, DynMem.cpp, and DynMem.h. Good luck!

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_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+7 How has the COVID-19 pandemic impacted the operations of IHRM?

Answered: 1 week ago