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...
We'll cover the following...
Problem Statement
Implement a code which have:
- A parent class named
Father.- Inside it define:
eye_colorhair_colorvoid Father_traits()function:- It prints the eye_color and hair_color of the called object
- Inside it define:
- Then, there are two derived classes
Sonclass- has a private member
name - has a function named
Son_traits()which prints traits of the Son
- has a private member
Daughterclass- 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
Fatherclass which prints theeye_colorand thehair_colorand forSonandDaughterclasses prints the name of a respective object.
- call the method of the
Input
-
In
Sonclass,eye_coloris set to Brown and thehair_coloris set to Black andnameis set to Ralph in parametrized constructor ofSonobject -
In
Daughterclass,eye_coloris set to Green and thehair_coloris set to Golden andnameis set to Rapunzel in parametrized constructor ofDaughterobject -
Now, print
Son_traitsandDaughter_traitsfrom 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();