您的位置:首页 > 其它

友元函数

2016-06-23 22:26 169 查看
/*

 *copvriqht(c)2016,烟台大学计算机学院

 *All rights reserved.

 *文件名称:test.cpp

 *作者:陈传祯

 *完成日期:2016年6月23日

 *版本号:v1.0

 *

 *问题描述

 *输入描述

 *程序输出
*/

#include <iostream>

#include<cmath>

using namespace std;

class Point

{

public:

    Point(int x=0,int y=0):x(x),y(y){}

    int getX(){return x;}

    int getY(){return y;}

    friend float dist(Point &p1,Point &p2);

private:

    int x,y;

};

float dist(Point &p1,Point &p2)

{

    double x=p1.x-p2.x;

    double y=p1.y-p2.y;

    return static_cast<float>(sqrt(x*x+y*y));

}

int main()

{

    Point myp1(1,1),myp2(4,5);

    cout<<"The distance is:";

    cout<<dist(myp1,myp2)<<endl;

    return 0;

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