Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Bioinformatics Databases And Systems

Authors: Stanley I. Letovsky

1st Edition

1475784058, 978-1475784053

More Books

Students also viewed these Databases questions