|
|
 |
|
|
|
|
91: cin >> choice;
92:
93: switch (choice)
94: {
95: case 1: pAnimal = new Dog(5,Brown);
96: break;
97: case 2: pAnimal = new Horse (4,Black);
98: break;
99: case 3: pAnimal = new Fish (5);
100: break;
101: default: fQuit = true;
102: break;
103: }
104: if (fQuit)
105: break;
106:
107: pAnimal->Speak();
108: pAnimal->Eat();
109: pAnimal->Reproduce();
110: pAnimal->Move();
111: pAnimal->Sleep();
112: delete pAnimal;
113: cout << \n;
114: }
115:
116:
117:
118: return 0;
119: } |
|
|
|
|
|
|
|
|
(1)Dog (2)Horse (3)Bird (0)Quit: 1
Animal constructor
Mammal constructor
Dog constructor
Whoof!
Dog eating
Dog reproducing
Dog running
Dog snoring
Dog destructor
Mammal destructor
Animal destructor
(1)Dog (2)Horse (3)Bird (0)Quit: 0 |
|
|
|
|
|
|
|
|
Analysis: On lines 721, the abstract data type Animal is declared. Animal has non-pure virtual accessors for itsAge, which are shared by all Animal objects. It has five pure virtual functions: Sleep(), Eat(), Reproduce(), Move(), and Speak(). |
|
|
|
|
|