Question
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started