Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions