Question: Update Assignment from codes below Main Function: Declare and fill an array with 1000 random integers between 1 - 1000. You will pass the array
Update Assignment from codes below
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 even numbers in the array.
Function 4:
Create a function that will allow the user to enter an integer value to search. Program will implement a Binary Search algorithm to perform the search. Program will output if integer value is found and the location of the integer in the array or The program will output value is not in array. (It is ok for now for duplicate if duplicate values exist in the array. The goal is to correct implement the Binary Search and return a singular location of where the value exists in the array.)
Function 5:
Create a function that will output the highest value in the array.
Function 6:
Create a function that will output the lowest value in the array.
Function 7:
Implement a Bubble Sort algorithm. Sort the elements in the array and output in descending order.
Here is the code from the previous program.
#include
#include
#include
using namespace std;
void printmenu()
{
cout<<"Enter 1. Output all integer values" << endl;
cout<<"Enter 2. Sum all odd numbers" << endl;
cout<<"Enter 3. Sum all even numbers" << endl;
cout<<"Enter 4. Enter a search value" << endl;
cout<<"Enter 5: Output the Highest Number" << endl;
cout<<"Enter 6: Output the Lowest Number" << endl;
cout<<"Enter 7: Sort the items in the array and Output in Descending Order" << endl;
cout<<"Enter 8: Output First Number in the Array" << endl ;
cout<<"Enter 9: Output Last Number in the Array" << endl;
cout<<"Enter 10: To Exit Program"<< endl;
}
void printarray(int *array, int size)
{
int i;
for(i=0; i< size;i++ )
{
cout << " Element["<
if(i%20 == 0)
cout< } } //function declarations void sum_odd(int *array, int size) { int result=0, i; for(i=0;i { //finding the sum of odd numbers if(array[i]%2 != 0) result+=array[i]; } cout<<" Sum of odd numbers:" << result; } void sum_even(int *array, int size) { int result=0, i; for(i=0;i //finding the sum of even numbers { if(array[i]%2 == 0) result+=array[i]; } cout<<"Sum of even numbers:" << result; } // This function will search for an element and display index position if found void search(int *array, int size) { int inp, i; cout<<"Please Enter a search value:"; cin >>inp; int flag = 0; for(i=0;i< size;i++ ) { if(array[i] == inp) { cout<< inp<< " is found at index position: Element["<< i <<"]"< flag = 1; } } if (flag == 0) { cout<< inp<< " is not in the array."< } } void large(int *array, int size) { int result = array[0]; for(int i=1;i { if(array[i] > result) result = array[i]; } cout << "The Highest number is: " << result << endl; } void small(int *array, int size) { int result = array[0]; for(int i=1;i { if(array[i] < result) result = array[i]; } cout << "The lowest number is: " << result << endl; } void bubblesort(int *arr, int n) { int i, j, temp; for (i = 0; i < n-1; i++) for (j = 0; j < n-i-1; j++) if (arr[j] < arr[j+1]) { temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] =temp; } printarray(arr, n); } int main() { int inp, i, num = 1000; int array[num],result; //generate random numbers srand((unsigned)time(0)); for(i=0;i { array[i]= rand() % 1000; } printmenu(); cout << "Please Enter Option:"; cin >> inp;//let user to put their input while(inp !=10 ) { switch(inp) { case 1: printarray(array, num); break; case 2: sum_odd(array,num); break; case 3: sum_even(array,num); break; case 4: search(array,num); break; case 5: large(array,num); break; case 6: small(array, num); break; case 7: bubblesort(array, num); break; case 8: cout << "First number in array:" << array[0]; break; case 9: cout << "Last number in array:" << array[num-1]; break; case 10: break; default: cout<<" **Error:Invalid Choice**"< } cout<< endl; printmenu(); cout << " Please Enter Option:"; cin >> inp; } cout<<" **End of program, Good Bye!!**"< return 0; } Please post the correct solution for this question. Please follow the guidelines thoroghly and update it.(c++). Thanks,
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
