定义一个Cpoint类,使用函数重载的方法定义两个重名函数,分别求出整型数的两点间距离和实型数的两点间距离。有4处错误,实际上是同一个类型错误。程序如下:#include<iostream.h>#include<stdio.h>#include<math.h>class cpoint{pu... 展开
定义一个Cpoint类,使用函数重载的方法定义两个重名函数,分别求出整型数的两点间距离和实型数的两点间距离。有4处错误,实际上是同一个类型错误。程序如下:#include<iostream.h>#include<stdio.h>#include<math.h>class cpoint{public: int Long(int,int);float Long(float,float);};int cpoint::Long(int a,int b) //求两整型数间距离的函数{ int c;c=(a-b)*(a-b);return c;} float cpoint::Long(float a,float b) ////求两实型数间距离的函数{ float c;c=(a-b)*(a-b);return c;}void main() { int x1,x2,y1,y2,x,y,z;//x=(x1-x2)^2,y=(y1-y2)^2,z=x+y(就是距离) float x3,x4,y3,y4,a,b,c;double h;cout<<"请输入两个整型数的坐标x1,y1,x2,y2:\n";cin>>x1;cin>>y1;cin>>x2;cin>>y2;cout<<"两个实型数的坐标x3,y3,x4,y4:\n";cin>>x3;cin>>y3;cin>>x4;cin>>y4;/*************************************** 求整型数的距离 ****************************************/ x=cpoint.Long(x1,x2);//此处表达不合法?!! y=cpoint.Long(y1,y2);z=x+y;h=sqrt(z);//开根 printf("两整型点间的距离为:%d\n",z);/*************************************** 求实型数的距离 ****************************************/ a=cpoint.Long(x3,x4);//x=(x1-x2)^2 b=cpoint.Long(y3,y4);c=a+b;h=sqrt(c);//开根 printf("两实型点间的距离为:%f\n",c);} 收起