Home > Back-end >  So why not?
So why not?

Time:03-24


Const double PI=3.14159;
The class Circle
{
Public:
Circle (double r);
Double Circumference ();
Double Area ();
Friend double fCircle_L (Circle & amp; The rr);
Friend double fCircle_S (Circle & amp; The rr);
Private:
Double radius;
};
Circle: : Circle (double r)
{
The radius=r;
}
Double Circle: : Circumference ()
{
Cout & lt; Return 2 * PI * radius;
}
Double Circle: : Area ()
{
Cout & lt; Radius, return PI * * radius;
}
Double fCircle_L (Circle & amp; R)
{
Cout & lt; Double L=2 * PI * r.r adius;
return L;
}
Double fCircle_S (Circle & amp; R)
{
Cout & lt; Double S=PI * r.r adius * r.r adius;
Return S;
}

CodePudding user response:

1. Static constants should use static modification;
2. There are structural default to 0, it should have the default parameters (double r=0);
3. Inside the perimeter of the function c1 is what? Can not, only the return that sentence is ok; (in the area of the function similarly)
4. Ask a friend function of the circumference in direct return 2 * PI * ok, a friend function can direct access to the private members; Another function in the same way ()

CodePudding user response:

Reference:
 # include 
using namespace std;

The class Circle
{

Public:

Circle (double r);
Circle (const Circle & amp; C);//copy constructor
~ Circle ();

Void setRadius (double r);
Double getRadius ();
Double Circumference ();
Double area ();
Friend double fCircle_L (Circle & amp; R);
Friend double fCircle_S (Circle & amp; R);
Private:
The static const double PI;//=3.1415;
double radius;//radius
};

Const double Circle: : PI=3.1415;

Circle: : Circle (double r=0)
{
The radius=r;
Cout<& lt;" The Constructor run "& lt; }

Circle: : Circle (const Circle & amp; C)
{
The radius=c.r adius;
Cout<& lt;" CopyConstructor run "& lt; }

Circle: : ~ Circle ()
{
Cout<& lt;" Destructor run "& lt; }

Void Circle: : setRadius (double r)
{
The radius=r;
}

Double Circle: : getRadius ()
{
Return the radius.
}

Double Circle: : Circumference ()
{
Return 2 * PI * radius;
}

Double Circle: : area ()
{
Radius, return PI * * radius;
}

Double fCircle_L (Circle & amp; R)
{
Return 2 * I * r.r r.P adius;
//return r.C ircumference ();
}

Double fCircle_S (Circle & amp; R)
{
Return r.P I * r.r adius * r.r adius;
//return of state Richard armitage rea ();
}

Int main (void)
{
Double r;
Cin & gt;> r;

Circle c1;
C1. SetRadius (r);
CoutCout
Circle the c2 (c1);
Cout & lt; Cout & lt;
return 0;
}
  • Related