Answered step by step
Verified Expert Solution
Link Copied!

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:

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Make A Database In Historical Studies

Authors: Tiago Luis Gil

1st Edition

3030782409, 978-3030782405

More Books

Students also viewed these Databases questions

Question

Define market concentration and market spreading.

Answered: 1 week ago

Question

Q - 2 0 ) Create a function called "linsolution" which solve

Answered: 1 week ago

Question

2. What recommendations will you make to the city council?

Answered: 1 week ago

Question

3. The group answers the questions.

Answered: 1 week ago