Circle class

i did my program but i m getting many error  in my program. errors like unexpected token ":" or ";" before double and this is my program.

 
#include<iostream>


 using namespace std;

 class Circle
 {
    private
    double PI = 3.14159;
    double radius;

    public Circle()
    {
        radius = 0.0;
    }

    public Circle(double r)
    {
        radius = r;
    }

    public void setRadius(double r)
    {
        radius = r;
    }

    public double getRadius()
    {
        return radius;
    }

    public double getArea()
    {
        return PI * radius * radius;
    }

    public double getDiameter()
    {
        return radius * 2;
    }

    public double getCircumference()
    {
        return 2 * PI * radius;
    }
 };


int main()
 {
     double radius;

     cout << "Enter the circle's radius:" << endl;
     cin >> radius;

     cout << "Radius:" << c.getRadius() << endl;

     cout << "Area:" << c.getArea() << endl;

     cout << "Diameter:" << c.getDiameter() << endl;

     cout << "Circumference:" << c.getCircumference() << endl;

     return 0;
 }

Open in new window

deep patelAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
You never create the circle c.

After you cin the radius you should have

Circle c = new Circle(radius);

int main()
 {
     double radius;

     cout << "Enter the circle's radius:" << endl;
     cin >> radius;

     cout << "Radius:" << c.getRadius() << endl;

     cout << "Area:" << c.getArea() << endl;

     cout << "Diameter:" << c.getDiameter() << endl;

     cout << "Circumference:" << c.getCircumference() << endl;

     return 0;
 }

Open in new window

0
phoffricCommented:
I fixed up your public and private notation, and had to define c, the circle.
http://ideone.com/v2KpQO
#include<iostream>

 using namespace std;

 class Circle
 {
private:
    const double PI = 3.14159;  // added const since PI is a constant
    double radius;

public:
    Circle()                 // do you really want to construct a circle of radius 0? Your choice. You could remove this constructor if you want
    {
        radius = 0.0;
    }

    Circle(double r)
    {
        radius = r;
    }

    void setRadius(double r)
    {
        radius = r;
    }

    double getRadius()
    {
        return radius;
    }

    double getArea()
    {
        return PI * radius * radius;
    }

    double getDiameter()
    {
        return radius * 2;
    }

    double getCircumference()
    {
        return 2 * PI * radius;
    }
 };


int main()
 {
     double radius;

     cout << "Enter the circle's radius:" << endl;
     cin >> radius;
     
     Circle c(radius);

     cout << "Radius:" << c.getRadius() << endl;

     cout << "Area:" << c.getArea() << endl;

     cout << "Diameter:" << c.getDiameter() << endl;

     cout << "Circumference:" << c.getCircumference() << endl;

     return 0;
 }

Open in new window

Here is the output:
Enter the circle's radius:
Radius:10
Area:314.159
Diameter:20
Circumference:62.8318

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
peprCommented:
For the static vs. dynamic creation of the Circle object, I second to phoffric -- the static one. The Circle c = new Circle(radius); is more usual in C# or Java. I C++, there should be delete to release the object memory. The static instance is a kind of simpler.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.