问题及代码:
/*
*copyright(c) 2014,烟台大学计算机学院
*All rights reserved
*文件名称:test.cpp
*作者:杨昊
*版本:v6.0
*问题描述:成员函数、友元函数和一般函数有区别
*输入描述:无
*程序输出:无
*/
#include<iostream>
#include<cmath>
using namespace std;
class Point
{
private:
double x;
double y;
public:
Point(double xx=0,double yy=0):x(xx),y(yy){}
double getx()
{
return x;
}
double gety()
{
return y;
}
};
double changdu(Point &t1,Point &t2)
{
return sqrt((t1.getx()-t2.getx())*(t1.getx()-t2.getx())+(t1.gety()-t2.gety())*(t1.gety()-t2.gety()));
}
int main()
{
Point a(1,2),b(3,4);
cout<<changdu(a,b)<<endl;
}
结果及总结: