求c++编程题,考试!!急需!!!

2024-11-24 01:26:46
推荐回答(2个)
回答1:

#include
#include
class Point
{
private:
float x, y;
public:
Point(float xx, float yy)
{ x=xx; y=yy; }
float GetX(){ return x; }
float GetY(){ return y; }
friend float distance(Point&, Point&);
};
float distance(Point& a, Point& b)
{
float dx = a.x - b.x;
float dy = a.y - b.y;
cout<<"用友元函数 distance().显示两点的坐标 : \n ";
cout< return sqrt(dx*dx+dy*dy);
}
void main()
{
float d;
Point p1(10.5, 20.5), p2(2.5, 6.5);
d=distance(p1, p2);
cout<<" 两点的距离 : d = "<}

回答2:

C++忘得差不多了,要做的话还要看书。
哎,再加点分,我就更有动力了。