Challenge 3: Implement a Father Class
In this challenge, we'll implement a base class father and derived classes, son and daughter.
We'll cover the following
Problem Statement
Implement a code which have:
- A parent class named
Father
.- Inside it define:
eye_color
hair_color
void Father_traits()
function:- It prints the eye_color and hair_color of the called object
- Inside it define:
- Then, there are two derived classes
Son
class- has a private member
name
- has a function named
Son_traits()
which prints traits of the Son
- has a private member
Daughter
class- has a private member
name
- has a function named
Daughter_traits()
which prints traits of the Daughter
- has a private member
- The derived classes should
- call the method of the
Father
class which prints theeye_color
and thehair_color
and forSon
andDaughter
classes prints the name of a respective object.
- call the method of the
Input
-
In
Son
class,eye_color
is set to Brown and thehair_color
is set to Black andname
is set to Ralph in parametrized constructor ofSon
object -
In
Daughter
class,eye_color
is set to Green and thehair_color
is set to Golden andname
is set to Rapunzel in parametrized constructor ofDaughter
object -
Now, print
Son_traits
andDaughter_traits
from their respective objects
Here’s a sample result which you should get.
Sample Input
Daughter obj("Rapunzel","Green","Golden");
obj.Daughter_traits();
Son Obj("Ralph","Brown","Black");
Obj.Son_traits();