View Assessment Result: Multiple Choice Quiz 3



Your performance was as follows:

1.
To which of the following is object-based programming ideally suited?

(a) Encapsulation
(b) Implementing simple monolithic programs
(c) Providing elegant mechanisms for code reuse
(d) Attaining the highest possible efficiency

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



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



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

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

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



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

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.
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: 10.00

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



6.
The purpose of a constructor is to

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

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



7.
The purpose of the assignment operator is to

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

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

      class  RealNumber {
            ...
            private:
                    RealNumber(void) {}
      };

Which of the following is true about such an implementation?



(a) Since the class defines a private constructor, it cannot define any public constructors.
(b) It exhibits good general defensive programming by using private constructors.
(c) All RealNumber objects will be read-only.
(d) It will be impossible to place RealNumber objects into a container.

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.

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

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



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

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

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



Go to top of assessment.

Total score: 90.00