Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 . Implement a class named Polygon has two member variables width and height both of type int, and has two member functions as follows:
Implement a class named Polygon has two member variables width and height both
of type int, and has two member functions as follows:
setvaluesFunction to set width and height
areaValuereturning function to return the area of the class instance as number
Using a Polygon class as a base class, implement two derived classes simulating a
Triangle and Rectangle, each redefining a function to calculate the area accordingly.
Write a function to handle the polymorphism using virtual functions in calculating the
area of three above classes instances.
Then write the main class that creates instances of three above classes one for each
class passes values and to their member functions setvalues ie
setvalues and called the function written in to demonstrate that the
areas were calculated correctly for each class instance sample output as a below picture
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started