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

I need to write a program that can give this output: The initialized array : 41

ID: 3539831 • Letter: I

Question

I need to write a program that can give this output:


The initialized array : 41 67 34 0 69 24 78 58 62 64


The sorted array : 0 24 34 41 58 62 64 67 69 78


Linear search called for value 50 : value not found !

Linear search called for value 64 : value found at index 6


Binary search called for value 50 : value not found !


Binary search called for value 64 : value found at element 6


For Linear Search I tried, but I couldn't understand how to do it. I use different functions, such as void SortArray(), void Inputarray(), void Binarysearch(), void linearSearch() and use main() to call these functions, but didn't work for me.

So, I tried using different method, which it's shown below, but I get errors and I need help on linearSearch as well.


#include<iostream>

#include<iomanip>

#include<array>

#include<string>

#include<algorithm>

using namespace std;


int main()

{

const size_t SIZE = 10;

array< int, SIZE> c = {41, 67, 34, 0, 69, 24, 78, 58, 62, 64};

//Output original array

cout << "The initialized array : ";

for(int c : c)

cout << c << " ";

sort( c.begin(), c.end() );

cout << " Sorted array: ";

for(int item : c)

cout << item << " ";

//Search for value 50

bool found = binary_search( c.begin(), c.end(), "50");

cout << " "50" " << ( found ? "was" : "was not")

<< " found in array" << endl;

//Search for value 64

found = binary_search( c.begin(), c.end(), "64");

cout << " "64" " << ( found ? "was" : "was not")

<< " found in array" << endl;


}

Explanation / Answer

#include using namespace std; void SortArray(int num[],int arrlen) { int i, j, first, temp; int numLength = arrlen; for (i= numLength - 1; i > 0; i--) { first = 0; // initialize to subscript of first element for (j=1; j num[first]) first = j; } temp = num[first]; // Swap smallest found with element in position i. num[first] = num[i]; num[i] = temp; } //return; } int linearSearch(int search,int num[],int len) { for(int i=0;i