Question: C++ Write a Circle class that has the following data members: radius: a double pi: a double initialized with the value 3.1416 The class should

C++

Write a Circle class that has the following data members:

radius: a double

pi: a double initialized with the value 3.1416

The class should have the following member functions:

Default constructor: a default constructor that sets radius to 0.0.

Constructor. Accepts the radius of the circle as an argument

setRadius (double). A mutator function for the radius variable.

double getRadius. An accessor function for the radius variable.

inputRadius - from the keyboard

double getArea. Return the area of the circle, which is calculated as area = pi * radius * radius

displayCircle - In this object function you need to call the function getArea to calculate the area of a circle, then display the radius of a circle and its area - format: Radius: ______, Area= ______ .

double getDiameter. Return the diameter of the circle, which is calculated as diameter = radius *2

double getCircumference. Return the circumference of the circle, which is calculated as circumference = 2 * pi * radius.

Requirements:

Constructors and class functions must be defined outside the class

Define constant PI = 3.1416 in the the private section of the class

Write a program the demonstrate the Circle class perform the following tasks:

Create a Circle object called C1 with radius equal to zero.

Create a Circle object called C2 with radius equal to 5.0

Input the radius for the circle C1 from the keyboard. Enter a value of 3.0 for the radius of the Circle C1.

Display the area of the circle C2 by calling the function getArea.

Display the diameter of the circle C2 by calling the function getDiameter.

Display the radius and area of the circle C1 by calling the function displayCircle.

Change the radius of the circle C1 to 10.0.

Display the circumference of the circle C1 by calling the function getCircumference.

Here is the main function:

Circle C1; Circle C2(5.0); cout<<"Enter the radius for circle C1"<

You can use the main function above to test your class Circle. The output of your program should be the same as the output shown below.

Output

Enter the radius for circle C1 3.0 Area of Circle C2: 78.54 Diameter of Circle C2: 10 Radius = 3 Area = 28.2744 Circumference of Circle C1 62.832

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!