Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++: Update the program below by adding the new requirements in this task. Please describe the results and add short comments to explain program. #include

C++: Update the program below by adding the new requirements in this task. Please describe the results and add short comments to explain program.

image text in transcribed

#include #include #include

using namespace std;

class Arr { private: int size; float* value;

public: Arr(){ }

Arr(int size) { this->size = size; value = new float[size]; }

void setSize(int size) { Arr c(size); this->size = size; }

int getSize() { return size; }

void inputValue() { srand(time(NULL)); for (int i = 0; i > value[i];

value[i] = rand() % (100-1) + 1; }

}

float addSum() { float total = 0.0;

for (int i = 0; i

return total; }

float calcAvg() { return addSum() / size; }

void displayValue() { cout

int binarySearch() { int i, j;

for (i = 0; i

for (j = 0; j

if (value[j] > value[j+1]) { int temp = value[j]; value[j] = value[j+1]; value[j+1] = temp; } } } int x, low = 0, high = size-1;

cout

cin >> x;

while (low

int mid = low + (high - low)/2;

if (value[mid] == x) return mid;

if (value[mid]

else high = mid - 1;

}

return -1; }

};

int main() { int size = 1000; int x;

//cout > size;

Arr c(size);

c.inputValue();

c.displayValue();

float sum = c.addSum();

float avg = c.calcAvg();

int index = c.binarySearch();

cout

if(index != -1) cout

return 0;

}

Task 3 Create an array that holds 100000 random floats between 1-1000. Depending on your computer and compiler the above example may not work. Attempt to execute from the command line is Visual Studio/IDE doesn't work. Reduce the number of floats to 10,000 if your computer cannot handle the execution. Allow the user to enter an floats 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 he Binary Search algorithm is executed Create and implement a Binary Search Algorithm. If the number exists in the array and output the position. If the search key does not exist in the Array simple output value not found. 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 Attach Photos of Source Code and Output

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

More Books

Students also viewed these Databases questions