第7周项目1 友元函数和一般函数

/*
 *copyright(c) 2016,烟台大学计算机学院
 *All rights reserved
 *文件名称:test.cpp
 *作者:李硕
 *版本:Code::Blocks
 *
 *问题描述:宣告主权
 *输入描述:
 *程序输出:
*/

#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){}
    //请继续写需要的代码
    //CPoint(CPoint &);
    friend void display1(CPoint &,CPoint &);
    //void display2(CPoint &,CPoint &);
};
/*CPoint::CPoint(CPoint &t)
{
    x=t.x;
    y=t.y;
}*/
void display1(CPoint &t1,CPoint &t2)
{
    double t;
    t=sqrt((t2.y-t1.y)*(t2.y-t1.y)+(t2.x-t1.x)*(t2.x-t1.x));
    cout<<"两点间的距离是:"<<t;
}
/*void CPoint::display2(CPoint &t1,CPoint &t2)
{
    double t;
       t=sqrt((t2.y-t1.y)*(t2.y-t1.y)+(t2.x-t1.x)*(t2.x-t1.x));
    cout<<"两点间的距离是:"<<t;
}*/
void display3(int x1,int y1,int x2, int y2)
{
    double t;
    t=sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
    cout<<"两点间的距离是:"<<t;
}
int main( )
{
    CPoint p1(1,2),p2(2,3);

    display1(p1,p2);
    //CPoint p3(p1);
    //CPoint p4(p2);
    display3(1,2,2,3);
       return 0;
}
<img src="https://img-blog.csdn.net/20160418222437186?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值