OJ:line point 7

#include <iostream>

using namespace std;

class Point{
    double x;
    double y;
    static int m;
    static int n;

public:

    Point(double a,double b):x(a),y(b){m++;n++;}
    Point(double a):x(a),y(a)         {m++;n++;}
    Point():x(0),y(0)                 {m++;n++;}
    Point(const Point &q):x(q.x),y(q.y){n++;m++;}
    double setx(double xx)            {x=xx;return x; }
    double sety(double yy)            {y=yy;return y; }
    double getx()const                     {return x;}
    double gety()const                     {return y;}
    ~Point(){m--;}
    static void showCounter(){cout<<"Current : "<<m<<" points."<<endl;}
    static void showSum()    {cout<<"In total : "<<n<<" points."<<endl;}
};
int Point::m=0;
int Point::n=0;
class Line{
    Point d1;
    Point d2;
    static int p;
    static int q;
public:
    Line():d1(0),d2(0){p++;q++;}
    Line (const Line &d):d1(d.d1),d2(d.d2){p++;q++;}
    Line (Point &a,Point &b):d1(a),d2(b){p++;q++;}
    Line (double a,double b,double c,double d):d1(a,b),d2(c,d){p++;q++;}
    Line &setLine(const Line &d)
    {
        d1.setx(d.d1.getx());
        d1.sety(d.d1.gety());
        d2.setx(d.d2.getx());
        d2.sety(d.d2.gety());
        p++;q++;
        return *this;
    }
    Line &setLine(const Point &a,const Point &b)
    {
        d1.setx(a.getx());
        d1.sety(a.gety());
        d2.setx(b.getx());
        d2.sety(b.gety());
        p++;q++;
        return *this;

    }
    Line setLine(double a,double b,double c,double d)
    {
        d1.setx(a);
        d1.sety(b);
        d2.setx(c);
        d2.sety(d);
        p++;q++;
        return *this;
    }
    ~Line(){p--;}
    static void showCounter(){cout<<"Current : "<<p<<" lines."<<endl;}
    static void showSum()    {cout<<"In total : "<<q<<" lines."<<endl;}
    void readLine()
    {
        char c;
        double x1,y1,x2,y2;
        cin>>x1>>c>>y1>>x2>>c>>y2;
        d1.setx(x1);
        d1.sety(y1);
        d2.setx(x2);
        d2.sety(y2);
    }
};
int Line::p=0;
int Line::q=0;


int main()
{
    int num, i;
    Point p(1, -2), q(2, -1), t;
    t.showCounter();
    t.showSum();
    std::cin>>num;
    Line line[num + 1];
    for(i = 1; i <= num; i++)
    {
        Line *l1, l2;
        l1->showCounter();
        l1->showSum();
        l1 = new Line(p, q);
        line[i].readLine();
        p.showCounter();
        p.showSum();
        delete l1;
        l2.showCounter();
        l2.showSum();
        q.showCounter();
        q.showSum();
    }
    Line l1(p, q), l2(p,t), l3(q,t), l4(l1);
    Line::showCounter();
    Line::showSum();
    Point::showCounter();
    Point::showSum();
    Line *l = new Line[num];
    l4.showCounter();
    l4.showSum();
    delete[] l;
    t.showCounter();
    t.showSum();
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章