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

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!