Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Circle class that has the following data members: radius: a double pi: a

ID: 3574942 • Letter: W

Question

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 set Radius (double). A mutator function for the radius variable. double getRadius. An accessor function for the radius variable. inputRadius- from the keyboard 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 getArea. Return the area of the circle, which is calculated as area = pi* radius* radius double getDiameter. Return the diameter of the circle, which is diameter = radius *2 double getCircumference. Return the circumference of the circle, which is calculated as circumference = 2* pi * radius. 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.

Explanation / Answer

#include<iostream>
using namespace std;
//Class Circle definition
class Circle
{
//Data member
double radius;
double static pi;
public:
//Default constructor initializes the data member radius to 0.0
Circle()
{
radius = 0.0;
}
//Parameterized constructor initializes the data member radius to r
Circle(double r)
{
radius = r;
}
//Give value to the radius
void setRadius(double r)
{
radius = r;
}
//Return radius
double getRadius()
{
return radius;
}
//Accept radius
void inputRadius()
{
int r;
cout<<" Enter the Radius: ";
cin>>r;
setRadius(r);
}
//Display the Radius and Area of the circle as per the format
void displayCircle()
{
cout<<" Radius: "<<radius<<" , Area = "<<getArea();
}
//Returns the Area of a Circle
double getArea()
{
return (pi * radius * radius);
}
//Returns the Diameter of a Circle
double getDiameter()
{
return (radius * 2);
}
//Returns the Circumference of a Circle
double getCircumference()
{
return (2 * pi * radius);
}
};
//Initializes the static data member pi to 3.1416
double Circle::pi = 3.1416;
int main()
{
//Creates a Circle class object C1 by calling default constructor
Circle C1;
//Creates a Circle class object C1 by calling parameterized constructor
Circle C2(5.0);
//Accepts the radius for object C1
C1.inputRadius();
cout<<" Area of the Circle = "<<C2.getArea();
cout<<" Diameter of the Circle = "<<C2.getDiameter();
cout<<" Area of the Circle = ";
C1.displayCircle();
C1.setRadius(10.0);
cout<<" Circumference of the Circle = "<<C1.getCircumference();
}

Output:

Enter the Radius: 2.5

Area of the Circle = 78.54
Diameter of the Circle = 10
Area of the Circle =
Radius: 2 , Area = 12.5664
Circumference of the Circle = 62.832

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote