这道C++编程题怎么做?求两点间的距离,高悬赏,求大神解答

2025-02-25 16:31:44
推荐回答(1个)
回答1:

//#include "stdafx.h"//If the vc++6.0, with this line.
#include 
#include "math.h"
using namespace std;
class CPoint{
    public:
    double x,y;
    friend double GetD(CPoint a,CPoint b);
};
double GetD(CPoint a,CPoint b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main(int argc,char *argv[]){
    CPoint t1,t2;
    cout << "Please enter the coordinates of point 1:";
    cin >> t1.x >> t1.y;
    cout << "Please enter the coordinates of point 2:";
    cin >> t2.x >> t2.y;
    cout << "The distance=" << GetD(t1,t2) << endl;
    return 0;
}