您的位置:首页 > 其它

友元函数

2016-04-17 13:10 288 查看
#include <iostream>
#include<cmath>
using namespace std;
class Cpoint
{
private:
double x;
double y;
public:
Cpoint(double xx=0,double yy=0):x(xx),y(yy){}
void setx(double xx);
void sety(double yy);
double putx();
double puty();
friend void showCpoint(Cpoint &a,Cpoint &b);
};
void Cpoint::setx(double xx)
{
x=xx;
}
void Cpoint::sety(double yy)
{
y=yy;
}
double Cpoint::putx()
{
return x;
}
double Cpoint::puty()
{
return y;
}
void showCpoint(Cpoint &a,Cpoint &b)
{
double x=a.x-b.x;
double y=a.y-b.y;
cout<<sqrt(x*x+y*y)<<endl;
}
void show(Cpoint a,Cpoint b)
{
double x=a.putx()-b.putx();
double y=a.puty()-b.puty();
cout<<sqrt(x*x+y*y)<<endl;
}

int main()
{
Cpoint a(3,3),b(1,1);

show(a,b);
showCpoint(a,b);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: