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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
//preprocessor directives
#include <iostream>
//namespace statement
using namespace std;
//function prototypes
void getData(float arrayNums[]);
void calcFunc(float arrayNums[], float& sum);
void printFunc(float sum);
void calcSmall(float arrayNums[], float& small);
void printSmall(float small);
void calcLargest(float arrayNums[], float& largest);
void printLargest(float largest);
//main function
int main(){
//declare variables arrayNums[10], sum, small
float arrayNums[10], sum, small, largest;
//functioncalls
getData(arrayNums);
calcFunc(arrayNums, sum);
printFunc(sum);
calcSmall(arrayNums, small);
printSmall(small);
calcLargest (arrayNums, largest);
printLargest (largest);
//print message, wait for keypress, and end the main func.
system ("pause");
//ends main function
return 0;
}
//getData: gets 10 inputs from user and stores them in "arrayNums[index]
void getData(float arrayNums[]){
//prompt the user to "Enter in 10 values". followed by a linebreak
cout << "Enter in 10 values (press ENTER key after each entry): " << endl;
//for loop: designed to take userinput an store within array, "arrayNums[index]
for (int index = 0; index <10; index= index +1)
//userinputs gets stored in arrayNums[index]
cin >> arrayNums[index];
}
//calcFunc: calculates the sum of the array and solves for the average
void calcFunc(float arrayNums[], float& sum){
//give sum the value of "0"
sum = 0;
//for loop: designed to calculate the average the sum of the array
for (int index = 0; index <10; index = index +1)
//calculation for sum, used to conclude the average
sum = sum +arrayNums[index] / 10;
}
//printFunc: prints the sum average of the array
void printFunc(float sum){
//print on screen, "The average value of the array is: " followed by a linebreak
cout << "The average value of the array is: " << endl;
//print on screen, "sum"
cout << sum << endl;
}
//calcSmall: Calculates the smalles value in the array
void calcSmall(float arrayNums[], float& small){
//give small the value of "10"
small =0;
//for loop: designed to calculate the smallest value in the array
for (int index = 0; index < 10; index = index +1)
//assign small the value of arrayNums[7]
small = arrayNums[0];
}
//printSmall: Prints the smallest value of the array
void printSmall(float small){
//print on screen, "the smallest value of the array is: " follwed by a line break
cout << "The smallest value of the array is: " << endl;
//print on screen, "small" followed by a line break
cout << small << endl;
}
//calcLargest: calculates the largest even number in the array
void calcLargest(float arrayNums[], float& largest){
//assign largest the value of "-1"
largest = -1;
//for loop: designed to check the elements in the array, thus determing the largest even number
for (int index = 0; index < 10; index = index +1);
// if statement, used to check and see which of the elements in arrayNums[] preceed the highest even number
if (arrayNums[0,1,2,3,4,5,6,7,8,9] > largest);
//assign largest the value of arraynums
largest = arrayNums[0,1,2,3,4,5,6,7,8,9];
}
//printLargest: prints the largest even number in the array
void printLargest(float largest){
//print on screen, "The largest even number un the array is: " followed by a endline
cout << "The largest even number in the array is: " <<endl;
//print on screen "largest", followed by a linebreak.
cout << largest << endl;
}[code]
| |