Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programing in C++ Data Structure Task 1: Update your program from Assignment 6 and 3. Create an array that holds 1000 random floats between 1-1000.

Programing in C++ Data Structure

Task 1:

Update your program from Assignment 6 and 3.

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 my previous code:

#include #include #include #include

using namespace std;

class Average{ private: float numarray[1000]; public:

void randomarray(){ srand (time(NULL)); for(int i=0;i<1000;i++){ float r = (rand() / (float)RAND_MAX * 99) + 1; numarray[i] = floor(r); } }

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

float summing(){ float sum = 0; for(int i=0;i<1000;i++){ sum = sum + numarray[i]; } return sum; }

float averagearay(){ float s = summing(); return s/1000; }

void BinarySearch(float input){ int smallest = 0; for(int i=0;i<1000;i++){ smallest = i; for(int j=i+1;j<1000;j++){ if(numarray[j] < numarray[smallest]){ smallest = j; } } float temp= numarray[i]; numarray[i] = numarray[smallest]; numarray[smallest] = temp; }

int l = 0; int r = 999; int found = 0; int m; while (l <= r){ m = l + (r-l)/2; if (numarray[m] == input){ found = 1; break; }

if (numarray[m] < input) l = m + 1; else r = m - 1; } if(found == 1){ cout<<" Number:"<

}

};

main(){ Average obj; obj.randomarray(); obj.showaray(); cout<

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

Define Administration and Management

Answered: 1 week ago

Question

=+Do you want to work from home?

Answered: 1 week ago

Question

=+ What skills and competencies will enable someone

Answered: 1 week ago

Question

=+to live and work wherever he or she wants?

Answered: 1 week ago