Challenge 1: Finding Max in an Array
In this exercise you have to use template type to generalize the method used to find max element in an array.
We'll cover the following...
Problem statement
In the code widget below, two methods both called array_max are declared. One finds max value for int type inputs and the other for double type.
In this exercise, you need to define a Generic Class type method called array_max that will generalize the method such that it finds maximum value for both int and double type array input values.
IMPORTANT NOTE: Remove both the
intanddoubletypearray_maxmethods and then write the code for the Generic Class typearray_maxmethod there.
Your generic class type array_max method code should find the maximum element in an array using generics.
- Method will take the array and array size as parameters.
Expected input
Input 1:
If input is:
int arr[] = {2,8,20,3,4};
Input 2:
If input is:
double arr[] = {2.7,3.8,5.5,6.7,9.7}
Expected output
Expected Output 1:
20
Expected Output 2:
9.7