Question: C++ Problem #1: Polygon vs. circle (You can do it!) I need help formatting the code(at the end of the page) so it can look

C++ Problem #1: Polygon vs. circle (You can do it!)

I need help formatting the code(at the end of the page) so it can look like the output in the example pictures. I also need assistance implementing the code in part vi. of the problem.

(vi. Print the area and perimeter of the circle and the average area and perimeter of the regular polygons, and their differences.) Thank you in advance!

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Design a class named Circle to represent a circle and a class named Polygon to represent a regular polygon.

Implement the classes (header and implementation files) using the following UML diagrams:

a.

Circle

-r: double

The radius, r, of the circle (default: 0)

+Circle()

+Circle(r: double)

+getArea(): double

+getPerimeter(): double

+getRadius(): double

+setRadius(r: double) void

Constructs a default circle object

Constructs a circle with specified radius

Returns the area of this circle

Returns the perimeter of this circle

Returns the radius of this circle

Sets a new radius, r, to this circle

Polygon

-R: double

-n: int

The circumradius, R, of the polygon (default:0)

The number of sides, n, of the polygon (default: 3)

+Polygon()

+getArea(): double const

+getPerimeter(): double const

+getApothem: double const

+getSideNumber: int const

+getSideLength: double const

+getInteriorAngle(): double const

+getExteriorAngle(): double const

+setSideNumber(sideNumber: double) void

+setCircumRadius(radius: double) void

Constructs a default polygon object

Returns the area of this polygon

Returns the perimeter of this polygon

Returns the apothem of this polygon

Returns the number of sides of this polygon

Returns the length side of this polygon

Returns the interior angle of this polygon

Returns the exterior angle of this polygon

Sets a new number of sides to this polygon

Sets a new circumradius to this polygon

b. Write a test program that

i.Randomly generate a double value ranging 1300 for X.

ii.Create one Circle object and assign radius of X

iii.Create 100 regular polygon objects, and assign circumradius of X and set the number of sides starting at 3 and increment by 1.

iv.Find the average area and perimeter of the 100 regular polygons.

v.Print a table of information of those 100 regular polygons.

Regular n-polygon where

n - number of sides

a - apothem

r - innerradius

R - circumradius

A - areas

P - perimeter

x - interior angle

y - exterior angle

Example output:

C++ Problem #1: Polygon vs. circle (You can do it!) I need

vi. Print the area and perimeter of the circle and the average area and perimeter of the regular polygons, and their differences.

Example output:

help formatting the code(at the end of the page) so it can

the program has to output exactly as the images above

I have this code to generate the some of whats requested but it needs to be formatted and we are missing part vi.

#include #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #include #include using namespace std;

class Circle{ private: int r; public: Circle(){ r = 0; } Circle(double radius){ r = radius; } double getArea(){ return (M_PI)*r*r; // Area of circle is pi*r*r } double getPerimeter(){ return 2*(M_PI)*r; // Perimeter of circle is 2*pi*r } double getRadius(){ return r; } // Sets a new radius, r, to this circle void setRadius(double radius){ r = radius; } };

class Polygon{ private: int R; int n; // Convert defrees to radians double degreeToRadian(double d) { return (d / 180.0) * ((double) M_PI); } public: Polygon(){ R=0; n=3; } double getArea(){ return R*R*n*sin(degreeToRadian(360))/2; } double getPerimeter(){ return 2*n*R*sin(degreeToRadian(M_PI)); } double getApothem(){ return R*cos(degreeToRadian(180)); } int getSideNumber(){ return n; } double getSideLength(){ return 2*R*sin(degreeToRadian(M_PI)); } double getInteriorAngle(){ double sumOfInteriorAngles = (n-2)*180; return sumOfInteriorAngles; } double getExteriorAngle(){ return 180 - getInteriorAngle(); } double getCircumRadius(){ return R; } void setSideNumber(int nS){ n = nS; } void setCircumRadius(int radius){ R = radius; } };

int main() { double x= 1+ (rand()*(300-1) / RAND_MAX); // min + (rand() * (int)(max - min) / RAND_MAX) Circle c(x); Polygon p[100]; cout egular n-polygon where numbeF Of sidles - apothem 1nnerradius R circumr aeas perimeter - interior angle - exterior angle 12.09 20.940 6.045 189.878 62.821 60.000 120.000 12.09 17.098 8.549 292.336 68.391 90.000 90.000 12.09 14.213 9.781 347.535 71.063 198.000 72.000 12.09 12.090 10.470 379.756 72.540 120.000 60.000 12.09 10.491 10.893 399.976 73.439 128.571 51.429 12.0909.253 11.170 413.42674.026 135.000 45.000 12.090 8.270 11.361 422.797 74.430 140.000 40.000 12.0907.47211.498 429.577 74.720 144.000 36.000 12.09 6.812 11.600 434.63474.935 147.273 32.727 12.09 6.258 11.678 438.504 75.099 150.000 30.000 12.0905.787 11.739 441.530 75.226 152.308 27.692 12.09 5.381 11.787 443.939 75.328 154.286 25.714 4

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!