Exercise 1: Finding Max in an Array
This exercise requires you to use template type to generalize the function used to find max element in an array
We'll cover the following
Problem Statement
In the code widget below, two functions 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 Template Class type function called array_max
that will generalize the function such that it finds maximum value for both int
and double
type array input values.
IMPORTANT NOTE: Remove both the
int
anddouble
typearray_max
functions and then write the code for the Template Class typearray_max
function there.
Your template class type array_max
function code should find the maximum element in an array using
- Function will take the array and array size as parameters.
Down below is what the expected output should look like.
Input 1:
If input is:
int arr[] = {2,8,20,3,2};
Input 2:
If input is:
double arr[] = {2.8,20.3,20.4,15.5}
Expected Output 1:
20
Expected Output 2:
20.4
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy