Question
I already have the codes, but there is a error in it, need some help on my C++ program assignment, this is the question below:
I already have the codes, but there is a error in it, need some help on my C++ program assignment, this is the question below:
Write a program that demonstrates the Circle class by asking the users for the circle's radius, creating a Circle object, and then reporting the circle's area, diameter, and circumference.
I hope someone can help me fix the error i have in my code, Thank you!
class Circle{
private:
double radius;
double pi = 3.14159;
public:
Circle();
void setRadius(double);
double getRadius() const
{ return radius; }
double getArea() const
{ return pi * radius * radius; }
double getDiameter() const
{ return radius * 2; }
double getCircumference() const
{ return 2 * pi * radius; }
};
#include
#include
#include
using namespace std;
Circle::Circle(){
radius = 0.0;
}
void Circle::setRadius(double rad){
if(rad >= 0)
radius = rad;
else{
cout << "Invalid radius ";
exit(EXIT_FAILURE);
}
}
int main(){
double radius;
cout << "Enter the radius of the circle:" << endl;
cin >> radius;
Circle c(radius);
cout << "Area of the circle:" << c.getArea() << endl;
cout << "Diameter of the circle:" << c.getDiameter() << endl;
cout << "Circumference of the circle is:" << c.getCircumference() << endl;
return 0;
}
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