C++编程
#include <iostream>using namespace std;
#define PI 3141592635
class Circle
{
public:
Circle() : _r(0f){}
Circle(double r) : _r(r){}
Circle(const Circle& circle)
{
this->_r = circle_r;
}
void setRadius(double r)
{
this->_r = r;
}
double Area()
{
return PI this->_r this->_r;
}
double Circumference()
{
return 2 PI this->_r;
}
private:
double _r;
};
int main()
{
Circle c1;
double x;
cin >> x;
c1setRadius(x);
cout << "c1面积:" << c1Area() << endl;
cout << "c1周长:" << c1Circumference() << endl;
Circle c2(2 x);
cout << "c2面积:" << c2Area() << endl;
cout << "c2周长:" << c2Circumference() << endl;
Circle c3(c1);
cout << "c3面积:" << c3Area() << endl;
cout << "c3周长:" << c3Circumference() << endl;
return 0;
}
程序是什么问题,你具体说说。我就说说我觉得不妥的地方,你的类中基本就没有用到你设私有成变量a,那还不如把它删了(如果真这样做记得把默认构造函数的a=0改为r=0),然后是你圆的对象obj2的定义那里,
Circle obj2(2x);
里面的2x错了吧,换其他数试试
#include <stdioh>
#define PI 314159
int main(void) {
int r;
printf("请输入圆的半径r(0-10000):");
scanf("%d",&r);
if(r>0&&r<=10000)
printf("半径为%d的圆面积为:%2f\n",r,PIrr); /%2f 控制输出结果保留两位小数/
else
printf("您输入的半径值错误,半径值需在0-10000之内\n");
return 0;
}
执行结果
r超出0-10000时
#include <mathh>
#include <graphicsh> /预定义库函数/
void circlePoint(int x,int y) /八分法画圆程序/
{
circle(320 x20,240 y20,3);
circle(320 y20,240 x20,3);
circle(320-y20,240 x20,3);
circle(320-x20,240 y20,3);
circle(320-x20,240 y20,3);
circle(320-x20,240-y20,3);
circle(320-y20,240-x20,3);
circle(320 y20,240-x20,3);
circle(320 x20,240-y20,3);
}
void MidBresenhamcircle(int r) / 中点Bresenham算法画圆的程序 /
{
int x,y,d;
x=0;y=r;d=1-r; / 计算初始值 /
while(x<y)
{ circlePoint(x,y); / 绘制点(x,y)及其在八分圆中的另外7个对称点 /
if(d<0) d =2x 3; / 根据误差项d的判断,决定非最大位移方向上是走还是不走 /
else
{ d =2(x-y) 5;
y--;
}
x ;
delay(900000);
} / while /
}
main()
{
int i,j,r,graphmode,graphdriver;
detectgraph(&graphdriver,&graphmode);
initgraph(&graphdriver,&graphmode," ");
printf("中点Bresenhamcircle算法画圆的程序\n"); /提示信息/
printf("注意 |r|<=11");
printf("\n输入半径值 r:");
scanf("%d",&r);
printf("按任意键显示图形");
getch();
cleardevice();
setbkcolor(BLACK);
for(i=20;i<=620;i =20) /使用双循环画点函数画出表格中的纵坐标/
for(j=20;j<=460;j )
putpixel(i,j,2);
for(j=20;j<=460;j =20) /使用双循环画点函数画出表格中的横坐标/
for(i=20;i<=620;i )
putpixel(i,j,2);
outtextxy(320,245,"0"); /原点坐标/
outtextxy(320-520,245,"-5");circle(320-520,240,2); /横坐标值/
outtextxy(320 520,245,"5");circle(320 520,240,2);
outtextxy(320-1020,245,"-10");circle(320-1020,240,2);
outtextxy(320 1020,245,"10");circle(320 1020,240,2);
outtextxy(320-1520,245,"-15");circle(320-1520,240,2);
outtextxy(320 1520,245,"15");circle(320 1520,240,2);
outtextxy(320,240-520,"-5");circle(320,240-520,2); /纵坐标值/
outtextxy(320,240 520,"5");circle(320,240 520,2);
outtextxy(320,240-1020,"-10");circle(320,240-1020,2);
outtextxy(320,240 1020,"10");circle(320,240 1020,2);
outtextxy(20,10,"The center of the circle is (0,0) "); /坐标轴左上角显示提示信息/
setcolor(RED); /标记坐标轴/
line(20,240,620,240); outtextxy(320 1520,230,"X");
line(320,20,320,460); outtextxy(330,20,"Y");
setcolor(YELLOW);
MidBresenhamcircle(r);
setcolor(BLUE); /绘制圆/
circle(320,240,r20);
setcolor(2);
getch();
closegraph();
}
以上就是关于圆的程序怎么编程全部的内容,包括:圆的程序怎么编程、编写一个关于圆形的C++程序。、C语言程序编写 输入圆半径r,计算圆面积。ππ=3.14159,结果保留两位小数。r在0到10000内。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)