Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Learning Activity 3 : Animals Create a simple set of classes representing types of animals. 1 . Create a base class representing all animals. The

Learning Activity 3: Animals
Create a simple set of classes representing types of animals.
1. Create a base class representing all animals. The base class should contain a field for the animals name. The name should be set to Animal by default but should also be set to a more specific value by any derived classes. The base class should also have a field for storing the number of legs the animal has. By default, in the Animal class, legs are set to 0. The animal class should have three virtual functions namely GetName(), GetLegs(), and GetSpecialAbility(), that return the Animals Name, the total number of legs, and the special ability of the Animal. Moreover, this base class contains an overridden ToString() method, to return all of its state variables in a given format. [Please investigate the starter code, or the provided input/ output to understand the format.]
2. Create a Dog class that is a type of Animal, and the class also contains a method called GetSpecialAbility() that returns Woof.
3. Create a Fish class that is a type of Animal, and the class also contains a method called GetSpecialAbility() that returns Just keep swimming.
4. Create a Shark class that is a type of Fish, and also contains a method called GetSpecialAbility() that uses a reference animal object that was initially passed as a parameter to a constructor method and returns Shark ate .
// Sample Outputs
/*Commands
animal
dog
fish
shark
exit
Sample Input/Output 1:
animal
Animal 0
Eating...
dog
Dog 4
Woof
fish
Fish 0
Just keep swimming
shark
Shark 0
Shark ate Fish
exit
---------------------------
*/
/*Commands
animal
shark
fish
shark
dog
shark
shark
exit
Sample Input/Output 2:
animal
Animal 0
Eating...
shark
Shark 0
Shark ate Animal
fish
Fish 0
Just keep swimming
shark
Shark 0
Shark ate Fish
dog
Dog 4
Woof
shark
Shark 0
Shark ate Dog
shark
Shark 0
Shark ate Shark
exit
*/

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions