填空题 [说明] 设计一个普通函数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) {{{U}} (1) {{/U}} int getx( ) { return x;} int gety( ) { return y; } void disp( ) { {{U}} (2) {{/U}} } }; float distance( Point &p1, Point &p2 ) { float d; {{U}}(3) {{/U}} return d; } void main( ) { {{U}} (4) {{/U}} p1. disp ( ); cout < <“与”; p2. diap( ); cout< <“之间距离=” < <distance (p1,p2) < <end1; }
  • 1、
【正确答案】 1、x=i; y=j;    
【答案解析】
clout< <"(" < d = sqrt ( (p1. getx( ) - p2. getx( ) ) * ( p1. getx( ) -
p2. getx( ) ) + (p1. gety( ) - p2. gety( ) ) * ( p1. gety
() - p2. gety( ) );
Point p1(2,2) ,p2(5,5);