#include<iostream>
#include <cstdlib>
#include<string.h>
#include<math.h>
using namespace std;
#define MAX 1000
class RandomFloatNumberGenerator{
private:
float arr[MAX];
public:
//Definition of generating random number
void generateNumber(float arr[]){
for(int i=0;i<MAX;i++){
float r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX/100);
cout<<"Number "<<r<<" is generated and stored in array."<<endl;
arr[i] = r;
}
}
//Definition of adding random number
void add(float arr[]){
float sum=0.0;
for(int i=0;i<MAX;i++){
sum += arr[i];
}
cout << "Total Sum = "<<sum<<endl;
}
//Definition of finding the average of random number
void average(float arr[]){
float sum=0.0;
for(int i=0;i<MAX;i++){
sum += arr[i];
}
cout<<"Average = "<<sum/MAX<<endl;
}
//Definition of displaying the random numbers
void display(float arr[]){
for(int i=0;i<MAX;i++){
cout<<"arr["<<i<<"] = "<<arr[i]<<endl;
}
}
//Definition of binary search
int search(float arr[],float num){
int first,last,mid;
first=0;
last=MAX-1;
while(first<=last){
mid =(first+last)/2;
//For doing comparision between two floating numbers we have to take some precision.
//Here 0.0001 is the precision or tolerance value.
if(fabs(arr[mid] - num)< 0.0001){
return mid;
}
if(arr[mid] < num)
first = mid+1;
else
last = mid-1;
}
return -1;
}
//Definition of sorting method
float* sort(float arr[]){
int i=0,j=0;
float temp;
for(i=0; i<MAX; i++)
{
for(j=0; j<(MAX-i-1); j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
return arr;
}
float* getArray(){
return arr;
}
};
int main(){
int loc = 0;
float num;
float temp_array[MAX];
srand(time(NULL));
RandomFloatNumberGenerator obj;//object creation
memcpy(temp_array,obj.getArray(),MAX);//copying the member array to a temp array
cout<<"Generating and storing random numbers into array"<<endl;
obj.generateNumber(temp_array);//calling generateNumber() function
obj.add(temp_array);//calling add() function
obj.average(temp_array);//calling average() function
cout<<"Before sorting the array is : "<<endl;
obj.display(temp_array);////calling display() function before sorting the array
cout<<"After sorting the array is : "<<endl;
obj.display(obj.sort(temp_array));//calling display() function after sorting the array
cout<<"Enter the number to search : "<<endl;
cin>>num;
num=float(num);
loc=obj.search(temp_array,num);//calling search() function
cout<<"Loc = "<<loc<<endl;
if(loc<0){
cout<<num<<" is not present!"<<endl;
}else{
cout<<num<<" is present at location "<<loc<<endl;
}
}

NOTE :-
Here I have attached the screen shot of output for array size 10 only.
c++ Gebremed、e Diagram TX ent/d/1cukolouus-Gqbal8MgX-znWzblaCw Xbct4azy5f6Mi/edit Search Divide and Conquer. Y ) (132) Zayn x |...
Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 - 1000. You will pass the array into functions that will perform operations on the array. Function 1: Create a function that will output all the integers in the array. (Make sure output is clearly formatted. Function 2: Create a Function that will sum and output all the odd numbers in the array. Function 3: Create a Function that will sum and output all the...
Using Arrays with Sorting and Searching Algorithms 1) This program has six required outputs and involves searching and sorting an array of integers. Write a java application that initializes an array with the following numbers, in this order: 23, 17, 5, 90, 12, 44, 38, 84, 77, 3, 66, 55, 1, 19, 37, 88, 8, 97, 25, 50, 75, 61, and 49. Then display the unsorted values. This is required output #1 of 6 for this program. 2) Using a...
Please Use C++ Language. And Note that please donot post the answer already there Because there is similar answer code but I need with modified Quick sort algorithm . Update your program from ... Create an array that holds 1000 random integers between 1-1000. Allow the user to enter an integer to search. Create and implement modified Quick sort algorithm which will sort the array before the Binary Search algorithm is executed. Create and implement a Binary Search Algorithm ....
Unit 4 Assignment 5: Coding Project using C# Binary Search Scenario Use the same integer array named partNumbers that you used for task 3. Sort the array in ascending order. 1065, 1095, 1075, 1055, 1056, 1090, 1098, 1088, 1097, and 1078. Java: use Array.sort() C#: use Array.Sort() PHP: use sort() Write code that asks the user to enter two part numbers. For C#, use console input. Implement a binary tree search function called binarySearch() to search the array for the...
Java Program Create a class to store an array of with enough space to store 10 integer values. Using the principle of recursion, implement the following: *getSize : returns the size of the array. *get (i): returns the i-th element of the array. If the element does not exist, it throws a "NoSuchElementException” which is a subclass of Java class RunTimeException. *add (val): inserts value as the last element of the array. If necessary, double the size of the current...
Write an object-oriented C++ program (i.e. a class and a main function to use it), using pointer variables, that program that performs specific searching and sorting exercises of an array of integers. This program has six required outputs. Start by initializing an array with the following integers, in this order: 23, 17, 5, 90, 12, 44, 38, 84, 77, 3, 66, 55, 1, 19, 37, 88, 8, 97, 25, 50, 75, 61, and 49. Your array input may be hardcoded...
Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...
In Java, Implement a class MyArray as defined below, to store an array of integers (int). Many of its methods will be implemented using the principle of recursion. Users can create an object by default, in which case, the array should contain enough space to store 10 integer values. Obviously, the user can specify the size of the array s/he requires. Users may choose the third way of creating an object of type MyArray by making a copy of another...
JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class. Print out the results after testing each of the methods in both of the classes and solving a simple problem with them. Task 1 – ArrayList Class Create an ArrayList class. This is a class that uses an internal array, but manipulates the array so that the array can be dynamically changed. This class should contain a default and overloaded constructor, where the default...
Write a C function that implements the Liner Search algorithm instead of Binary Search. However, this linear search algorithm returns the indices of the longest sorted subset of numbers in an array of integers of size n. The longest sorted subset of numbers must satisfy three conditions. First, the subset consists of unique numbers (no duplicate); second, all the numbers in this subset is divisible by m, the minimum size of the subset is two elements. In the main method...