Question: Write a class Polygon that has the following members: Protected members: width, height: integers Public members: Default Constructor Constructor with Parameter Function set _ values,
Write a class Polygon that has the following members:
Protected members:
width, height: integers
Public members:
Default Constructor
Constructor with Parameter
Function setvalues, which takes two integers and sets the values of width and height.
Pure virtual function area.
printinfo function to print the height and width
Class Rectangle that inherits from class Polygon and has the following members:
Public members:
function area that implements the pure virtual function area and should return widthheight
printinfo function to print the height, width, and area.
Class Triangle inherits from class Polygon and has the following members:
Public members:
function area that implements the pure virtual function area and should return widthheight
printinfo function to print the height, width, and area.
Main function that creates two objects rec and tri of class Rectangle and Triangle, respectively. It should then assign the address of rec and tri to two pointers poly and poly of type Polygon. You should use these two pointers to set the values of width and heights, then calculate and use printinfo to print out all details for each object.
ANSWER only in C
ONLY C
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
