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:
set_values_Function to set width and height
area-Value-returning function to return the area of the class instance as number 0
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 4 and 5 to their member functions set_values (i.e., set_values (4,5)), and called the function written in 3. to demonstrate that the areas were calculated correctly for ech class instance (sample output as a below picture).
Area as a Polygon object: 0
Area as a Triangle object: 10
Area as a Rectangle object: 20
z
 Implement a class named Polygon has two member variables width and

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!