c++第三次作业

来源:互联网 发布:怎样进入淘宝店铺 编辑:程序博客网 时间:2024/06/06 21:05
#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 juli1(CPoint p);        friend void juli2(CPoint p1,CPoint p2);        double getx(){return x;}        double gety(){return y;}    };    void CPoint::juli1(CPoint p)    {        double s=sqrt((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y));            cout<<"两点的距离为:"<<s<<endl;    }    void juli2(CPoint p1, CPoint p2)    {        double s=sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));            cout<<"两点的距离为"<<s<<endl;        }    void juli3(CPoint p1,CPoint p2)    {        double s=sqrt((p1.getx()-p2.getx())*(p1.getx()-p2.getx())+(p1.gety()-p2.gety())*(p1.gety()-p2.gety()));            cout<<"两点的距离为:"<<s<<endl;        }        int main()    {        CPoint p1,p2(3,3);      cout<<"以成员函数求距离:"<<endl;      p1.juli1(p2);      cout<<"以友元函数求距离:"<<endl;      juli2(p1, p2);      cout<<"以一般函数求距离:"<<endl;      juli3(p1,p2);      return 0;    }  

0 0
原创粉丝点击