Question: --------------- done in c++ ----------------- For this exercise, you will create a dynamic array and manipulate it using pointers. Problem Description: While the program will

--------------- done in c++ -----------------

For this exercise, you will create a dynamic array and manipulate it using pointers.

Problem Description:

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 -50 and 50, insert

them into the array in sorted order, 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 using a binary search.

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;)

For this, as in all assignments, you are expected to follow the course programming style guidelines

and to properly implement both header and source files for your functions. All input should be

validated as integer and within range.

Required functions

getInteger

o used to input array size and integers to add to the array

o input parameters are min and max value

o get and validates an integer between min and max

o return the value

createArray

o used to create and fill the array

o input parameter is the array size

o dynamically creates an array of that size

o fills the array

  • all accesses with pointer dereferencing *(array+i)
  • sorting in order from smallest to largest as each item is added
  • with numbers between -50 and 50

o returns the array using a pointer

displayArray

o displays the array

o input parameters the array and its size (pass safely)

o display the array five values per line in neat columns

  • all accesses with pointer dereferencing

o no return values

binSearch

o binary search function

o input parameters the array safely, size, and value to search for (all safe passes)

o perform a binary search

all accesses with pointer dereferencing

o return true if the value is present, false otherwise

Main will define a pointer to save the address of the array, call these functions, and terminate when

done. A for loop should be used to get the values to search for and they should be entered with

getInteger. The array memory should be properly freed when no longer needed.

Program Suggestion:

Your main should have this basic structure:

get the array size between 10 and 20

create and fill the array

display the array

loop three times

o get a new number

o search the array for that number

o output if found or not

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!