Exercise 3: Finding Index of Smallest Value

This exercise, requires you to find the index of the smallest value in an array using the concept of Templates

We'll cover the following

Problem Statement

In the code widget below, two functions both called index_of_smallest are declared. One finds minimum value index of an int type array and the other for double type.

In this exercise, you need to define a Template Class type function index_of_smallest that will generalize the function such that it finds minimum value index for both int and double type array input values.

IMPORTANT NOTE: Remove both the int and double type index_of_smallest functions and then write the code for the Template Class type index_of_smallest function there.

The function code for finding the index of the smallest value in an array:

  • Takes three values:
    • Array of values
    • Start index value
    • Size of array

Down below is what the expected output should look like.

Input 1:

int array []= {2,3,4,8,1} 

Input 2:

double array[] = {2.5,3.3,1.5,8.2,4.2}

Expected Output 1:

Index of smallest value is: 4

Expected Output 2:

Index of smallest value is: 2

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy