#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;
}
友元函数
最新推荐文章于 2024-06-20 09:00:44 发布