Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create the header file named “regPoly.h” that contains the following class: The

ID: 3607058 • Letter: C

Question

Create the header file named “regPoly.h” that contains the following class: The class RegularPolygon is representing a regular polygon which is a polygon whose sides are all congruent such as the equilateral triangle. This class should contain:

Section 1: Class Create the header file named "regPoly.h” that contains the following class: The class RegularPolygon is representing a regular polygon which is a polygon whose sides are all congruent such as the equilateral triangle. This class should contain: A public double field that represents the number of sides of the polygon. A public double field that represents the length of the sides of the polygon A public default constructor that sets the fields to represent an unit equilateral triangle A public overloaded constructor that takes a double paraneter which should be assigned to the length of the sides field if it is greater than zero; otherwise, the field should be assigned 1 And the number of sides field should be assigned 3. A public overloaded constructor that takes two (2) double parameters which should be assigned to the fields of the class. The parameter that is assigned to the length of the sides field should be greater than 0; otherwise, the length of the sides field should be assigned 1. And the parameter that is assigned to the number of sides field should be greater than or equal to 3; otherwise, the number of sides field should be assigned 3 A public destructor A public copy constructor A public overloaded assignment operator A public double method nained Perimeter() that takes no parameters. It should return the perimeter of the polygon it is representing A public double method named SunOf InteriorAngles() that takes no parameters. It should return the sum of the interior angles of the polygon it is representing. A public double method named Area) that takes no parameters. It should return the area of the polygon it is representing A public string method named ToString() that takes no param eters. It should return a string that lists the fields each set to one decimal point separated by a delimiter of your choice except or a new line. Section 2: Implementation Create the cpp file "m A string function named Stats() that takes a Regular Polygon as a parameter. It should nain.cpp" that contains the following: return a string that lists the properties of the RegularPolygon parameter which are the number of sides, length of the sides, perimeter, sum of interior angles and the area of the polygon. A void function narned Records() that takes an int as a pararneter. It should displays the statistics of the first n (where n is the parameter) regular polygons with random side lengths no more than 10 if n is greater than or equal to 1 otherwise, it should do nothing. Each statistic should be on its own line The main function should call Records() with an argument that is greater than or equal to 5 and less than 15 Section 3: Extra Credit Modify Records() to also print the list to a file

Explanation / Answer

Important Formulas for Polygon :

___________________________________________________________________________________________

regPoly.h :

#ifndef REGPOLY_H_

#define REGPOLY_H_

#include <string>

#include <math.h>

#include <sstream>

class RegularPolygon

{

public:

double totSide;

double length;

public://Constructors

RegularPolygon();

RegularPolygon(double);

RegularPolygon(double, double);

public://Destructor

~RegularPolygon();

public://Copy Constructor

RegularPolygon(const RegularPolygon &rPol);

void operator=(const RegularPolygon &rhs);

public:

double Perimeter(); //Formula for calculate Perimeter = Number of side X Length of side

double SumOfInteriorAngles();

double Area();

std::string ToString();

};

RegularPolygon::RegularPolygon()

{

length = 1;

totSide = 3;

}

RegularPolygon::RegularPolygon(double len)

{

if(len > 0)

{

length = len;

}

else

{

length = 1;

totSide = 3;

}

}

RegularPolygon::RegularPolygon(double len, double sideCount)

{

len > 0 ? length = len : length = 1;

sideCount >= 3 ? totSide = sideCount : totSide = 3;

}

RegularPolygon::~RegularPolygon()

{

}

RegularPolygon::RegularPolygon(const RegularPolygon &rPol)

{

length = rPol.length;

totSide = rPol.totSide;

}

void RegularPolygon::operator = (const RegularPolygon &rhs )

{

length = rhs.length;

totSide = rhs.totSide;

}

double RegularPolygon::Perimeter()

{

double perimeter;

perimeter = totSide * length ;

return perimeter;

}

double RegularPolygon::SumOfInteriorAngles()

{

double sumIntAngles;

sumIntAngles = (totSide - 2) * 180;

return sumIntAngles;

}

double RegularPolygon::Area()

{

double area;

long double cotValue = (1 / tan(3.14159/totSide));

double apthem = (length / 2) * cotValue;

area = (apthem * Perimeter()) / 2;

return area;

}

std::string RegularPolygon::ToString()

{

std::stringstream s;

s << "Number of Side : " << totSide << ", Length of Each Side : " << length;

return s.str();

}

#endif /* REGPOLY_H_ */

______________________________________________________________________________________

main.cpp :

#include <iostream>

#include <cstdlib>

#include <string>

#include "regPoly.h"

using namespace std;

string Stats(RegularPolygon poly)

{

std::stringstream s;

s << poly.ToString() << ", Area : " << poly.Area()<< ", Sum of Interior Angles : " << poly.SumOfInteriorAngles();

s << ", Perimeter : " << poly.Perimeter()<<" ";

return s.str();

}

void Records(int n)

{

int i;

double length;

if(n>=1)

{

for(i=3; i<=n; i++)

{

length = (rand() % 10 + 1);

RegularPolygon poly(length, i);

cout<<Stats(poly);

}

}

}

int main()

{

Records(15);

return 0;

}