/*
* Copyright (c) 2011, 煙臺大學計算機學院
* All rights reserved.
* 作 者:王靜
* 完成日期:2013 年 4 月 16 日
* 版 本 號:v1.0
* 輸入描述:
* 問題描述:
* 程序輸出:
* 問題分析:
* 算法設計:略
*/
#include <iostream>
#include <cmath>
using namespace std;
class CPoint
{
public:
CPoint(double xx=0,double yy=0):x(xx),y(yy){}
void distance1(CPoint &a);
friend void distance2(CPoint &a,CPoint &b);
double getx(){return x;}
double gety(){return y;}
private:
int x;
int y;
};
void distance3(CPoint &a,CPoint &b);
void CPoint::distance1(CPoint &a)
{
cout<<sqrt((x-a.x)*(x-a.x)+(y-a.y)*(y-a.y))<<endl;
}
void distance2(CPoint &a,CPoint &b)
{
cout<<sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y))<<endl;
}
void distance3(CPoint &a,CPoint &b)
{
cout<<sqrt((b.getx()-a.getx())*(b.getx()-a.getx())+(b.gety
()-a.gety())*(b.gety()-a.gety()))<<endl;
}
int main()
{
CPoint a(3,5),b(4,7);
a.distance1(b);
distance2(a,b);
distance3(a,b);
// system("pause");
return 0;
}
運行結果:
(貼圖)
心得體會: