C++ 设计一个圆类,计算圆的面积和周长。
展开全部
#include<iostream>
using namespace std;
class Circle
{
double radius; //圆的半径
int x,y; //圆心坐标
static const double PI;
public:
Circle(double radius,int x=0,int y=0);
double getArea();
double getCircleLength();
};
const double Circle::PI=3.1415;
Circle::Circle(double radius, int x , int y )
{
this->radius=radius;
this->x=x;
this->y=y;
}
double Circle::getArea()
{
return PI*radius*radius;
}
double Circle::getCircleLength()
{
return 2*PI*radius;
}
int main()
{
Circle c(3.2);
cout<<"圆的面积为: "<<c.getArea()<<endl;
cout<<"圆的周长为: "<<c.getCircleLength()<<endl;
return 0;
}
using namespace std;
class Circle
{
double radius; //圆的半径
int x,y; //圆心坐标
static const double PI;
public:
Circle(double radius,int x=0,int y=0);
double getArea();
double getCircleLength();
};
const double Circle::PI=3.1415;
Circle::Circle(double radius, int x , int y )
{
this->radius=radius;
this->x=x;
this->y=y;
}
double Circle::getArea()
{
return PI*radius*radius;
}
double Circle::getCircleLength()
{
return 2*PI*radius;
}
int main()
{
Circle c(3.2);
cout<<"圆的面积为: "<<c.getArea()<<endl;
cout<<"圆的周长为: "<<c.getCircleLength()<<endl;
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream.h>
#define PI 3.1415926
class Circle{
private:
double point_x,point_y;//圆心
double radius;//半径
public:
Circle(double initial_x = 0.0,double initial_y = 0.0,double initial_r = 1.0){
point_x = initial_x;
point_y = initial_y;
radius = initial_r;
}
~Circle(){
}
double GetArea(){
return(PI*radius*radius);
}
double GetPerimeter(){
return(2*PI*radius);
}
};
void main(){
Circle myCircle = Circle(0,0,10);
cout<<"面积="<<myCircle.GetArea()<<endl;
cout<<"周长="<<myCircle.GetPerimeter()<<endl;
}
#define PI 3.1415926
class Circle{
private:
double point_x,point_y;//圆心
double radius;//半径
public:
Circle(double initial_x = 0.0,double initial_y = 0.0,double initial_r = 1.0){
point_x = initial_x;
point_y = initial_y;
radius = initial_r;
}
~Circle(){
}
double GetArea(){
return(PI*radius*radius);
}
double GetPerimeter(){
return(2*PI*radius);
}
};
void main(){
Circle myCircle = Circle(0,0,10);
cout<<"面积="<<myCircle.GetArea()<<endl;
cout<<"周长="<<myCircle.GetPerimeter()<<endl;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询