Question: 1 . Implement a class named Polygon has two member variables width and height both of type int, and has two member functions as follows:

1. Implement a class named Polygon has two member variables width and height both
of type int, and has two member functions as follows:
set_valuesFunction to set width and height
areaValue-returning function to return the area of the class instance as number
0
2. 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.
3. Write a function to handle the polymorphism (using virtual functions) in calculating the
area of three above classes instances.
4. 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 each class instance (sample output as a below picture).

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!