Question
In C++: populate an array of 20 integers with random numbers range from 1-1000. Display these numbers. The program will then sort the numbers into
In C++: populate an array of 20 integers with random numbers range from 1-1000. Display these numbers. The program will then sort the numbers into ascending order using insertion sort. Display the numbers again. The program should then ask the user to input a number, and search to see if the number exists in the array. Your program will need to implement a recursive version of that sequential search algorithm to search for the number.
Use functions to organize your code. You should use the following functions:
-
A function to populate the array with random numbers between 1 and 1000.
-
A function to display the numbers on the array.
-
A function to sort the array in ascending order using insertion sort.
-
A function that searches for the number. The number to be searched for can be obtained in main and passed to the function.
Example output:
lcome to my Recursive Sequential Search Program nsorted.... 501 1) 159 2) 834 3) 906 892 639 ) 19 7) 336 ) 60 640 10) 856 11) 152 12) 565 13) 932 14) 308 15) 177 16) 480 17) 466 18) 710 19) 164 Sorted 19 1) 60 2) 152 3) 159 164 5) 177 308 ) 336 8) 466 ) 480 10) 501 11) 565 12) 639 13) 640 14) 710 15) 834 16) 856 17) 892 18) 906 19) 932 lease Enter the number to be recursively searched in the sorted list: 710 710 is found at index 14 ress any key to continueStep 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