C++计算两点距离(定义两个类)一个类是定义点,一个是定义距离.这个程序为什么错了.#include "iostream"using namespace std;class point{float x;float y;friend class distance;public:point(float a,float b){x=a;y=b;}};class
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 22:02:07
C++计算两点距离(定义两个类)一个类是定义点,一个是定义距离.这个程序为什么错了.#include "iostream"using namespace std;class point{float x;float y;friend class distance;public:point(float a,float b){x=a;y=b;}};class
C++计算两点距离(定义两个类)
一个类是定义点,一个是定义距离.这个程序为什么错了.
#include "iostream"
using namespace std;
class point
{
float x;
float y;
friend class distance;
public:
point(float a,float b)
{
x=a;
y=b;
}
};
class distance
{
float result;
public:
distance(const point &A,const point &B)
{
float x1=A.x,x2=B.x,y1=A.y,y2=B.y;
result=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
float getresult()
{
return result;
}
};
int main()
{
float x1,x2,y1,y2;
cout
C++计算两点距离(定义两个类)一个类是定义点,一个是定义距离.这个程序为什么错了.#include "iostream"using namespace std;class point{float x;float y;friend class distance;public:point(float a,float b){x=a;y=b;}};class
汗,改了好久才发现distance不能用,distance是个库函数,该成distan就可以了.
附代码:
#include "iostream"
using namespace std;
class point
{
float x;
float y;
friend class distan;
public:
point(float a,float b)
{
x=a;
y=b;
}
};
class distan
{
float result;
public:
distan(const point &A,const point &B)
{
float x1=A.x,x2=B.x,y1=A.y,y2=B.y;
result=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
float getresult()
{
return result;
}
};
int main()
{
float x1,x2,y1,y2;
cout