Question
C++

St// 105 points Problem 5 | 15 Points | Polymorphism and Virtual functions led Top. It has one public method called print that prints out the following expression I am the parent Create a class called Bottom that is inherited from the class Top.It has one public method also called print that prints out the following expressionI am the child e Write a function called mainprint that takes as input a class instance of type Top. This function will call the print method of the instance. Finally demonstrate the use of polymorphism and virtual functions by creating a main program that passes an instance of Top to mainprint and then pass an instance Bottom to mainprint. Answer Problem 5
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Following is the answer:

#include <iostream>

using namespace std;

class Top

{

friend class Bottom; // declaring Bottom as friend class

public:

void print()

{

cout<<"I am the parent";

}

};

class Bottom

{

public:

void print()

{

cout<<"I am the child";

}

};

int main()

{

Top top;

Bottom bottom;;

top.print();

cout<<endl;

bottom.print();

cout<<endl;

return 0;

}

Output:

I am the parent I am the child

Add a comment
Know the answer?
Add Answer to:
C++ St// 105 points Problem 5 | 15 Points | Polymorphism and Virtual functions led Top....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT