Question: There is some erorrs in .cpp file. it is a C++ program. ////////BinarySearch.cpp//////////// #include #include #include BinarySearch.hpp using namespace std; int recursiveBinarySearch(int array[], int start_index,

There is some erorrs in .cpp file. it is a C++ program.

////////BinarySearch.cpp////////////

#include

#include

#include "BinarySearch.hpp"

using namespace std;

int recursiveBinarySearch(int array[], int start_index, int end_index, int targetValue);

//if the start index is lower than the end index we can start the recursive search

if (start_index < end_index) {

//compute the midpoint within the range of possible numbers

int mid = (start_index + end_index) /2;

//if

if (targetValue == array[mid]) {

return mid;

} else if (targetValue < array[mid]) {

return recursiveBinarySearch(array, start_index, mid -1, targetValue)

} else {

return recursiveBinarySearch(array, start_index, mid +1, targetValue)

}

}

return -(start_index + 1);

}

//////////BinarySearch_test.cpp///////////

#include

#include

using namespace std;

int recursiveBinarySearch(int array[], int start_index, int end_index, int targetValue)

{

//if the start index is lower than the end index we can start the recursive search

if (start_index < end_index) {

//compute the midpoint within the range of possible numbers

int mid = (start_index + end_index) /2;

//if

if (targetValue == array[mid]) {

return mid;

} else if (targetValue < array[mid]) {

return recursiveBinarySearch(array, start_index, mid -1, targetValue);

} else {

return recursiveBinarySearch(array, start_index, mid +1, targetValue);

}

}

return -(start_index + 1);

}

int mai() {

//declare ifstream object

ifstream inputFile;

//declare size for array

int size;

//open dataarray.bin using ifstream object

inputFile.open("dataarray.bin", ios::in | ios::binary);

//use seekg method to read memory of the .bin file

inputFile.seekg(0, ios::end);

//use tellg method and assign memory to size

size = inputFile.tellg() / sizeof (int);

//reset stream object to beginning of .bin file

inputFile.seekg(0);

//create pointer for array

int * array;

//create array with dynamic memory allocation

array = new (nothrow) int[size];

//use read method to read contents of .bin into array

inputFile.read(reinterpret_cast (array), size*size);////modified

//close input file

inputFile.close();

//sort?

//declare a int value variable and int result variable

int value, result;

//output message to user, asking "Enter the number you want to search"

cout << "Enter the number you want to search" << endl;

//assign response to value

cin >> value;

//call the recusriveBinarySearch function and assign return value to result

result = recursiveBinarySearch(array, 0, size - 1, value);

//tell user if we could find their number

if (result < 0) {

cout << "the number you entered couldn't be found" << endl;

} else {

cout << "Your number was found at the index" << result << "in the array" << endl;

}

//return 0

return 0;

}

///////BinarySearch.h/////////

#include

using namespace std;

int recursiveBinarySearch(int array[], int start_index, int end_index, int targetValue);

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!