Q 1. Consider the following class definition class father { protected : int age; public; father (int x) {age = x;} virtual void iam ( %3D { cout <

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 24SA
icon
Related questions
Question

Please solve this with C++

Q 1. 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 : << age<< end1:}
};
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
classes and then calls iam ( ) for them. Declare pointer to father. Successively, assign
addresses of objects of the two derived classes to this pointer and in each case, call iam (
) through the pointer to demonstrate polymorphism in action.
Transcribed Image Text:Q 1. 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 : << age<< end1:} }; 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 classes and then calls iam ( ) for them. Declare pointer to father. Successively, assign addresses of objects of the two derived classes to this pointer and in each case, call iam ( ) through the pointer to demonstrate polymorphism in action.
Expert Solution
steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning