Sample Data Structures Questions
Chapter 14
Software Reuse with Derived Classes
Data Structures and Other Objects Using C++
by
Michael Main
and
Walter Savitch
Second Edition ISBN 0-201-70297-5, Softcover, 816 pages, 2000
The Purpose of These Questions
These are typical exam questions from Chapter 14 of the textbook. These
exact questions might not be on your exam, but if you research and find
the right answers to these questions, that should be good preparation
for a real exam. (It's also possible that some of this material was
not covered in your class.) At the moment there are
8 short answer questions
and
10 multiple choice questions
in this file.
Short Answers
Short Answers Section 14.1 Derived Classes
|
-
Write one or two sentences to describe
the primary advantage of implementing a derived class. Your answer
should use the word "inherited" at least once.
-
If the programmer doesn't declare any constructors for a derived
class, an automatic default constructor will be provided by the
compiler. What steps will this default constructor carry out?
-
If the programmer doesn't declare a destructor for a derived
class, an automatic destructor will be provided by the compiler.
What steps will this destructor carry out?
Short Answers Section 14.2 An Ecosystem Simulation
|
-
Describe one purpose of a member initialization list for a
derived class.
-
When is it appropriate to use a container class of pointers to
objects (rather than a container class of actual objects)?
-
In the pond life simulation program, the weeds in the pond were
represented by a variable
weeds
with the declaration:
Bag weeds;
The constructor for the Plant class has two arguments: the initial
size of the plant (in ounces) and the growth rate of the plant
(in ounces/week). Write a for-loop that will put pointers to 100
new plants in the weeds bag. Each plant should have an initial size
of 15 ounces, and a growth rate of 2.5 ounces/week.
Short Answers Section 14.3 Using Derived Classes for ADTs
|
-
Describe the difference between a public base class and a private
base class.
-
Suppose that a derived class has a private base class. How
is it possible to
to make some of the inherited members become public?
Multiple Choice
Multiple Choice Section 14.1 Derived Classes
|
Throughout this section,
A is a class and B is
a new class derived from A.
Also, we have these variables:
A a;
B b;
B b1;
B b2;
|
-
What C++ syntax is used to declare that a class B is derived from
class A?
- A. class A derives B { ... };
- B. class B from A { ... };
- C. class B : public A { ... };
- D. class B subclass of A { ... };
-
If a class B is derived from A, then which
of the following terms describes A?
- A. ancestor class.
- B. base class.
- C. parent class.
- D. superclass.
- E. All of the above.
-
Using the variable declarations at the top of this section,
which of the following assignment statements are legal?
- A. a = b;
- B. b = a;
- C. b1 = b2;
- D. Both (A) and (B) are legal, but not (C).
- E. Both (A) and (C) are legal, but not (B).
- F. Both (B) and (C) are legal, but not (A).
-
Consider the assignment statement
a=b;
(with the variable
declarations at the top of this section).
Which answer is true?
- A. The assignment statement is illegal.
- B. The assignment statement activates the A assignment operator.
- C. The assignment statement activates the B assignment operator.
- D. The assignment statement activates both A and B assignment
operators.
-
Consider the assignment statement
b=a;
(with the variable
declarations at the top of this section).
Which answer is true?
- A. The assignment statement is illegal.
- B. The assignment statement activates the A assignment operator.
- C. The assignment statement activates the B assignment operator.
- D. The assignment statement activates both A and B assignment
operators.
-
What is the term used to describe the situation when a derived
class provides a
function already provided in the base class?
- A. Inheriting.
- B. Overriding.
-
Consider the declarations at the top of this section. Suppose there
are two functions: f has an argument of type A and g has an
argument of type B. Which statement is correct?
- A. Both f(b) and g(b) are legal function calls.
- B. f(b) is legal, but g(b) is not legal.
- C. f(b) is not legal, but g(b) is legal.
- D. Neither f(b) nor g(b) is a legal function function call.
-
Consider the declarations at the top of this section. Suppose there
are two functions: f has an argument of type A and g has an
argument of type B. Which statement is correct?
- A. Both f(a) and g(a) are legal function calls.
- B. f(a) is legal, but g(a) is not legal.
- C. f(a) is not legal, but g(a) is legal.
- D. Neither f(a) nor g(a) is a legal function function call.
Multiple Choice Section 14.3 Using Derived Classes for ADTs
|
-
Suppose you were going to quickly implement a Stack class. What
class would be the best base class?
- A. Bag.
- B. List.
- C. Queue.
- D. Table.
-
Suppose you were going to quickly implement a Stack class as a
derived class. Why would it be likely that the base class would be a
private base class?
- A. You would not want to have all of the base classes private member
functions be private member functions of the stack.
- B. You would not want to have all of the base classes private member
functions be public member functions of the stack.
- C. You would not want to have all of the base classes public member
functions be private member functions of the stack.
- D. You would not want to have all of the base classes public member
functions be public member functions of the stack.
Data Structures and Other Objects Using C++
Michael Main
(main@colorado.edu)
and
Walter Savitch
(wsavitch@ucsd.edu)
Thank you for visiting
http://www.cs.colorado.edu/~main/questions/chap14q.html
Copyright © 2000
Addison-Wesley Computer and Engineering Publishing Group