View Assessment Result: Multiple Choice Quiz 3



Your performance was as follows:

1.
Suppose a user-defined class Thing has a simple constructor that does not require any calls to new. Which of the following is true about the destructor?

(a) It will not contain calls to delete.
(b) In this case, no destructor is required for class Thing.
(c) It might contain calls to delete, but might not.
(d) The appropriate destructor will be provided automatically by the compiler.

Correct answer is (c)

Your score on this question is: 10.00

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



2.
What is the most compelling reason for a random number generator to be implemented as a function object?

(a) A random number generator needs to maintain state between uses
(b) Efficiency
(c) The use of a function object can increase the "randomness" of the generator
(d) So that the generator can be seeded

Correct answer is (a)

Your score on this question is: 0.00

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



3.
Of the following methods, which is least important in a user-defined class with value semantics?

(a) The assignment operator
(b) The output operator
(c) A destructor
(d) A copy constructor

Correct answer is (b)

Your score on this question is: 10.00

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



4.

Assume that Thing is a user-defined class, and consider the following function.

Thing  f(Thing& A)  {
  Thing B;
  B.x  =  A.x;
  return B;
}

Where in this code will a copy constructor be used?



(a) In the creation of the local variable B
(b) In the return operation
(c) In copying the data from A to B
(d) In passing the parameter

Correct answer is (b)

Your score on this question is: 10.00

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



5.
In a C++ class, access to data members and function members are typically

(a) both public
(b) public and private, respectively
(c) both private
(d) private and public, respectively

Correct answer is (d)

Your score on this question is: 10.00

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



6.
The purpose of a copy constructor is to

(a) facilitate assignments between instances of the class
(b) initialize memory when an instance is first created
(c) prevent memory leaks
(d) make otherwise identical copies of objects

Correct answer is (d)

Your score on this question is: 10.00

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



7.

Consider the following class outline for a user-defined implementation of real numbers.

      class  RealNumber {
      ...
             RealNumber( float x );
             RealNumber( float x, float y=0 );
      };

What, if anything, is wrong with the outline?



(a) The second constructor conflicts with the first.
(b) Nothing
(c) There is no reasonable way to construct a real from two real parameters.
(d) Default values are not allowed in constructors.

Correct answer is (a)

Your score on this question is: 10.00

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



8.

Consider the class outline below.

      class  Stack {
      ...
             explicit Stack( int n );
      };

What is the purpose of the explicit in this outline?



(a) To make sure that the constructor does not apply to short, only to int
(b) To draw attention to the fact that there is a constructor
(c) To prevent the Stack destructor from damaging the data stored in the stack
(d) To inhibit automatic conversions from an integer to a Stack

Correct answer is (d)

Your score on this question is: 10.00

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



9.
Which of the following statements properly describes the restriction in C++ regarding what a function can return?

(a) Functions cannot be returned, but function objects can be returned.
(b) Function pointers cannot be returned, but function objects can be returned.
(c) Neither function pointers nor function objects can be returned.
(d) Neither functions nor function objects can be returned.

Correct answer is (a)

Your score on this question is: 10.00

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



10.
Which of the following correctly describes the difference between an ordinary function and a function object?

(a) A function object may contain data that persist between calls.
(b) Functions are allowed to be recursive.
(c) The compiler can perform type checking with function objects.
(d) Function objects execute faster on some machines.

Correct answer is (a)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 90.00