In: Computer Science
c++ language
Create a file program that reads an int type Array size 10; the array has already 10 numbers, but your job is to resize the array, copy old elements of array to the new one and make it user input and add an additional 5 slots in the array, and lastly do binary search based on user input. close the file.
So I have implemented the required code, please read all the
comments carefully, every bit of line is explained using comments
because if I try to explain as a whole then possibly it will become
difficult for you to understand.
Let me tell you the main algorithm I have followed
Step 1: I have extracted the values from the text file using the syntax as the C++ rules
Step 2 : Created array of 5 slots bigger and copied the values and took input for remaining 5 values.
Step 3 : User input for the element to be searched and called binary search function thereafter.
In the last add cout if you want to print the result of binarySearch function.
Below is the output :
first line shows numbers read from .txt file, second is input for 5 extra slots, third is the element to be searched and final fourth is the location of the element which is searched