一个关于类的问题
写了一个程序,是计算两点之间的距离,可是程序写完之后程序总是报错,又不知道怎么改,先把程序贴出来,大家帮忙看下
#include<iostream>
#include<cmath>
using namespace std;
class point
{
public:
point(float xx=0,float yy=0,float zz=0)
{
x=xx;
y=yy;
z=zz;
}
point(point &p);
float getX(){return x;}
float getY(){return y;}
float getZ(){return z;}
void setpoint(float newX=0,float newY=0,float newZ=0);
void displaypoint();
friend float dis(point &,point &);
private:
float x,y,z;
};
void point::setpoint(float newX,float newY,float newZ)
{
x=newX;
y=newY;
z=newZ;
}
void point::displaypoint()
{
cout<<"The point is"<<"("<<x<<","<<y<<","<<z<<")"<<endl;
}
float dist(point &p1,point &p2)
{
return sqrt((p1.getX-p2.getX)*(p1.getX-p2.getX)+(p1.getY-p2.getY)*(p1.getY-p2.getY)+(p1.getZ-p2.getZ)*(p1.getZ-p2.getZ));
}
void main()
{
point a(1,2,3);
point b(2,3,4);
a.setpoint();
b.setpoint();
cout<<"two points have been created."<<endl;
a.displaypoint();
b.displaypoint();
cout<<"the distance is"<<dist(a,b)<<endl;
}