Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program in C++ Data Structure Task 2: Task 2 (Repurpose Task 2 Assignment 3 and Task 3 Assignment 6): Write a program that uses an

Program in C++ Data Structure

Task 2:

Task 2 (Repurpose Task 2 Assignment 3 and Task 3 Assignment 6):

Write a program that uses an array to find the Average of a set float values entered by the user.

You will have the main function control the operation of the program, but all values will be stored in the class.

You will need to use get and set methods in your class.

Create an array as a member of the class.

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

Create 1 method to sum all numbers in array

Create 1 method to output the average of all numbers.

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

Hard Code a Binary Search Method and allow the user to input a value to search for. Output if the value exist in the array. If the value exist in array output the location in the array.

Create a menu to control your program. Give the user the option to choose the operation to perform. Make sure there is a choice to select Fill Array, all through the array will be filled with random numbers.

Create and implement isEmpty helper method, if the user decides to search for a number, output average, etc. before there are values inside of the array. The program should prompt the user to say Array is empty.

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

Finance The Role Of Data Analytics In Manda Due Diligence

Authors: Ps Publishing

1st Edition

B0CR6SKTQG, 979-8873324675

More Books

Students also viewed these Databases questions

Question

Explain the sources of recruitment.

Answered: 1 week ago

Question

Differentiate sin(5x+2)

Answered: 1 week ago

Question

Compute the derivative f(x)=1/ax+bx

Answered: 1 week ago

Question

What is job enlargement ?

Answered: 1 week ago