Sams Teach Yourself C in 21 Days

(singke) #1
Working with C++ Classes and Objects 701

BD3



  1. If a guppyinherits from a fishclass, then the fishis said to be the
    a. base class
    b. subclass
    c. Neither the base class nor the subclass

  2. What would be the header line for the declaration of the guppyclass used in quiz
    question 4?

  3. Which executes first, a base class’s constructor or the sub class’s constructor?

  4. Which executes first, a base class’s destructor or the sub class’s destructor?


Exercises ........................................................................................................


  1. Create a class that will hold a point. Call the class point. This should contain an x
    value and a yvalue that are both private. Use data access members.

  2. Create a class for a circle. The data members can be the circle’s center point and
    the circle’s radius. Use the point class from exercise 1 to create the point’s center
    data member.

  3. Create a constructor for the circle class in exercise 2. Use zeros as default parame-
    ters for the point’s center. Use 1 as the default radius.

  4. Create a public member function that returns the circle’s circumference.

  5. Write the code for the point class presented at the beginning of today’s lesson.

  6. Write the code for the line class presented at the beginning of today’s lesson.

  7. Rewrite the code for the lineclass so that it inherits the point class and extends it
    by also storing a length.

  8. Rewrite Listing B4.3 to work for the studentclass instead of the employeeclass.


38 448201x-Bonus3 8/13/02 11:19 AM Page 701

Free download pdf