Write a C++ program that has a Polygon interface that has abstract functions, ar
ID: 3649242 • Letter: W
Question
Write a C++ program that has a Polygon interface that has abstract functions, area(), and perimeter(). Implement classes for Triangle, Quadrilateral, Pentagon, Hexagon, and Octagon, which implement this interface, with the obvious meanings for the area() and perimeter() functions. Also implement classes, Isosceles Triangle, Equilateral Triangle, Rectangle, and Square, which have the appropriate inheritance relationships. Finally, write a simple user interface that allows users to create polygons of the various types, input their geometric dimensions, and then output their area and perimeter. For extra effort, allow users to input polygons by specifying their vertex coordinates and be able to test if two such polygons are similar.Explanation / Answer
class Polygon { protected int width, height; public void setParameters (int w,int h) { width = w; height = h; } }; class Rectangle : public Polygon { public int calculateArea () { return (width*height); } }; class Triangle : public Polygon { public int calculateArea () { return( (width*height)/2); } }; int main () { Rectangle rect; Triangle trgl; rect. setParameters (4,5); trgl. setParameters (4,5); coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.