vc++相关程序问题

vc++相关程序问题以及其继承和派生应用实践相关问题……谢谢了……

img

#include<iostream>
#include<cmath>
using namespace std;
 
class Point   //坐标点类
{
public:
    const double x,y;
    Point(double x=0.0, double y=0.0): x(x),y(y) {}
 
    double distanceTo(Point p)const    //到指定点的距离
    {
        return sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y)) ;
    }
};
 
class Line   //线段类
{
public:
    const Point p1,p2;  //线段的两个端点
 
    Line(Point p1, Point p2):p1(p1),p2(p2) {}
    double length()const
    {
        return p1.distanceTo(p2);    //线段的长度
    }
};
 
class Line_length    //线段长度类
{
public:
    const Point p1,p2;    //线段的两个顶点
 
    Line_length(Point p1,Point p2):p1(p1),p2(p2) {}
    double length()const  //线段的长度
    {
        return Line(p1, p2).length() ;
    }
};
 
int main()
{
    Line_length L(Point(0.0, 0.0), Point(0.0, 1.0));
    cout<<"线段长度是:"<<L.length()<<endl;
    return 0;
}

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632