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
|
#include <iostream>
using namespace std;
int array [5];
int size = 5;
void input (int num);
void display (int num);
int statistics ( int &max, int &min, int &avg, int &sum);
int countNum (int &count, int &match, int num);
main () {
int num, min, max, avg, sum, count, match, seek;
input (num);
display (num);
statistics (max, min, avg, sum);
cout << "The min is: " << min << endl;
cout << "The max is: " << max << endl;
cout << "The avg is: " << avg << endl;
cout << "The sum is: " << sum << endl;
cout << "What number would you like to count? ";
cin >> match;
countNum (count, match, num);
cout << count << endl;
}
void input (int num) {
for (int num = 0; num < size; num++) {
cout << "Enter element " << num+1 << ": ";
cin >> array [num];
}
}
void display (int num) {
cout << "You entered: \n";
cout << "Postion \t Value \n";
cout << "--------------------" << endl;
for (int num = 0; num < size; num++) {
cout << num+1 << "\t \t" << array [num] << endl;
}
}
int statistics (int &max, int &min, int &avg, int &sum) {
max = array [0];
min = array [0];
avg = array [0];
sum = array [0];
for (int num = 0; num <size; num++) {
if (min > array[num])
min = array[num];
else if ( max < array [num])
max = array [num];
sum += array [num+1];
avg=sum/size;
}
}
int countNum (int &count, int &match, int num) {
count = 0;
for (num = 0; num < size; ++num) {
if (array[num] == match)
++count;
}
}
|