填空题
[说明] 设计一个普通函数distance (Point &p1,Point &p2),用于计算p1和p2点之间的距离。本程序执行结果如下:(2,2)与(5,5)之间距离=4.24264
# include < iostream. h >
# include < math. h >
class Point
{
int x, y;
public:
Point(int i, int j) { (1)
int getx( ) { return x;}
int gety( ) { return y; }
void disp( )
{
(2)
}
};
float distance( Point &p1, Point &p2 )
{
float d;
(3)
return d;
}
void main( )
{
(4)
p1. disp ( ); cout < <“与”; p2. diap( );
cout< <“之间距离=” < <distance (p1,p2) < <end1;
}
【参考答案】
x=i; y=j;