• 自考新教材-p90_5(2)


    源程序:

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

    class Point
    {
    private:
    double x, y;
    public:
    Point(double a, double b)
    {
    x = a;
    y = b;
    }
    double distance()
    {
    double len;
    len = sqrt(x*x+y*y);
    return len;
    }
    friend double dis_point2(Point &,Point &);
    };

    double dis_point2(Point &s1, Point &s2)
    {
    double t_x = s1.x - s2.x;
    double t_y = s1.y - s2.y;
    double t_xy = sqrt(t_x * t_x + t_y * t_y);
    return t_xy;
    }

    int main()
    {
    Point p1(2.5, 6.3), p2(5.5,9.0);
    cout << "p1到原点的距离为:"<<p1.distance() << endl;
    cout << "p2到原点的距离为:" <<p2.distance() << endl;
    cout << "p1到p2的距离为:"<<dis_point2(p1, p2) << endl;
    system("pause");
    return 1;
    }

    运行结果:

  • 相关阅读:
    php
    php
    linux 网络管理基础 OSI ISO IOS的区别
    Linux 添加交换分区的步骤
    linux 命令
    linux命令
    linux 命令
    linux 命令
    Linux命令
    linux命令- 挂载命令 mount
  • 原文地址:https://www.cnblogs.com/duanqibo/p/12269146.html
Copyright © 2020-2023  润新知