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) In this case, no destructor is required for class Thing.
(b) It will not contain calls to delete.
(c) The appropriate destructor will be provided automatically by the compiler.
(d) It might contain calls to delete, but might not.

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



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

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

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



3.
A user-defined class Thing that has value semantics behaves very much like

(a) a pointer to a built-in type such as int* or float*
(b) an expression of arithmetic
(c) a built-in type such as int or float
(d) any class that has a default constructor

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



4.
What is the difference between a C++ class and a C++ struct ?

(a) The default access in a class is private and in a struct is public.
(b) There is no difference.
(c) Structs cannot contain function members.
(d) The default access in a class is public and in a struct is private.

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



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

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

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



6.
The purpose of a constructor is to

(a) handle assignments between instances of the class
(b) clean up memory when an instance goes out of scope
(c) prevent memory leaks
(d) initialize data members of a class properly after space has been allocated

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.
The purpose of the assignment operator is to

(a) prevent memory leaks
(b) be used internally in an object's copy constructor
(c) initialize data members when an instance is first created
(d) provide for proper assignment between 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



8.

Assume that Thing is a user-defined class, and consider the following code fragment, where B is an instance of Thing.

      Thing  A = B

Which of the following is a class member that is used in this code fragment?



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

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



9.

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



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) Function objects execute faster on some machines.
(c) The compiler can perform type checking with function objects.
(d) Functions are allowed to be recursive.

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: 100.00