Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem: write the function for the binary search. Thefunction should return the

ID: 3617712 • Letter: P

Question

Problem: write the function for the binary search. Thefunction should return the position of the elementfound.

The code should have 3 functions (one to input values into thearray, one to print the array, and one to search the array). Your main function should call the function to input elements intothe array, call the function to print the contents of the array,call the function to search the array, and then print the locationof the found element (if applicable). If the element was notfound in the array, then there should be a printout to indicatethat.


I have tried the most part, and the code is still not working,and I really don't know how to fix the functionthat do the binary search. Any help to fix myprogram is appreciated, thanks


#include <iostream>

using namespace std;

int Function1(double []);
void PrintArray(const double [], int);
const int MAXSIZE =100;
int main()
{    double array1[100];
    int count,target;
    count = Function1(array1);
    cout<<"There were "<<count<<"numbers entered into the array."<<endl;
    PrintArray(array1,count);   //function call to function that will print the array
    cout<<"Enter a number to search for:";
    cin>>target;
    result= search(array1,size,target)
    if (result== -1)
    cout<<target<<" is not on thelist"<<endl;
    else cout<<target<<" is stored inarray position "<<result+1<<endl;
    system("pause");
    return 0;}
//Write the function here to read in numbers into the array. The array is called myarray.
//add comments describing what this function does, what is passedto it, what it sends back, etc.

int Function1(double myarray[])// this functions works to input thenumbers(user entered) into arrays,
                              // the inputed numbers is passed to this function
                             // it sends back the counts ofnumbers
{ int count=0;
    cout<<"Please enter some numbers "<<count+1 <<endl;
    cin>>myarray[count];
    while(count < MAXSIZE-1 &&myarray[count] >= 0 &&myarray[count]>myarray[count-1])
{ count++;
    cout<<"Please enter some number"<<count+1<<endl;
    cin>>myarray[count];
} if(count==MAXSIZE-1)
    return count+1;
    return count;}
//Write the new function here along with comments
//add comments describing what this function does, what is passedto it, what it sends back, etc.



void PrintArray(const double a1[], int size) //this function willprint the inputed numbers one by one,
                                           //the name of each numbers (in numeric order) is passed to thefunction using for loop
                                         //it sends back the numberrespectively in order which same as input order.
{
for ( int i = 0; i < size; i++ )
{
    cout << a1[ i ] << endl;
}
}

int BinarySearch(double array1[ ], int size, double target)
{    int high = size-1, low = 0, middle;
while (low <= high)
{    middle = (low + high)/2;
if (key == array1[middle]) {
            returnmiddle;}
else if (key < array1[middle]) {   
            high =middle - 1 ;
        } else{   
            low =middle + 1 ;
        }   
    }return -1;
}

Explanation / Answer

please rate - thanks code was good, variable names were different throughout and aprototype was missing and a few ; #include using namespace std; int BinarySearch(double[ ], int , double ); int Function1(double []); void PrintArray(const double [], int); const int MAXSIZE =100; int main() {    double array1[100];     int count,target,result;     count = Function1(array1);     cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote