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