/*Lawrence Martinez Lab#1 Write a program that 1.reads in the size of an array of integers from the keyboard, 2.reads in an array of numbers from the keyboard, 3.displays all of the numbers above the average */ #includevoid DisplayIntro() { cout << "Lawrence Martinez\nCs245 Lab#1"; cout << "\n\nWrite a program that"; cout << "\n\t1.reads in the size of an array of integers from the keyboard,"; cout << "\n\t2.reads in an array of numbers from the keyboard,"; cout << "\n\t3.displays all of the numbers above the average."; cout << "\n\n"; } int GetSizeOfArray() /*Purpose: To prompt user to key in size of an array of integers Recieve: NONE Return: int lvalue arraySize which holds the size of the array Input: From keyboard Output: NONE */ { int arraySize; cout << endl << "Please enter the size of array needed:\n"; cin >> arraySize; return arraySize; } int sum = 0; //sum keeps track of running total of all elements //count keeps track of the number of elements inarray void main() //Main program { DisplayIntro(); //Function to display intro int size = GetSizeOfArray(); //Size is initialized to value inputed by user int *arr; //Pointer to an integer array arr = new int [size]; //Allocate the size of array cout << "\nPlease enter an element, followed by ENTER:\n"; for (int i = 0; i < size; i++) //Prompt user for element input { cin >> arr[i]; sum += arr[i]; //add each array element to sum } double average; //declaration of object average average = double (sum / size); //Definition of object average cout << "The average of all the elements is: " << average; //cout average //to user cout << "\nThe elements greater than the average are: "; for ( int k = 0 ; k < size ; k++ ) { //Display output to user if (arr[k] > average) //Test if elements are > the average cout << arr[k] << ", "; //Display elements < than average } }