求一道C++题目编程

[复制链接]
查看11 | 回复0 | 2006-3-24 16:15:24 | 显示全部楼层 |阅读模式
#include #include class Point { int x,y; public: Point(int i,int j){x=i;y=j;} friend float distance(Point &p1,Point &p2); void disp() { cout<<"("<<x<<","<<y<<")"; } }; float distance(Point &p1,Point &p2) // 友元函数的实现 { float d; d=sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); return d; } void main() { Point p1(2,2),p2(5,5); p1.disp(); cout<<"与"; p2.disp(); cout<<"之间距离="<<distance(p1,p2)<<endl; }
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行