Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. What should you list in the precondition of a template function? a. what happ

ID: 3581584 • Letter: 1

Question

1. What should you list in the precondition of a template function?

            a. what happens after the function is executed.

            b. any functionality that the instantiating class must implement (like < )

            c. what must be true before the function executes.

            d. all of the above.

            e. A & B

            f. B & C

2. Given that you have two versions of a function that are the same except that one expects some integer parameters, and the other expects a float and an integer parameter, which parameters would you change a T in order to make this a template function.

            a. The parameter that always stays an integer.

            b. The parameter that is an integer in one function and a float in the other function.

            c. Both parameters change.

            d. neither parameter changes.

3. Why can you not use the swap template function to swap two complete arrays?

template <class T>

void swap (T& left, T& right){

T tmp = left; left = right; right = tmp;}

            a. You cannot pass an array to a function.

            b. The swap function does not return anything

            c. the = operator does not work for an array.

            d. tmp should be an integer.

Explanation / Answer

1. What should you list in the precondition of a template function?

c. what must be true before the function executes.

2. Given that you have two versions of a function that are the same except that one expects some integer parameters, and the other expects a float and an integer parameter, which parameters would you change a T in order to make this a template function.

b. The parameter that is an integer in one function and a float in the other function.

3. Why can you not use the swap template function to swap two complete arrays?

template <class T>

void swap (T& left, T& right){

T tmp = left; left = right; right = tmp;}

c. the = operator does not work for an array.