Question: Please help me with this: Update the previous task. Create an array that holds 1000 random floats between 1-1000. Allow the user to enter an

Please help me with this: Update the previous task. Create an array that holds 1000 random floats between 1-1000.

Allow the user to enter an float to search.

Create and implement modified bubble sort algorithm which will sort the array before the Binary Search algorithm is executed.

Create and implement Insertion sort algorithm which will sort the array before the Binary Search algorithm is executed.

Create and implement a Binary Search Algorithm .

If the number exists in the array output the position.

If the search key does not exist in the Array simple output value not found.

Make sure to try and simulate value in the array and the value not appearing in the array.

Use the clock(); method to time the execution of the search and sort

Execute the program 4 times. Twice running the modified bubble sort as the sorting algorithm and twice running the Insertion Sort as the sorting algorithm

Describe your results: Here is the previous code from the program:

#include

using namespace std;

class ArrayManipulator {

// Creating array as the member of the class

public:

//const int max = 10;

float array[10];

float randomArray[1000];

int binarysearchElements[8] = {

25,

45,

78,

56,

84,

59,

21,

37

};

void createArray() {

for (int i = 0; i < 10; i++) {

cout << "Enter the " << i << " element : ";

cin >> array[i];

}

}

//Create a method that will generate 1000 random floats (between 1-100) No decimal valuables

void GenerateRandomFloat() {

cout << "The Generated array is: " << endl;

for (int i = 0; i < 1000; i++) {

randomArray[i] = rand() % 100 + 1; // generating random number between 1-100

cout << randomArray[i] << ", ";

}

}

//Create 1 method to sum all numbers in array

float SumArray() {

float sum = 0;

for (int i = 0; i < 10; i++) {

sum = sum + array[i];

}

return sum;

}

//Create 1 method to output the average of all numbers input by the user.

void averageArray() {

float sum = SumArray();

cout << "The average of all elements in list is: " << sum / 10 << endl;

}

//Create 1 method to output all the numbers input by the user.

void showallElements() {

cout << "The elements entered by user is : " << endl;

for (int i = 0; i < 10; i++) {

if (i == 10)

cout << array[i] << endl;

else

cout << array[i] << ", ";

}

}

int binarySearch(int arr[], int l, int r, int x) {

if (r >= l) {

int mid = l + (r - l) / 2;

// If the element is present at the middle

// itself

if (arr[mid] == x)

return mid;

// If element is smaller than mid, then

// it can only be present in left subarray

if (arr[mid] > x)

return binarySearch(arr, l, mid - 1, x);

// Else the element can only be present

// in right subarray

return binarySearch(arr, mid + 1, r, x);

}

// We reach here when element is not

// present in array

return -1;

}

};

int main() {

int searchNumber;

ArrayManipulator arraymanipulator;

//cout<<"Please enter the length of array : ";

//cin>>arraymanipulator.max;

cout << "Enter the elements of array : " << endl;

arraymanipulator.createArray(); // Creating array elements

arraymanipulator.showallElements(); // showing all elements

arraymanipulator.GenerateRandomFloat(); // Generating random numbers

float sum = arraymanipulator.SumArray(); // sum of array numbers

cout << "The sum of numbers generated in array is : " << sum << endl;

arraymanipulator.averageArray(); // average of array numbers

cout << "Enter the number you want to search for : ";

cin >> searchNumber;

int result = arraymanipulator.binarySearch(arraymanipulator.binarysearchElements, 0, 7, searchNumber);

(result == -1) ? cout << "Element is not present in array": cout << "Element is present at index " << result + 1;

return 0;

}

Please read the question thoroughly. It should be in c++ language. Thanks in advance.

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!