Question: Define constants for the following: ( all constants should be int ) array size - value is 1 0 0 minimum value to initialize array
Define constants for the following: all constants should be int
array size value is minimum value to initialize array with value is maximum value to initialize array with value is menu options for the following:
Display all array contentsDisplay lower valuesDisplay higher valuesDisplay averageQuit program
Define prototypes for the following functions:
initializeArray: This function does not return a value and accepts parameters the array and its size. It initializes the array with random numbers between and getMenuChoice: This function does not accept any parameters and returns an int. It displays the menu and returns the user's menu choice.processMenuChoice: This function accepts parameters the user's choice, the array, and its size. The function does not return a value. It calls the appropriate function based on the choice parameter.displayArray: This function accepts parameters the array and its size. The function displays each element of the array to the console.displayLower: This function accepts parameters the array, its size, and a number. The function display all elements of the array that are less than its number parameter.displayHigher: This function accepts parameters the array, its size, and a number. The function display all elements of the array that are higher than its number parameter.displayAverage: This function accepts parameters the array and its size. It calculates and displays the average of all elements in the array.You will need the following tool functions from tools.cpp:
getIntgetBoundedIntflushInputrandomInt
Main implementation
Define an array of integers and a size of
int arrayARRAYSIZE;
Initialize the array, call initializeArrayCreate a dowhiletrue loop. Within the loop, do the following
Display the menu and get the user's choice, call getMenuChoiceBreak out of the loop if the choice is quitProcess the menu choice call processMenuChoice passing the choice, array, and array size
InitializeArray implementation
Create a for loop that walks through each element of the array. For example:
for int index ; index size; index
Within the loop, initialize the array element. For example:
arrayindex randomIntMINVALUE, MAXVALUE;
getMenuChoice implementation
Create cout statements that display the menuget and return the user's choice call the getBoundedInt function
processMenuChoice implementation
Define a local int variable that will be used to get a number from the userCreate a switch statement with a case statement for each menu option
display all call the displayArray function passing the array and size parametersdisplay lower:
prompt the user to enter a number call getBoundedIntcall the displayLower function passing the array, size, and number arguments
display higher:
prompt the user to enter a number call getBoundedIntcall the displayHigher function passing the array, size, and number arguments
average
call the displayAverage function passing the array and size arguments
quit
break out of the switch statement
default
display an error message indicating invalid menu choice
displayArray implementation
Create a for loop that walks through each element of the array similar to the for loop used in the initalizeArray function.
output the array element: cout setw arrayindex;Output a newline if the current index is if index
displayLower Implementation
Create a local variable that will be used to hold the number of numbers displayed. Initialize it to Create a for loop that walks through each element of the array
If number is the current array element then
display the array elementincrement the number of numbers displayed variableOutput a new line character if elements have been displayed on the current line. For example: if numDisplayed
displayHigher implementation
The implementation of this function is exactly like the displayLower function. The only difference is the expression within the if statement that compares the number to the current array element. The if statement should be: if number is the current array element
displayAverage implementation
Create the following local variables
int totaldouble average
Create a for loop that walks through each element of the array
Add the array element to the total
Calculate and return the average total size. Don't forget to cast total to double before performing the division.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
