C++一个圆类,要求定义构造函数(以半径为参数,缺省值为0,周长和面积在构造函数中生成)和复制构造函数
属性为半径(radius)、圆周长和面积,操作为输入半径并计算周长、面积,输出半径、周长和面积。如何正确输出?#include<iostream>usingnamespa...
属性为半径(radius)、圆周长和面积,操作为输入半径并计算周长、面积,输出半径、周长和面积。如何正确输出?
#include<iostream>
using namespace std;
const double PI=3.141593;
class Circle{
public:
Circle(float r);
float circumference();
float area();
private:
float radius;
};
Circle::Circle(float r){
radius=r;
}
float Circle::circumference(){
return 2*PI*radius;
}
float Circle::area(){
return PI*radius*radius;
}
int main(){
float radius;
cout<<"Enter the radius:";
cin>>radius;
Circle circle(radius);
float circumference=Circle.circumference;
cout<<"Circumference is "<<circumference<<endl;
float area=Circle.area;
cout<<"Area is "<<area<<endl;
return 0;
} 展开
#include<iostream>
using namespace std;
const double PI=3.141593;
class Circle{
public:
Circle(float r);
float circumference();
float area();
private:
float radius;
};
Circle::Circle(float r){
radius=r;
}
float Circle::circumference(){
return 2*PI*radius;
}
float Circle::area(){
return PI*radius*radius;
}
int main(){
float radius;
cout<<"Enter the radius:";
cin>>radius;
Circle circle(radius);
float circumference=Circle.circumference;
cout<<"Circumference is "<<circumference<<endl;
float area=Circle.area;
cout<<"Area is "<<area<<endl;
return 0;
} 展开
展开全部
改成
float circumference=Circle.circumference();
cout<<"Circumference is "<<circumference<<endl;
float area=Circle.area();
cout<<"Area is "<<area<<endl;
return 0;
}
再试试……
float circumference=Circle.circumference();
cout<<"Circumference is "<<circumference<<endl;
float area=Circle.area();
cout<<"Area is "<<area<<endl;
return 0;
}
再试试……
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |