Question
Searching and Sorting Write a program that prompts the user to enter the number of elements and the numbers themselves to be placed in an
Searching and Sorting
Write a program that prompts the user to enter the number of elements and the numbers themselves to be placed in an integer array that holds a maximum of 50 elements. The program should then prompt the user for an integer which will be searched for in the array using a binary search. Make sure to include the following step along the way:
-A sort routine must be called before the binary search. You may use either the selection sort or the bubble sort. However, the sort must be implemented in its own function and not in main.
-Next include a function called by main to implement the binary search.The ordered array produced by the sort should be passed to the search routine which returns the location in the sorted array of the sought value, or -1 if the value is not in the array.
-Add a value returning function that computes the mean of you data set. Recall that the mean is the sum of the data values divided by the number of pieces of data. Your program should output the size of the array entered, the array as entered by the user, the sorted array, the integer being searched for, the location of that integer in the sorted array (or an appropriate message if it is not in the array), and the mean of the data set.
-Modify your program so that the data is entered from a file rather than from the keyboard. The first line of the file should be the size of the integer array. The second line should contain the integer searched for in the data set. Finally, the array elements are to start on the third line. Make sure you separate each array element with a space. The output, as described in should be sent to a file.
Sample Output:
Please input the number of integer
5
Please input integer number 1
4
Please input integer number 2
8
Please input integer number 3
-2
Please input integer number 4
10
Please input integer number 5
7
Enter an integer to search for:
1
This array has 5 items.
The array entered by the user is
4 8 -2 10 7
The sorted array is as follows:
-2 4 7 8 10
The item searched is 1
The value 1 is not in the list
The mean of all the elements in the array is 5.4
Press any key to continue . . .
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