It 218
ntc242 - The following is University of Phoenix IT/218 week 8 check point: Derived Classes and Base Classes. The following contains the code from the text book as well as corrected code for exercise 2 on p. 597 of the text book.
ntc 242 - CheckPoint: Derived Classes and Base Classes: Due Friday in Assignment Section
it218 - Complete Exercise 2 on p. 597.
Answer the following question in one paragraph. How are derived classes and base classes related in this exercise?
it 218 - Derived Classes and Base Classes
The following code is from exercise 2 on page 597 chapter 9 of the textbook.
Suppose you have a class CBird, as follows, that you want to use as a base class for deriving a hierarchy of bird classes:
class CBird
{
protected:
int wingSpan;
int eggSize;
int airSpeed;
int altitude;
public:
virtual void fly() { altitude = 100; }
};
Is it reasonable to create a CHawk by deriving from CBird? How about a COstrich? Justify your answers. Derive an avian hierarchy that can cope with both of these birds.
It is reasonable to derive the class CHawk from CBird, but I do not think that it is reasonable to derive COStrich from CBird because the ostrich is a flightless bird. A better hierarchy of classes would represent both birds of flight and flightless birds such as the ostrich and the penguin. In the following code, Chawk can be derived from CFlyingBird and COStrich is dervied from CFlightlessBirdwhile both still share the same common base class of CBird.
class CBird
{
protected:
int wingSpan;
int eggSize;
};
class CFlightlessBird: public CBird
{
};
class CFlyingBird: public CBird
{
protected:
int airSpeed;
int altitude;
public:
virtual void fly( {altitude = 100;
};
It 218
ntc 242 - CheckPoint: Derived Classes and Base Classes: Due Friday in Assignment Section
it218 - Complete Exercise 2 on p. 597.
Answer the following question in one paragraph. How are derived classes and base classes related in this exercise?
it 218 - Derived Classes and Base Classes
The following code is from exercise 2 on page 597 chapter 9 of the textbook.
Suppose you have a class CBird, as follows, that you want to use as a base class for deriving a hierarchy of bird classes:
class CBird
{
protected:
int wingSpan;
int eggSize;
int airSpeed;
int altitude;
public:
virtual void fly() { altitude = 100; }
};
Is it reasonable to create a CHawk by deriving from CBird? How about a COstrich? Justify your answers. Derive an avian hierarchy that can cope with both of these birds.
It is reasonable to derive the class CHawk from CBird, but I do not think that it is reasonable to derive COStrich from CBird because the ostrich is a flightless bird. A better hierarchy of classes would represent both birds of flight and flightless birds such as the ostrich and the penguin. In the following code, Chawk can be derived from CFlyingBird and COStrich is dervied from CFlightlessBirdwhile both still share the same common base class of CBird.
class CBird
{
protected:
int wingSpan;
int eggSize;
};
class CFlightlessBird: public CBird
{
};
class CFlyingBird: public CBird
{
protected:
int airSpeed;
int altitude;
public:
virtual void fly( {altitude = 100;
};
It 218