下面程序通过把类Distance声明为类Point的友

下面程序通过把类Distance声明为类Point的友元类来实现计算两点之间的距离。请在下面程序的横线处填上适当字句,以使程序完整。

#include<iostream>
#include<cmath>
using namespace std;
class Point
{
double X,Y;
public:
Point(double x,double y)
{X=x;Y=y;}
____________(1)____________;
};
class Distance
{
public:
double Dis(Point& p1,Point& p2);
{
double t;
____________________(2)___________________;
return t;
}
}
void main()
{
Point p(10,10),q(20,20);
Distance d;
cout<<d.Dis(p,q)<<endl;
}
答案
第1空:friend class Distance
第2空:sqrt ((p1. x-p2. x) *(p1. x-p2. x) + (p1. y-p2. y) *(p1. y-p2. y) )

题目信息

题号:7611
题型:填空题
难度:普通