Question
For this exercise, you will create a dynamic array and manipulate it using pointers. (C++) Program Requirements While the program will be an introduction to
For this exercise, you will create a dynamic array and manipulate it using pointers. (C++)
Program Requirements
While the program will be an introduction to pointers and dynamic memory, it is also a review of functions, arrays, searching, and sorting. For this program you will get a value from the user between 10 and 20, create an array of this size using dynamic memory allocation, fill the array with random numbers between 1 and 99, sort the array, and then display the array. You will then ask the user for 3 numbers and for each value you will say whether it is in the array or not. In order to give you more practice with pointers, you are to do all array element accesses with a pointer instead of using subscripting. (int * ptr = array; *ptr = value; instead of array[0] = value;)
Required functions
The first function will ask the user for a value between 10 and 20, verify that they entered an integer in this range, and return it to main. You will pass this length to the second function. This function will create an array of that length using dynamic memory allocation (the new operator) and fill it with random numbers between 1 and 99. For all of your memory accesses you are to use pointer dereferencing (*array) instead of array subscripting (array[0]). Once the array is created and filled, you will return it using a pointer. The third function is a sort function. You will pass in the array along with its length and then sort it using any of the sorts described in class last week. The array should be sorted in ascending order (smallest at first location, largest at last location). The fourth function is a display function. You will pass the array to the function along with its length. Then you will display the values, five per line. Again, you are to do all your memory references using pointer dereferencing. The fifth function is a search. You will pass in the array to the function along with a value. You return true if the value is in the array, false otherwise.
Your main should have this basic structure:
getSize
createArray
sortArray
displayArray
loop three times
getInteger
search
output if found or not
You need to use constants where appropriate and comment all functions. You should free up the memory from your array, using delete properly when you are done.
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