Question: Implement a class named Polygon has two member variables width and height both of type int, and has two member functions as follows: set _
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 ech class instance sample output as a below picture
Area as a Polygon object:
Area as a Triangle object:
Area as a Rectangle object:
z
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
