代码:
#include <iostream.h>
#include <math.h>
class Point
{
public:
 Point(double xx, double yy) { x = xx; y = yy; }
 void Getxy();
 friend double Distance(Point &a, Point &b);
private:
 double x, y;
};
void Point::Getxy()
{
 cout<< "(" << x << ", " << y << ")";
}
double Distance(Point &a, Point &b)
{
 double dx = a.x - b.x;
 double dy = a.y - b.y;
 return sqrt(dx*dx+dy*dy);
}
int main()
{
 Point p1(3.0, 4.0), p2(6.0, 8.0);
 p1.Getxy();
 p2.Getxy();
 double d = Distance(p1, p2);
 cout << "两点之间的距离是:" << d;
 return 0;
}
[提问]其中的Point(double xx, double yy) { x = xx; y = yy; }是什麽意思?在主函数中:Point p1(3.0, 4.0), p2(6.0, 8.0);
可以这样写吗?不是(类名.someone    someone.类成员)



 
											





 
	    

 
	
 
											




