36-Section-Handout

36-Section-Handout - CS106X Winter 2008 Handout 36 Section...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Handout 36 Winter 2008 March 5, 2008 Section Handout Problem 1: Inheritance Design The animal kingdom has a wide variety of members which all have various things in common (that is, those things that differentiate them from plants or rocks). However, just labeling something an Animal is not a whole lot of information about the specifics of the creature. Consider this definition for an Animal class. class Animal { public: Animal(string color); void breathe(); void move(); int getNumLegs(); int getNumEyes(); string getColor(); private: string color; int numLegs; }; You are to define three subclasses of the Animal class— Horse , Fish and Bird —that each have different characteristics. The Horse has four legs, for example, while the Bird has two and the Fish none. In addition, you will need to take the following into account: Each has its own method of moving. Assume that the Animal constructor sets a default numLegs = 4 as well as storing the user-provided color. In addition to the default form of movement, the
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

36-Section-Handout - CS106X Winter 2008 Handout 36 Section...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online