Program 8 Solution

Allocate two array variables with space for 20 integers each Call chooseSize to get the data size

Call generateValues to fill one array

Call duplicate to copy first array values into the second array Call sort to sort second array

Give user a menu of choices:

Sequential search (of first array) Binary search (of second array) Output

Quit

Perform the specified operation, write out the results (of the searches), and repeat the menu until the user chooses to quit.

Function descriptions:

chooseSize – ask the user to choose a number in the range of 5 to 20 (inclusive).

Repeat the input until they enter a number in the correct range, then bring

that number back to the calling program.

generateValues – use unique values from the Fibonacci sequence to fill the array

with the number of values chosen by the user. Start with 1 and 2 and go from there (1,2,3,5,8,...) so that each value is unique. After putting the values into the array, randomize their positions within the array space.

duplicate – copy one array into another, one element at a time.

sort – use a bubble sort or a selection sort to sort the array data into increasing

order.

sequential – perform a sequential search for a number specified by the user. binary – perform a binary search on a sorted array for a number specified by the

user.

output – write out all of the known values in the array, showing a maximum of 5

values per line.
Powered by