Challenge 2: Implement an Animal Class

In this challenge, we'll implement a base class Animal and two derived classes Sheep and Dog.

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.
  • 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
    • Sheep class
      • has a private member color
      • has a function named Sheep_detail() which prints detail of the Sheep
  • The derived classes should

    • call the method of the Animal class which prints the name and the sound and for Dog class prints the family of dog that is Carnivores and for Sheep class prints the color of sheep White.

Input

  • Name of Dog is set to Pongo and the Sound is set to woof woof in parametrized constructor of Dog object
  • Name of Sheep is set to Billy and the Sound is set to baaa baaa in parametrized constructor of Sheep object
  • Now, print Dog_detail and Sheep_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();

Sample Output

Get hands-on with 1400+ tech skills courses.