level 6
/*************************************************演示一个点类的功能**功能:返回点的x,y坐标,计算两点之间的距离*************************************************/#include
#include
/*--------------------点类---------------------*/class Location{float x,y;public:Location(float a,float b)//构造函数{x=a;y=b;}float get_x()//返回x坐标{return x;}float get_y()//返回Y坐标{return y;}double distance(Location point)//计算点到另一点的距离,参数为另一个点类{float x1,x2,y1,y2;x1=x;y1=y;x2=point.get_x();y2=point.get_y();double dis=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));return dis;}};void main(){int c;Location a(1.0,1.0),b(4.0,5.0);cout<<"A("<
>c;}
2007年06月11日 09点06分
1
level 6
/*************************************************演示一个直线类的功能**功能:返回直线的两点坐标,计算直线的长度*************************************************/#include
#include
/*--------------------点类---------------------*/class Location{float x,y;public:Location(float a,float b)//构造函数{x=a;y=b;}float get_x()//返回x坐标{return x;}float get_y()//返回Y坐标{return y;}double distance(Location point)//计算点到另一点的距离,参数为另一个点类{float x1,x2,y1,y2;x1=x;y1=y;x2=point.get_x();y2=point.get_y();double dis=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));return dis;}};/*--------------------直线类--------------------*/class Line{float x1,y1,x2,y2;public:Line(Location point1,Location point2)//用两点构造一直线{x1=point1.get_x();y1=point1.get_y();x2=point2.get_x();y2=point2.get_y();}Location get_point1()//返回起点坐标{Location a(x1,y1);return a;}Location get_point2()//返回终点坐标{Location a(x2,y2);return a;}double length()//求直线长度的函数{Location a(x1,y1);Location b(x1,y2);double len=a.distance(b);return len;}};void main(){Location point_a(1.0,1.0),point_b(4.0,5.0);Line l(point_a,point_b);Location point1=l.get_point1();//获得起点坐标Location point2=l.get_point2();//获得终点坐标double len=l.length();//获得直线长度cout<<"AB: ("<
>c;}
2007年06月11日 09点06分
2
level 6
/*************************************************演示一个圆类的功能**功能:获得圆的圆心坐标和半径**计算圆的周长和面积,两圆圆心间的距离*************************************************/#include
#include
#define pi 3.14159/*--------------------点类---------------------*/class Location{protected:float x,y;public:Location(float a,float b)//构造函数{x=a;y=b;}float get_x()//返回x坐标{return x;}float get_y()//返回Y坐标{return y;}double distance(Location point)//计算点到另一点的距离,参数为另一个点类{float x1,x2,y1,y2;x1=x;y1=y;x2=point.get_x();y2=point.get_y();double dis=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));return dis;}};/*--------------------圆类:继承了点类---------------------*/class Circle:public Location{float r;public:Circle(float a,float b,float ra):Location(x,y){x=a;y=b;r=ra;}Location get_location()//获得圆心位置{Location a(x,y);return a;}float get_r()//获得半径长度{return r;}double get_girth()//计算周长{double c=2*pi*r;return c;}double get_area()//计算面积{double area=pi*r*r;return area;}double distance(Circle a)//计算两圆圆心间的距离{double dis=Location::distance(a.get_location());return dis;}};void main(){Circle a(1.0,1.0,3.5),b(4.0,5.0,2.1);float x1=a.get_x();float y1=a.get_y();float r1=a.get_r();float x2=b.get_x();float y2=b.get_y();float r2=b.get_r();double g1=a.get_girth();double g2=b.get_girth();double a1=a.get_area();double a2=b.get_area();double dis=a.distance(b);cout<<"A:("<
>c;}
2007年06月11日 09点06分
3
level 1
各个是编程高手阿。。。正好我最近也在学呢。。。教我吧~哦呵呵
2007年06月20日 05点06分
8
level 0
#include
int huiwen(int i);int sushu(int i);void main(){int m,n;cout<<"Please input m:";cin>>m;cout<<"\nPleas input n:";cin>>n;if(m<10||n>32000||m>n)cout<<"\nInput error!";else{for(int i=m,j=0;i<=n;i++)if(huiwen(i)&&sushu(i)){cout<
>n;}int huiwen(int i)//判断一个数是否为回文数{if(i/10000){if((i/10000==i%10)&&(i/1000%10==i%100/10))return 1;else return 0;}else if(i/1000){if((i/1000==i%10)&&(i/100%10==i%100/10))return 1;else return 0;}else if(i/100){if(i/100==i%10)return 1;else return 0;}else if(i/10){if(i/10==i%10)return 1;else return 0;}else return 0;}int sushu(int i)//判断一个数是否为素数{if(i%2==0)return 0;else{for(int j=3;j<=i/3;j+=2)if(i%j==0)return 0;return 1;}}
2007年06月25日 01点06分
10