For the following program, Arrays are used to perform the following given tasks
Program:
#include <iostream>
using namespace std;
int binarySearch(int arr[], int l, int r, int x)
{
while (l <= r) {
int m = l + (r - l) / 2;
if (arr[m] == x)
return m;
if (arr[m] < x)
l = m + 1;
else
r = m - 1;
}
return -1;
}
int main()
{
int array[]={25,39,12,85,55,69,40,75};
int grt40[8];
int count=0;
for(int i=0;i<8;i++)
{
if(array[i]>40)
{
grt40[count]=array[i];
count++;
}
}
cout<<"Output for Task 2"<<endl;
cout<<"Numbers greater than 40 are ";
for(int i=0;i<count;i++)
{
cout<<grt40[i]<<" ";
}
cout<<"\n\nOutput for Task 3";
cout<<endl<<"My vector is :"<<endl;
for(int i=0;i<8;i++)
{
cout<<array[i]<<" ";
}
cout<<endl<<"My sorted vector is : "<<endl;
int key, j;
for(int i = 1; i<8; i++)
{
key = array[i];//take value
j = i;
while(j > 0 && array[j-1]>key)
{
array[j] = array[j-1];
j--;
}
array[j] = key; //insert in right place
}
for(int i=0;i<8;i++)
{
cout<<array[i]<<" ";
}
cout<<"\n\nOutput for Task 4";
cout<<endl<<"Find 5";
int index1 = binarySearch (array, 0, 8-1, 5);
if(index1 == -1)
cout<<endl<<"5 cannot be found!";
else
cout<<endl<<"5 can be found at index : "<<
index1;
cout<<endl<<"Find 75";
int index2 = binarySearch (array, 0, 8-1, 75);
if(index2 == -1)
cout<<endl<<"75 cannot be found!";
else
cout<<endl<<"75 can be found at index : "<<
index2;
cout<<"\n\nOutput for Task 5";
cout<<endl<<"Five largest elements are : ";
for(int i=7;i>=7-5;i--)
{
cout<<array[i]<<" ";
}
return 0;
}
Output:

Hope this helps!!
please help urgent c++ Use the vector/array below for the following tasks: {25, 39, 12, 85,...
C++ Sorting and Searching 1. Mark the following statements as true or false. a. A sequential search of a list assumes that the list elements are sorted in ascending order. b. A binary search of a list assumes that the list is sorted. 2. Consider the following list: 63 45 32 98 46 57 28 100 Using a sequential search, how many comparisons are required to determine whether the following items are in the list or not? (Recall that comparisons...
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...
The ExceptionLab class provided: – Creates an array of 100
elements and fills it with random numbers from 1 to 100. – It asks
the user for an index value between 0 and 99. – Prints the element
at that position. – If a number > 99 is entered by the user, the
class will abort with an ArrayIndexOutOfBoundsException • Modify
the ExceptionLab: – Add a try-catch clause which intercepts the
ArrayIndexOutOfBounds and prints the message: Index value cannot be...
Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D array of integers which is 10x10. 2. Prints out the contents of the 2D array after assigning the data to make sure correct data was assigned. 3. Figures out and prints out the square root of the sum of ALL the elements in the 2D array. 4. Figures out and prints out the average of ALL THE ELEMENTS in the 2D array. 5. Figures...
Please use C++ Initialize the 2-D array of integers detailed below. { 25, 50, 75, 100, 125 }, { 50, 100, 150, 200, 250}, { 75, 150, 225, 300, 375}, { 100, 200, 300, 400, 500}, { 125, 250, 375, 500, 625 }, Traverse and output array elements for the 2D array above in reverse order. Starting with 625, 500, 375, 250, etc…. Directly Access and output 225 and 400 from the 2D array. DO NOT Traverse 2D Array
NEED C++ HELP. PLEASE FOLLOW DIRECTIONS
CAREFULLY:
Use a 1 dimensional array object to create a 2 dimensional table
object. Then modify to create a triangular table.
Example:
Objective -> create an array of dynamic objects of
RowAray inside Table. See below
for RowAray.h, Table.h, Then
create a triangular table like the example above.
Fill each cell with random 2 digit integers.
The Example Table above has 8 columns of RowAray objects each
filled with 6 rows of random 2...
C++ programming language POINTERS Write a program that dynamically allocates an array, on the Heap, large enough to hold 200 test scores between 55 and 99 -- using a Random Number generator to populate the array. Then do the following: 1) Sort scores in ascending order. 2) List your scores in rows of ten(10) values. 3) Calculate the Mean for the distribution. 4) Calculate the Variance for the distribution. 5) Calculate the Median for the distribution. 6) Calculate the Mode...
please check my answers if it wrong answer me
a) (25 points) Suppose that you are asked to analyze the performance. Algorithms operate on 1D array of size nor 2D a of the algorithms below, write down the Big O or order of grow terms of n. If the algorithm cannot be applied to the array, write 0(1), O(log n), O(n), O(n logn), 90), O(n"), O(n!). The will only be given for reasonable Big O answers. & algorithms for their...
Just Q3 and Q4
Q1] Write a C function to implement the binary search algorithm over an array of integer numbers and size n. The function should return the index of the search key if the search key exists and return - 1 if the search key doesn't exist. [10 Points] Q2] Write a C function to implement the selection sort algorithm, to sort an array of float values and size n. The function should sort the array in ascending...
Write a C program to assign natural numbers 1 to 100 into a one-dimensional integer array. Display all the values in the array on the screen. For each number in the array, determine if the number contains digit 7 or is divisible by 7. Display all those numbers on the screen. Original array: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27...