用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - c++代码库

两点成线

2017-08-03 作者: 芙蓉妹妹举报

[c++]代码库

#include<iostream>
using namespace std;
class Point
{
public:
    double x,y;
    Point(double a,double b)
    {
        x=a;
        y=b;
        cout<<"Point : ("<<x<<", "<<y<<") is created."<<endl;
    }
    Point()
    {
        x=y=0;
        cout<<"Point : ("<<x<<", "<<y<<") is created."<<endl;
    }
    Point (const Point &p)
    {
        x=p.x;
        y=p.y;
        cout<<"Point : ("<<x<<", "<<y<<") is copied."<<endl;
    }
    ~Point()
    {
        cout<<"Point : ("<<x<<", "<<y<<") is erased."<<endl;
    }
    void show ()
    {
        cout<<"Point : ("<<x<<", "<<y<<")"<<endl;
    }
};
class Line
{
private:
    Point m,n;
public:
    void SetLine (double a1,double b1,double a2,double b2)
    {
        m.x=a1;
        m.y=b1;
        n.x=a2;
        n.y=b2;
    }
    Line (Point &a,Point &b):m(a),n(b)
    {
        cout<<"Line : ("<<m.x<<", "<<m.y<<") to ("<<n.x<<", "<<n.y<<") is created."<<endl;
    }
    Line(double a1=0,double b1=0,double a2=0,double b2=0):m(a1,b1),n(a2,b2)
    {
         //m.x=m.y=n.x=n.y=0;
        cout<<"Line : ("<<m.x<<", "<<m.y<<") to ("<<n.x<<", "<<n.y<<") is created."<<endl;
    }
    ~Line()
    {
        cout<<"Line : ("<<m.x<<", "<<m.y<<") to ("<<n.x<<", "<<n.y<<") is erased."<<endl;
    }
    double show()
    {
        cout<<"Line : ("<<m.x<<", "<<m.y<<") to ("<<n.x<<", "<<n.y<<")"<<endl;
    }
};
int main()
{
    char c;
    int num, i;
    double x1, x2, y1, y2;
    Point p(1, -2), q(2, -1), t;
    t.show();
    std::cin>>num;
    Line line[num];
    for(i = 0; i <num; i++)
    {
        std::cout<<"=========================\n";
        std::cin>>x1>>c>>y1>>x2>>c>>y2;
        line[i].SetLine(x1, y1, x2, y2);
        line[i].show();
    }
    std::cout<<"=========================\n";
    Line l1(p, q), l2(p, t), l3(q, t), l4(t, q);
    l1.show();
    l2.show();
    l3.show();
    l4.show();
}


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...