Preview File Edit View Go Tools Window Help [-] 100% i, Tue 7:30 AM Jonathan Lad
ID: 3721143 • Letter: P
Question
Preview File Edit View Go Tools Window Help [-] 100% i, Tue 7:30 AM Jonathan Ladner Q E a Assignment 9 - Circle Class (1 page) Q Search 1124 CSC 205 Assignment 8 Circle Class Write a circle class that has the following member variables: e radius: a double pi: a double initialized with the value 3.14159 he 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. A mutator function for the radius variable. getRadius. An accessor function for the radius variable. getArea. Returns the area of the circle, which is calculated as area-pi * radius * radius .getDiameter. Returns the diameter of the circle, which is calculated as diameter = radius * getCircumference. Returns the circumference of the circle, which is calculated as circumference 2 pi * radius Write a program that demonstrates the Circle class by asking the user for the circle's radius, creating a Circle object, and then reporting the circle's area, diameter, and circumference 3096 Page 362 of 1124Explanation / Answer
#include <iostream>
using namespace std;
class Circle
{
private:
double radius;
double pi=3.14159;
public:
Circle();
void setRadius(double);
double getRadius() ;
double getArea() ;
double getCircumference() ;
double getDiameter() ;
};
Circle::Circle(){
radius=0;
}
void Circle::setRadius(double r){
radius = r;
}
double Circle::getRadius(){
return radius;
}
double Circle::getArea(){
return pi * radius *radius;
}
double Circle::getCircumference(){
return 2* pi * radius ;
}
double Circle::getDiameter(){
return 2 * radius ;
}
int main()
{
double r;
cout<<"Enter the radius: "<<endl;
cin >> r;
Circle c1;
c1.setRadius(r);
cout << "Circle Radius: "<<c1.getRadius() << endl;
cout<<"Area: "<<c1.getArea()<<endl;
cout<<"Perimeter: "<<c1.getCircumference()<<endl;
cout<<"Diameter: "<<c1.getDiameter()<<endl;
return 0;
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.