Challenge 2: Implement an Animal Class
In this challenge, we'll implement a base class Animal and two derived classes Sheep and Dog.
We'll cover the following...
We'll cover the following...
Problem Statement
The code below has:
-
A parent class named
Animal.- Inside it define:
NameSoundvoid Animal_Details()function:- It prints the name and sound of the
Animal.
- It prints the name and sound of the
- Inside it define:
-
Then there are two derived classes
Dogclass- has a private member
family - has a function named
Dog_detail()which prints detail of the dog
- has a private member
Sheepclass- has a private member
color - has a function named
Sheep_detail()which prints detail of the Sheep
- has a private member
-
The derived classes should
- call the method of the
Animalclass which prints thenameand thesoundand forDogclass prints the family of dog that is Carnivores and forSheepclass prints the color of sheep White.
- call the method of the
Input
NameofDogis set to Pongo and theSoundis set to woof woof in parametrized constructor ofDogobjectNameofSheepis set to Billy and theSoundis set to baaa baaa in parametrized constructor ofSheepobject- Now, print
Dog_detailandSheep_detailfrom their respective objects
Here’s a sample result which you should get.
Sample Input
Dog d("Pongo", "Woof Woof");
d.Dog_detail();
Sheep s("Billy", "Baaa Baaa");
s.Sheep_detail();