/*! \file Polygon.cpp * \brief Polygon implementations\n * A Regular Polygon has a number of sides of equal length * */ #include #include #include "Polygon.h" /*! * \fn Constructor * Requires: Number of sides, length of sides * Values default to 1. **************************************************************************/ Polygon::Polygon(int numSides, double sideLength) { sides = numSides; length = sideLength; } /*! * getSides - returns the number of sides * inspector **************************************************************************/ int Polygon::getSides() const{ return sides; } /*! * getLength - returns the length * inspector **************************************************************************/ double Polygon::getLength() const{ return length; } /*! * getPerimeter - calculates and returns the perimeter * facilitator **************************************************************************/ double Polygon::getPerimeter() const{ double perimeter; perimeter = getLength() * getSides(); return perimeter; } /*! * getArea - calculates and returns the area * facilitator **************************************************************************/ double Polygon::getArea() const{ double area; area =(getSides() * (pow(getLength(), 2))) / (4 * (tan(3.1416/getSides()))); return area; } /*! * operator < - sorts the Polygon objects based on size * facilitator ***************************************************************************/ bool Polygon::operator<(Polygon &right) const { if(getSides() < right.getSides()) return true; else return false; } /*! *operator == compares polygons *facilitatos ***************************************************************************/ bool Polygon::operator==(Polygon &right) const { if(getSides() == right.getSides()) return true; else return false; } /*! * operator<< - overloaded operator for outputting Polygon's string name * facilitator **************************************************************************/ ostream &operator<<(ostream &output, const Polygon &right){ static string shapeNames[9] = {"","","","Triangle","Square","Pentagon","Hexagon","Septagon","Octogon"}; output << shapeNames[right.getSides()]; return output; }