展开全部
/ test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#define PI 3.1415962
using namespace std;
class circle
{
private:
int r; //半径
public:
circle() //无参数构造函数以10为半径
{
r=10;
}
circle(double x) //构造函数
{
r=x;
}
double length()
{
return 2*PI*r;
}
double area()
{
return PI*r*r;
}
}
main()
{
double x;
circle a;
cout<<"默认无参数构造函数输出"<<endl;
cout<<"周长"<<a.length()<<endl;
cout<<"面积"<<a.area()<<endl;
cout<<"请输入半径";
cin>>x;
circle b(x);
cout<<"参数构造函数输出"<<endl;
cout<<"周长"<<b.length()<<endl;
cout<<"面积"<<b.area()<<endl;
}
//
#include "stdafx.h"
#include<iostream>
#define PI 3.1415962
using namespace std;
class circle
{
private:
int r; //半径
public:
circle() //无参数构造函数以10为半径
{
r=10;
}
circle(double x) //构造函数
{
r=x;
}
double length()
{
return 2*PI*r;
}
double area()
{
return PI*r*r;
}
}
main()
{
double x;
circle a;
cout<<"默认无参数构造函数输出"<<endl;
cout<<"周长"<<a.length()<<endl;
cout<<"面积"<<a.area()<<endl;
cout<<"请输入半径";
cin>>x;
circle b(x);
cout<<"参数构造函数输出"<<endl;
cout<<"周长"<<b.length()<<endl;
cout<<"面积"<<b.area()<<endl;
}
展开全部
(法1)#include<iostream>
using namespace std;
#define PI 3.1415926
class Circle
{
double r;
public:
Circle(double R=0)
{
r=R;
}
void Get()
{
cout<<"输入圆半径:";
cin>>r;
}
void cal()//计算圆的周长和半径
{
cout<<"周长:"<<2*PI*r<<endl;
cout<<"面积:"<<PI*r*r<<endl;
}
};
void main()
{
Circle C;
C.Get();
C.cal();
}
(法2)
#include<iostream>
using namespace std;
#define PI 3.1415926
void main()
{
double r;
cout<<"输入圆半径:";
cin>>r;
cout<<"周长:"<<2*PI*r<<endl;
cout<<"面积:"<<PI*r*r<<endl;
}
using namespace std;
#define PI 3.1415926
class Circle
{
double r;
public:
Circle(double R=0)
{
r=R;
}
void Get()
{
cout<<"输入圆半径:";
cin>>r;
}
void cal()//计算圆的周长和半径
{
cout<<"周长:"<<2*PI*r<<endl;
cout<<"面积:"<<PI*r*r<<endl;
}
};
void main()
{
Circle C;
C.Get();
C.cal();
}
(法2)
#include<iostream>
using namespace std;
#define PI 3.1415926
void main()
{
double r;
cout<<"输入圆半径:";
cin>>r;
cout<<"周长:"<<2*PI*r<<endl;
cout<<"面积:"<<PI*r*r<<endl;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<iostream>
using namespace std;
int main ()
{float r,c,s,pi;
pi=3.14;
cin>>r;
c=2*pi*r;
s=pi*r*r;
printf("c=%0.2f\n",c);
printf("s=%0.2f\n",s);
system("pause");
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<iostream>
using namespace std;
int main()
{
cout<<"请输入圆的半径:";
int r;
cin>>r;
cout<<"圆的周长是"<<2*3.14*r<<endl;
cout<<"圆的面积是"<<r*r*3.14<<endl;
return 0;
}
using namespace std;
int main()
{
cout<<"请输入圆的半径:";
int r;
cin>>r;
cout<<"圆的周长是"<<2*3.14*r<<endl;
cout<<"圆的面积是"<<r*r*3.14<<endl;
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询