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

  1. 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.

  2. 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?

  3. 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

  4. Describe one purpose of a member initialization list for a derived class.

  5. When is it appropriate to use a container class of pointers to objects (rather than a container class of actual objects)?

  6. 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

  7. Describe the difference between a public base class and a private base class.

  8. 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;

  1. What C++ syntax is used to declare that a class B is derived from class A?

  2. If a class B is derived from A, then which of the following terms describes A?

  3. Using the variable declarations at the top of this section, which of the following assignment statements are legal?

  4. Consider the assignment statement a=b; (with the variable declarations at the top of this section). Which answer is true?

  5. Consider the assignment statement b=a; (with the variable declarations at the top of this section). Which answer is true?

  6. What is the term used to describe the situation when a derived class provides a function already provided in the base class?

  7. 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?

  8. 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?

    Multiple Choice
    Section 14.3
    Using Derived Classes
    for ADTs

  9. Suppose you were going to quickly implement a Stack class. What class would be the best base class?

  10. 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?


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