第七周 项目1-成员函数、友元函数和一般函数有区别(1)外部

来源:互联网 发布:查重软件 编辑:程序博客网 时间:2024/04/27 13:56
<p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">/* *copyright(c) 2014,烟台大学计算机学院 *All rights reserved *文件名称:test.cpp *作者:谭泽纯 *版本:v6.0 * *问题描述:成员函数、友元函数和一般函数有区别</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;"> *输入描述:无 *程序输出:数据</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">*/</p>
#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;}

0 0