Sdut Object-Oriented Programming machine Exercise 1 (function overloading)
Object-Oriented Programming machine Exercise 1 (function overloading) Time Limit: 1000 MS Memory limit: 65536 K The topic description uses array and function overload to calculate the maximum number of five numbers (considering integers, single precision, and long integers respectively ). Enter five int integers, five float integers, and five long integers. The output outputs the maximum values of five int integers, the maximum values of five float integers, and the maximum values of five long integers. Sample Input
11 22 666 44 5511.11 22.22 33.33 888.88 55.551234567 222222 333333 444444 555555
Sample output
666888.881234567
# Include
Using namespace std; // evaluate the maximum number of five integers int max (int a []) {int I; int m = 0; for (I = 0; I <5; I ++) {if (a [I]> m) m = a [I];} return m ;} // evaluate the maximum number of five floating point numbers float max (float a []) {int I; float m = 0.0; for (I = 0; I <5; I ++) {if (a [I]> m) m = a [I];} return m ;}// obtain the maximum long max (long a []) from five long integers. {int I; long m = 0; for (I = 0; I <5; I ++) {if (a [I]> m) m = a [I];} return m;} // main function int main () {int j; int x [5]; float y [5]; long z [5]; // input for (j = 0; j <5; j ++) cin> x [j]; for (j = 0; j <5; j ++) cin> y [j]; for (j = 0; j <5; j ++) cin> z [j]; // output int e; e = max (x); cout <e <endl; float f; f = max (y); cout <f <endl; long g; g = max (z); cout <g <endl; return 0 ;}