Question: The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user

The name of the C++ file must be search.cpp

Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will be searched for in the array using binary search. Make sure to include the following:

- A sort function must be called before the binary search. Implement the selection sort function that uses findMin and swap functions.

- Include a function called by main to implement the binary search.

- The ordered array produced by the sort function 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 median of your data set. (i.e. main function will display the median)

- Use showArray function to show elements of the array before sorting and after sorting as required in the program output. The function should display the array values nicely formatted in rows.

The program should output:

- The total number of elements read from the file (valid items in the array)

- The array as read from the file

- The sorted array

- The integer being searched for and the location of that integer in the sorted array (or an appropriate message if it is not in the array)

- The median of the data set.

Assume that the maximum number of values in the input file will not exceed 50. Sample input file: data.dat

data.dat :

67 34 566 233 1 28334 65 3343 233 45 34 233 78 12 3 5 890 23 4 455 3445 433 567 547 899 23 879 90 677 455 356 23 78 99 799 779 57547 455 334 847

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!