/*
* 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;
}
运行结果:
(贴图)
心得体会: