View Assessment Result: Multiple Choice Quiz 4



Your performance was as follows:

1.
The purpose of function templates is to

(a) replace generic void* pointers in C
(b) increase the efficiency of various algorithms
(c) easily specify a family of operationally equivalent functions
(d) help the type-checker search for errors

Correct answer is (c)

Your score on this question is: 10.00

Feedback:
   See section 1.4.1 of the course notes.
   (c) No Feedback



2.
What is the purpose of class templates?

(a) To easily specify a group of related classes
(b) To improve the portability of code
(c) To avoid the use of dangerous pointers
(d) To increase the efficiency of the class methods

Correct answer is (a)

Your score on this question is: 10.00

Feedback:
   See section 1.4.1 of the course notes.
   (a) No Feedback



3.
What is the purpose of the keyword typename?

(a) To increase the efficiency of template compilation
(b) To point out to the compiler that whatever follows is the name of a type
(c) The same purpose as that of typedef
(d) To denote a generic type

Correct answer is (b)

Your score on this question is: 10.00

Feedback:
   See section 1.4.1 of the course notes.
   (b) No Feedback



4.

Consider the following template specification.

      template<int n>  ...

In use, the template parameter n can be replaced by



(a) int values and int containers only
(b) arithmetic type values only
(c) any type of value
(d) int values only

Correct answer is (d)

Your score on this question is: 10.00

Feedback:
   See section 1.4.1 of the course notes.
   (d) No Feedback



5.

Consider the following templated array copy function and arrays.

      template<class T>  void  copy( T a[], T b[], int n ) {
          for(int i = 0; i < n; i++ ) a[i] = b[i];
      }
      char   C[10], CC[10];
      int    I[10];
      float  F[10];

Which of the following calls to copy would produce a compile time error?



(a) copy( I, (int*)F, 10 );
(b) copy( I, F, 10 );
(c) copy( I, I, 10 );
(d) copy( C, CC, 10 );

Correct answer is (b)

Your score on this question is: 10.00

Feedback:
   See section 1.4.1 of the course notes.
   (b) No Feedback



6.

Consider the following templated array copy function and arrays.

      template<class S, class T>  void  copy( S a[], T b[], int n ) {
          for(int i = 0; i < n; i++ ) a[i] = b[i];
      }
      char   C[10];
      int    I[10];
      float  F[10];

Which of the following calls to copy would produce a compile time error?

  1. copy( F, C, 10 );
  2. copy( I, C, 10 );
  3. copy( C, F, 10 );


(a) None
(b) I
(c) II
(d) III

Correct answer is (a)

Your score on this question is: 10.00

Feedback:
   See section 1.4.1 of the course notes.
   (a) No Feedback



7.
Which of the following is true about the run-time efficiency of using templated functions versus using nontemplated functions?

(a) The run-time efficiency is better for templated functions.
(b) The run-time efficiency is the same for both.
(c) The run-time efficiency is slightly worse for templated functions.
(d) The run-time efficiency is much worse than for templated functions.

Correct answer is (b)

Your score on this question is: 10.00

Feedback:
   See section 1.4.1 of the course notes.
   (b) No Feedback



8.

What, if anything, is wrong with the following function declaration?

      template<class A, class B>  A  f( B x );


(a) The parameter should be passed by reference.
(b) Nothing
(c) The compiler cannot determine B when f is called.
(d) The compiler cannot determine A when f is called.

Correct answer is (d)

Your score on this question is: 10.00

Feedback:
   See section 1.4.1 of the course notes.
   (d) No Feedback



9.

If templates were removed from C++, which of the following would be true?

  1. Some algorithms could no longer be implemented.
  2. Any particular algorithm could still be implemented, but often less elegantly.
  3. Any particular algorithm could still be implemented, but the efficiency would often be catastrophically worse.


(a) II only
(b) None
(c) II and III
(d) I only

Correct answer is (b)

Your score on this question is: 10.00

Feedback:
   See section 1.4.1 of the course notes.
   (b) No Feedback



10.

Consider the following templated function.

   template<class T> T Apply( T x, T (*ff)(T) ){ return ff(x); }

Which of the following is true concerning its use?



(a) The input function can be arbitrary, and the templated function returns the result of calling the second input on the first input.
(b) The input function can be arbitrary, and the templated function returns a pointer to the result of calling the second input on the first input.
(c) The input function must return the same type as its argument, and the templated function returns the result of calling the second input on the first input.
(d) The input function must return the same type as its argument, and the templated function returns a pointer to the result of calling the second input on the first input.

Correct answer is (c)

Your score on this question is: 10.00

Feedback:
   See section 1.4.1 of the course notes.
   (c) No Feedback



Go to top of assessment.

Total score: 100.00