Derive the two classes son and daughter from the above


Program

Consider the following class definition 

Class father
{
  Protected: 
     int age;
  public:
     father (int x) {age=x;}

        virtual void iam ()
      {
         Cout<<"I AM THE FATHER, my age is:"};

Derive the two classes son and daughter from the above class and for each, define iam() to write our similar but appropriate messages. you should also define suitable constructors for these classes.

Now write a main() that creates objects of the three and then calls iam() for them. Declare pointer and in each case call iam() through the pointer to demonstrate polymorphism in action.

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Derive the two classes son and daughter from the above
Reference No:- TGS01475472

Now Priced at $10 (50% Discount)

Recommended (90%)

Rated (4.3/5)