Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Task 1: Main Function: Declare and fill an array with 1000 random integers betwe

ID: 3590418 • Letter: T

Question

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 even numbers in the array Function 4 Create a function that will allow the user to enter an integer value to 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: ("value is not in array should not be printed more than once.") Function 5 Create a function that wll outout the highest value in the array Function 6 Create a function that will output the lowest value in the array. implement a Bubble Sort algorthm. Sort the order elements in the array and output in descending

Explanation / Answer

// c++ code

#include <iostream>

#include <stdlib.h>

using namespace std;

void showChoices();

void even_number(int[],int);

void odd_number(int[],int);

void highest_val(int[],int);

void lowest_val(int[],int);

void bubble_sort(int[],int);

void first_num(int[]);

void last_num(int[],int);

int main()

{

int size = 1000,i;

int choice;

// declare integer array

int array[size];

int search;

// iterate over the array and fill with random numbers in range 1-1000

for(int i=0; i<20; i++)

{

array[i] = (rand()%1000)+1;

cout << array[i] << endl;

}

do

{

showChoices();

cin >> choice;

switch (choice)

{

case 1:

odd_number(array, size);

break;

case 2:

even_number(array, size);

break;

case 3:

highest_val(array,size);

break;

case 4:

lowest_val(array,size);

break;

case 5:

bubble_sort(array,size);

break;

case 6:

first_num(array);

break;

case 7:

last_num(array,size);

break;

case 8:

break;

default:

cout << "Invalid input" << endl;

}

}while (choice != 8);

return 0;

}

void showChoices()

{

cout << "MENU" << endl;

cout << "1: sum all odd numbers" << endl;

cout << "2: sum all even numbers " << endl;

cout << "3: output highest number " << endl;

cout << "4: output lowest number " << endl;

cout << "5: Bubble sort in Descending order " << endl;

cout << "6: first number in array " << endl;

cout << "7: last number in array " << endl;

cout << "8: Exit " << endl;

cout << "Enter your choice :";

}

void even_number(int arr[],int size_of_array)

{

int number;

int sum=0;

cout << " even numbers in array are: ";

for(number = 0;number < size_of_array; number++)

if(arr[number] % 2 ==0)

{

cout << arr[number]<< " ";

sum = sum + arr[number];

}

cout<<" sum of even numbers is "<<sum;

}

void odd_number(int arr[],int size_of_array)

{

int number;

int sum=0;

cout << " odd numbers in array are: ";

for(number = 0;number < size_of_array; number++)

if(arr[number] % 2 !=0)

{

cout << arr[number]<< " ";

sum = sum + arr[number];

}

cout<<" sum of odd numbers is "<<sum;

}

void highest_val(int arr[], int size)

{

int i;

int highest=arr[0];

// Loop to store largest number to arr[0]

for(i = 1;i < size; i++)

{

// Change < to > if you want to find the smallest element

if(highest < arr[i])

highest = arr[i];

}

cout << " Highest element = " << highest;

}

void lowest_val(int arr[], int size)

{

int i;

int low=arr[0];

// Loop to store largest number to arr[0]

for(i = 2;i <= size; i++)

{

// Change < to > if you want to find the smallest element

if(low > arr[i])

low = arr[i];

}

cout << " Lowest element = " << low;

}

void bubble_sort(int arr[],int size)

{

int temp,i,j;

for(i=0;i<size;i++)

{

for(j=0;j<size-i-1;j++)

{

if(arr[j]<arr[j+1]) //just replace < by > for ascending order.

{

temp=arr[j];

arr[j]=arr[j+1];

arr[j+1]=temp;

}

  

}

}

cout<<" Descending order is:";

for(i=0;i<size;i++)

{

cout<<" "<<arr[i];

}

}

void first_num(int arr[])

{

cout<<" first number in array is "<<arr[0];

}

void last_num(int arr[],int size)

{

cout<<" Last number in array is "<<arr[size-1];

}

output: for 20 random numbers from range of 1-1000

384
887
778
916
794
336
387
493
650
422
363
28
691
60
764
927
541
427
173
737
MENU
1: sum all odd numbers
2: sum all even numbers
3: output highest number
4: output lowest number
5: Bubble sort in Descending order
6: first number in array
7: last number in array
8: Exit
Enter your choice :5

Descending order is: 927 916 887 794 778 764 737 691 650 541 493 427 422 387 384 363 336 173 60 28MENU
1: sum all odd numbers
2: sum all even numbers
3: output highest number
4: output lowest number
5: Bubble sort in Descending order
6: first number in array
7: last number in array
8: Exit
Enter your choice :2

even numbers in array are: 916 794 778 764 650 422 384 336 60 28
sum of even numbers is 5132MENU
1: sum all odd numbers
2: sum all even numbers
3: output highest number
4: output lowest number
5: Bubble sort in Descending order
6: first number in array
7: last number in array
8: Exit
Enter your choice :8

Exit code: 0 (normal program termination)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote