Sams Teach Yourself C++ in 21 Days

(singke) #1
Advanced Inheritance 591

16


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


The Workshop contains quiz questions to help solidify your understanding of the mater-
ial covered and exercises to provide you with experience in using what you’ve learned.
Try to answer the quiz and exercise questions before checking the answers in Appendix
D, and be certain you understand the answers before going to tomorrow’s lesson.

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



  1. How do you establish an is-arelationship?

  2. How do you establish a has-arelationship?

  3. What is the difference between aggregation and delegation?

  4. What is the difference between delegation and implemented in terms of?

  5. What is a friend function?

  6. What is a friend class?

  7. If Dogis a friend of Boy, is Boya friend of Dog?

  8. If Dogis a friend of Boy, and Terrierderives from Dog, is Terriera friend of Boy?

  9. If Dogis a friend of Boyand Boyis a friend of House, is Doga friend of House?

  10. Where must the declaration of a friend function appear?


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



  1. Show the declaration of a class,Animal, that contains a data member that is a
    Stringobject.

  2. Show the declaration of a class,BoundedArray, that is an array.

  3. Show the declaration of a class,Set, that is declared in terms of an array.

  4. Modify Listing 16.1 to provide the Stringclass with an extraction operator (>>).
    5.BUG BUSTERS:What is wrong with this program?
    0: Bug Busters
    1: #include
    2: using namespace std;
    3: class Animal;
    4:
    5: void setValue(Animal& , int);
    6:
    7: class Animal
    8: {
    9: public:
    10: int GetWeight()const { return itsWeight; }
    11: int GetAge() const { return itsAge; }
    12: private:
    13: int itsWeight;
    14: int itsAge;

Free download pdf