Comp 2673
Spring 2002
Homework 7
Due Wednesday, May 22

  1. (4 pts) What is the difference between a function template and a template function? Which is more like a blueprint or stencil?
  2. (3 pts) How are function templates similar to/different from function overloading?
  3. (3 pts) Multiple choice:
    1. Select the false statement. Template functions
    (a) are overloaded
    (b) are specific instances of a function template
    (c) are members of class templates
    (d) are like stencils
    
    2. If a function template takes in user-defined types and uses operators
       (such as &, +, ==, etc), then overloading those operators is
    (a) required
    (b) only required if there are non-template functions with the same name and different parameters
    (c) not required
    (d) required unless there are non-template functions with the same name and different parameters 
    
    3. Class templates
    (a) may include the statement template< class Type > anywhere.
    (b) must include template< class Type > before the class definition.
    (c) must put template< class Type > inside the class definition.
    (d) have the option of including the statement template< class Type >.
    
  4. (40 pts) Write a function template called sort. It should have a void return value, and should take two parameters: a pointer to the array to be sorted and an int representing the number of elements. Write a program that tests this function template with at least 2 different types of arrays, an array of numbers of a built-in type, and an array of objects of a user-defined class (your choice of what class this is). Test it on enough examples so that you're sure the sorting works properly! Implement quicksort for full credit, and any inferior sort algorithm for 75% credit.