+ -
当前位置:首页 → 问答吧 → 求懂得人修改下!

求懂得人修改下!

时间:2011-12-05

来源:互联网

#include<iostream>
#include<cmath>
using namespace std;
class point
{
public:
int x,y;
point()
{
cout<<"请输入两点的坐标"<<endl;
cin>>x>>y;
}
};

class Line:private point
{
public:
Line():s1(),s2()
{};

show_length()
{
cout<<"此线段的长度是"<<sqrt((s2.y-s1.y)*(s2.y-s1.y)+(s2.x-s1.x)*(s2.x-s1.x))<<endl;
};

show_xl()
{
cout<<"斜率是"<<(s2.y-s1.y)/(s2.x-s1.x)<<endl;
};

private:
point s1,s2;
};

void main()
{
Line L1;
L1.show_xl();
L1.show_length();
}

这个程序怎么改才能在定义L1对象后运行程序后只需要输入两个值就可以了??
求高手解答,可以适当改下程序!

作者: s_april_s   发布时间: 2011-12-05

好多错误啊
C/C++ code
class point
{
public:
    int x,y;
    point(const int n1 = 0,const int n2 = 0):x(n1),y(n2)
    {
    }
};

class Line:public point
{
public:
    Line(const point p1,const point p2):s1(p1),s2(p2)
    {};

    void show_length()
    {
        cout<<"此线段的长度是"<<sqrt((double)(s2.y-s1.y)*(s2.y-s1.y)+(double)(s2.x-s1.x)*(s2.x-s1.x))<<endl;
    };

    void show_xl()
    {
        cout<<"斜率是"<<(double)(s2.y-s1.y)/(double)(s2.x-s1.x)<<endl;
    };

private:
    point s1,s2;
};



int main()
{
    int x1,y1,x2,y2;
    cout<<"请输入第一点的坐标"<<endl;
    cin>>x1>>y1;
    point p1(x1,y1);
    cout<<"请输入第二点的坐标"<<endl;
    
    cin>>x2>>y2;
    point p2(x2,y2);
    Line L1(p1,p2);
    L1.show_length();
    L1.show_xl();
    system("pause");
    return 0;
}

作者: riyueming184   发布时间: 2011-12-05