Challenge 45

Description

The purpose of this challenge is to use function templates.

Requirements

  1. Write a function template that will calculate the average of an array of integers.
    template <typename T>
    double average(T array[], int size)
    {
      // calculate and return the average
    }
    
  2. Write a function template, void show(…), that will display the values of an array. Elements will be displayed separated by a single space . Set up the template function similar to Step 1
  3. Write a specialization for the show() function from Step 2. This version will be strictly for string types. In this function, each element will be displayed one per line.
  4. In main(), declare three arrays: int idata[10], double ddata[10], string sdata[10]. 
  5. Ask the user to fill in data for each of the arrays.
  6. Show the contents of the int array by calling the show() function
  7. Show the average of the int aray
  8. Show the contents of the double array by calling the show() function
  9. Show the average of the double array
  10. Show the contents of the string array by calling the show() function. Remember to invoke the specialized version.

Sample main()

int main()
{
  int idata[10];
  double ddata[10];
  string sdata[10];

  ///

  return 0;
}

CATALOG ID: CPP-CHAL00045

Print Requirements