01: #include <iostream>
02: using namespace std;
03: /**
04: Reads data into an array.
05: @param a the array to fill
06: @param a_capacity the maximum size of a
07: @param a_size filled with the size of a after reading
08: */
09: void read_data(double a[], int a_capacity, int& a_size)
10: { a_size = 0;
11: double x;
12: while (a_size < a_capacity && (cin >> x))
13: { a[a_size] = x;
14: a_size++;
15: }
16: }
17: /**
18: Computes the maximum value in an array
19: @param a the array
20: @param a_size the number of values in a
21: */
22: double maximum(const double a[], int a_size)
23: { if (a_size == 0) return 0;
24: double highest = a[0];
25: for (int i = 1; i < a_size; i++)
26: if (a[i] > highest)
27: highest = a[i];
28: return highest;
29: }
30:
31: int main()
32: { const int SALARIES_CAPACITY = 100;
33: double salaries[SALARIES_CAPACITY];
34: int salaries_size = 0;
35:
36: cout << "Please enter all salary data: ";
37: read_data(salaries, SALARIES_CAPACITY, salaries_size);
38:
39: if (salaries_size == SALARIES_CAPACITY && !cin.fail())
40: cout << "Sorry--extra data ignored\n";
41:
42: double maxsal = maximum(salaries, salaries_size);
43: cout << "The maximum salary is " << maxsal << "\n";
44: return 0;
45: }