Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using C++ Declare a class geometry that contains two (2) data items, measure1 and measure2, of type double. The constructor has two formal arguments that
Using C++
Declare a class geometry that contains two (2) data items, measure1 and measure2, of type double.
The constructor has two formal arguments that correspond to the data members. The second argument has the default value 0.0, which allows a geometry object to be declared with a single runtime argument.
When measure2 is 0.0, the figure represented is a circle; otherwise, it is a rectangle.
For example,
// represent a circle of radius 1 and rectangle with
// dimensions 3 x 5
geometry circ(1), rect(3,5);
The function border() returns the perimeter of the object. The function area() and diagonal() returns the diagonal of the object. Note that the diameter of a circle is its diameter. Implement the geometry class in the file geometry.h, and develop the following application.
Input the radius of a circle, and declare a geometry object that represents it. Use this radius to declare a square that circumscribes the circle. Declare a circle that circumscribes the square. Output the area and perimeter of each figure, i.e. the square that circumscribes the circle and the circle that circumscribes the square. To manipulate circle you will need to define a constant PI = 3.141592653589793. Also, you will need to use the function sqrt. For this you must include cmath. (Hint: the diagonal of a square can be obtained by using the Pythagorean theorem. Also, a square circumscribed by a circle has a diagonal that is twice the radius of the circle). The following figure shows the three objects that you are creating.
An example screen shot of the Windows Command Prompt window follows:
Enter a radius: 5
Area/perimeter of inner circle: 78.5398 / 31.4159
Area/perimeter of square: 100 / 40
Area/perimeter of outer circle: 157.08 / 44.4288
Press any key to continue . . .
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started