Question: Compose a C++ console app that defines a class named RegularPolygon. A regular polygon is a shape such as a triangle, square, pentagon, etcetera, where

Compose a C++ console app that defines a class named RegularPolygon. A regular polygon is a shape such as a triangle, square, pentagon, etcetera, where all sides lengths are equal and the angles at the vertices are also all equal. Create the class definition inside a separate header (.h) file. Create the class implementation in a separate source code (.cpp) file. Note that both source code files need to #include the header file. Don't forget to wrap the class definition inside a #ifndef inclusion guard.

The RegularPolygon class should contain private date members for the number of sides, the length of a side and the (x,y) position of the polygon. The position should be defined as a class in a separate file with it's x and y coordinates made private and only accessible through the use of accessor methods.

Define a 0-arg constructor that initializes a RegularPolygon object with sensible default values. Define a 2-arg constructor that initializes an object with the given number of sides and the side length. Define a 3-arg constructor that initializes an object with given values for all 3 data members.

Define 2 methods that calculate and return the perimeter and the area. Provide accessor and mutator methods for all 3 data members.

From main, demonstrate the class by creating 3 RegularPolygon objects using the 3 different constructors. For the objects that utilize the 2-arg and 3-arg constructors, allow the user to input the argument values. Display the data members, perimeter and area for all 3 polygons in a pleasing format. All I/O should occur from within main.

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!