点到直线的距离c语言程序,求一C++程序:计算点到直线的距离?已知点(X,Y)到直线ax+by+y=0的计算公式为:d=|(ax+by+c)/sqrt(a^2+b^2)| .分别定义一个point类和...
优质解答在Windows XP+VC++6.0下编译通过并正常运行我的测试程序是用默认参数值初始化的当然,你可以改为:Point P(2,3);Line L(1,2,3);其它的都不变懂了么?#include#includeusing namespace std;class Line;//声明类Line,因为Point类中声明友元函数friend dist(Point P,Line L)用到该类.
优质解答
在Windows XP+VC++6.0下编译通过并正常运行
我的测试程序是用默认参数值初始化的
当然,你可以改为:
Point P(2,3);
Line L(1,2,3);
其它的都不变
懂了么?
#include
#include
using namespace std;
class Line;//声明类Line,因为Point类中声明友元函数friend dist(Point P,Line L)用到该类
class Point
{
private:
double x;
double y;
public:
Point(double xx=0,double yy=0)
{
x=xx;
y=xx;
}
friend double dist(Point P,Line L);
};
class Line
{
private:
double a;
double b;
double c;
public:
Line(double aa=1,double bb=1,double cc=1)
{
a=aa;
b=bb;
c=cc;
}
friend double dist(Point P,Line L);
};
double dist(Point P,Line L)
{
double s;
s=(L.a*P.x+L.b*P.y+L.c)/sqrt(L.a*L.a+L.b*L.b);
if(s>0)
return s;
else
return -s;
}
int main()
{
Point P;//这相当于 Point P(0,0);
Line L;//相当于 Line L(1,1,1);
cout
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)