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
Problem Statement
The code below has:
-
A parent class named
Animal
.- Inside it define:
Name
Sound
void 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
Dog
class- has a private member
family
- has a function named
Dog_detail()
which prints detail of the dog
- has a private member
Sheep
class- 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
Animal
class which prints thename
and thesound
and forDog
class prints the family of dog that is Carnivores and forSheep
class prints the color of sheep White.
- call the method of the
Input
Name
ofDog
is set to Pongo and theSound
is set to woof woof in parametrized constructor ofDog
objectName
ofSheep
is set to Billy and theSound
is set to baaa baaa in parametrized constructor ofSheep
object- Now, print
Dog_detail
andSheep_detail
from 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();