Question: C++ ONLY!!! Create 4 classes that inherit the polygon pure virtual base class you adjusted and defined in Exercise 1. Those polygons are assumed to

C++ ONLY!!! Create 4 classes that inherit the polygon pure virtual base class you adjusted and defined in Exercise 1. Those polygons are assumed to be perfect (no irregular shapes). The polygons are as follows: This will be the parent class for all two dimensional polygons you will be working with in this assignment.

polygon.h

#ifndef POLYGON_H #define POLYGON_H

class polygon{ private: int sides; public: polygon(int sides); //Constructor - default sides to 3 polygon(const polygon*); //Copy constructor void setSides(int sides); //setter for private attribute int getSides() const; //Getter for private attribute //Other functions virtual double calcArea()=0; //calculates the area of a polygon virtual double calcPerimeter()=0; //calculates the perimeter of a polygon virtual void printDimensions()=0; //displays the dimensions of a polygon along with its area and perimeter };

#endif

polygon.cpp

#include #include "polygon.h" using namespace std;

polygon::polygon(int sides) //Constructor - default sides to 3 { this->sides = sides; } polygon::polygon(const polygon *p)//Copy constructor { this->sides = p->sides; } void polygon::setSides(int sides) //setter for private attribute { this->sides = sides; } int polygon::getSides() const //Getter for private attribute { return sides; }

- triangle (triangle.h and triangle.cpp) - rectangle (rectangle.h and rectangle.cpp) - pentagon (pentagon.h and pentagon.cpp) - hexagon (hexagon.h and hexagon.cpp)

Research how to calculate the area and perimeter for each of these shapes and be sure to override the appropriate base class functions to achieve this. In the printDimensions() function, be sure to output what each polygon (rectangle, triangle, etc) is along with its pertinent dimensions and the number of sides.

In the rectangle class, add a boolean member function, isSquare() that is true when the sides of the rectangle object are equal. If the object is a square output that information as a part of the output of the rectangle object.

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!