袁辉勇 5=13 友元函数 两点坐标 距离

friend double dist(point  ,  point);

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

class point
{   
  double x,y;
public:
    point(double xx,double yy)   {   x=xx, y=yy;   }
    
    friend double dist(point  ,  point);
};

double dist(point p1,point p2)
     {      return sqrt(  (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)  );      }

int main()
{   int n;
    double x1,x2,y1,y2;
    cin>>n;
    while (n--)
    {          cin>>x1>>y1>>x2>>y2;
        point p1(x1,y1),p2(x2,y2);
        cout<<fixed <<setprecision(3)<< dist(p1,p2)  <<endl;
    }
}



friend double dist(point p1,point p2)    {      return sqrt(  (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)  );      }

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

class point
{   
  double x,y;
public:
    point(double xx,double yy)   {   x=xx, y=yy;   }
    
    friend double dist(point p1,point p2)
     {      return sqrt(  (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)  );      }
};



int main()
{   int n;
    double x1,x2,y1,y2;
    cin>>n;
    while (n--)
    {          cin>>x1>>y1>>x2>>y2;
        point p1(x1,y1),p2(x2,y2);
        cout<<fixed <<setprecision(3)<< dist(p1,p2)  <<endl;
    }
}



类有元 

 friend class test;


#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

class point;

class test
{   public:
       double dist(point,point);      };
       
class point
{   double x,y;

  public:
    point(double xx,double yy)   {   x=xx, y=yy;   }
    
    friend class test;
};


double test::dist(point p1,point p2)
{    return sqrt(  (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)  );  } 
    
int main()
{   int n;    double x1,x2,y1,y2; test t;
    cin>>n;
    while (n--)
    {   cin>>x1>>y1>>x2>>y2;
        point p1(x1,y1),p2(x2,y2);
        cout<<fixed<<setprecision(3)<<t.dist(p1,p2)<<endl;
    }
}






friend double test::dist(point ,  point);
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
class point;

class test
{
  public:
     double dist(point,point);
};

class point
{     double x,y;
  public:
    point(double xx,double yy)   {   x=xx, y=yy;   }
    
friend double  test::  dist(point ,  point);
};

    double test::dist(point p1,point p2)
       {   return sqrt(  (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)  );  }
     
int main()
{   int n;    double x1,x2,y1,y2; test t;
    cin>>n;
    while (n--)
    {   cin>>x1>>y1>>x2>>y2;
        point p1(x1,y1),p2(x2,y2);
        cout<<fixed<<setprecision(3)<<t.dist(p1,p2)<<endl;
    }
}




C++ 文章被收录于专栏

C++谭浩强 冯博强 贾应知 袁辉勇

全部评论

相关推荐

点赞 评论 收藏
分享
asdasdasdasdas:19岁,不容易啊可能升个本会好点,现在学历歧视太严重了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务