[C++] 两点成线 →→→→→进入此内容的聊天室

来自 , 2019-08-31, 写在 C++, 查看 143 次.
URL http://www.code666.cn/view/96055f5b
  1. #include<iostream>
  2. using namespace std;
  3. class Point
  4. {
  5. public:
  6.     double x,y;
  7.     Point(double a,double b)
  8.     {
  9.         x=a;
  10.         y=b;
  11.         cout<<"Point : ("<<x<<", "<<y<<") is created."<<endl;
  12.     }
  13.     Point()
  14.     {
  15.         x=y=0;
  16.         cout<<"Point : ("<<x<<", "<<y<<") is created."<<endl;
  17.     }
  18.     Point (const Point &p)
  19.     {
  20.         x=p.x;
  21.         y=p.y;
  22.         cout<<"Point : ("<<x<<", "<<y<<") is copied."<<endl;
  23.     }
  24.     ~Point()
  25.     {
  26.         cout<<"Point : ("<<x<<", "<<y<<") is erased."<<endl;
  27.     }
  28.     void show ()
  29.     {
  30.         cout<<"Point : ("<<x<<", "<<y<<")"<<endl;
  31.     }
  32. };
  33. class Line
  34. {
  35. private:
  36.     Point m,n;
  37. public:
  38.     void SetLine (double a1,double b1,double a2,double b2)
  39.     {
  40.         m.x=a1;
  41.         m.y=b1;
  42.         n.x=a2;
  43.         n.y=b2;
  44.     }
  45.     Line (Point &a,Point &b):m(a),n(b)
  46.     {
  47.         cout<<"Line : ("<<m.x<<", "<<m.y<<") to ("<<n.x<<", "<<n.y<<") is created."<<endl;
  48.     }
  49.     Line(double a1=0,double b1=0,double a2=0,double b2=0):m(a1,b1),n(a2,b2)
  50.     {
  51.          //m.x=m.y=n.x=n.y=0;
  52.         cout<<"Line : ("<<m.x<<", "<<m.y<<") to ("<<n.x<<", "<<n.y<<") is created."<<endl;
  53.     }
  54.     ~Line()
  55.     {
  56.         cout<<"Line : ("<<m.x<<", "<<m.y<<") to ("<<n.x<<", "<<n.y<<") is erased."<<endl;
  57.     }
  58.     double show()
  59.     {
  60.         cout<<"Line : ("<<m.x<<", "<<m.y<<") to ("<<n.x<<", "<<n.y<<")"<<endl;
  61.     }
  62. };
  63. int main()
  64. {
  65.     char c;
  66.     int num, i;
  67.     double x1, x2, y1, y2;
  68.     Point p(1, -2), q(2, -1), t;
  69.     t.show();
  70.     std::cin>>num;
  71.     Line line[num];
  72.     for(i = 0; i <num; i++)
  73.     {
  74.         std::cout<<"=========================\n";
  75.         std::cin>>x1>>c>>y1>>x2>>c>>y2;
  76.         line[i].SetLine(x1, y1, x2, y2);
  77.         line[i].show();
  78.     }
  79.     std::cout<<"=========================\n";
  80.     Line l1(p, q), l2(p, t), l3(q, t), l4(t, q);
  81.     l1.show();
  82.     l2.show();
  83.     l3.show();
  84.     l4.show();
  85. }

回复 "两点成线"

这儿你可以回复上面这条便签

captcha