Sams Teach Yourself C in 21 Days

(singke) #1
Q Can I use member functions in structures in my C programs?
ANo. Remember that C++ structures are a specialized type of class. Member func-
tions are a part of a class. C does not have a class construct, so you shouldn’t try to
use classes, nor should you try to use member functions.
Q Can I write full-fledged C++ programs using what is covered in this book?
AYou can write complete C++ programs using what was learned in the lessons in
this book; however, you have only learned a few of the basics of C++. If you try to
update or modify existing C++ programs, you may find that they are much more
complex than any you saw here.
Q Can you inherit from more than one base class?
AYes. In C++ you can inherit from multiple base classes. Just as you inherited from
both your mother and your father, a class can have multiple parents. The new sub-
class, then, has characteristics of both of the base classes. It is beyond the scope of
this book to go into more detail on this.

Workshop ............................................................................................................


The Workshop provides quiz questions to help you solidify your understanding of the
material covered and exercises to provide you with experience in using what you’ve
learned. Answers to the quiz are provided in Appendix F.

Quiz ..............................................................................................................


  1. What is the difference between a structure and a class in C++?

  2. Can you assign values to a class?

  3. What is an object?

  4. What does it mean when you instantiate a class?

  5. Which object-oriented programming characteristics do classes use?

  6. Where within your programs can you access a private data member of a class?

  7. Where within your programs can you access a public data member of a class?

  8. When is a constructor executed?

  9. When is a destructor executed?

  10. How is using a class as a data member different from using other types of data?

  11. If a guppyinherits from a fishclass, the guppyis said to be the
    a. base class
    b. subclass
    c. Neither the base class nor the subclass


700 Bonus Day 3

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

Free download pdf