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) The appropriate destructor will be provided automatically by the compiler.
(c) It will not contain calls to delete.
(d) It might contain calls to delete, but might not.

Correct answer is (d)

Your score on this question is: 0.00

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



2.

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 copying the data from A to B
(b) In the return operation
(c) In the creation of the local variable B
(d) In passing the parameter

Correct answer is (b)

Your score on this question is: 0.00

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



3.
If a user-defined class overloads both operator== and operator<, which other operator, if any, is implicitly overloaded as a consequence?

(a) operator!=
(b) operator<=
(c) operator<<
(d) No other operator

Correct answer is (d)

Your score on this question is: 0.00

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



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

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

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



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

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

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



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 a copy constructor is to

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

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



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 assignment operator
(b) The default constructor
(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 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) Default values are not allowed in constructors.
(b) Nothing
(c) The second constructor conflicts with the first.
(d) There is no reasonable way to construct a real from two real parameters.

Correct answer is (c)

Your score on this question is: 0.00

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



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

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

Correct answer is (b)

Your score on this question is: 0.00

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



Go to top of assessment.

Total score: 50.00