title: Order: An Analysis on Point Sorting
body: <p>So I've made for myself a point printing class, that is supposed to have the user enter in 2-tuples; that is, x and y, that then prints them back to the user in ^order,^ where order means p1=(x,y)
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;cmath&gt;
  #include &lt;algorithm&gt;
  
  using namespace std;
  
  class Point2D {
  public:
      Point2D();
      Point2D(double a, double b);
  
      double getx();
      double gety();
  
      void setx(double a);
      void sety(double b);
  
      virtual void print();
      virtual void print(int a);
  
      double angle();
  
  private:
      double x;
      double y;
  };
  
  bool operator&lt;( Point2D a , Point2D b );
  
  int main() {
  
      double my_x=-999;
      double my_y=-999;
      string my_color;
      double my_weight;
      vector&lt;Point2D*&gt; points;
  
      cout &lt;&lt; "Welcome to Point Printer! Please insert the x-and y-coordinates for your points and I will print them in sorted order! Just one rule, the point (0,0) is reserved as the terminating point, so when you are done enter (0,0).\n";
  
      while(true)
      {
          cout &lt;&lt; "x = ";
          cin&gt;&gt;my_x;
          cout &lt;&lt; "y = ";
          cin&gt;&gt;my_y;
          if((my_x == 0)&amp;&amp;(my_y==0))
          {
              break;
          }
          points.push_back(new Point2D(my_x, my_y));
      }
      sort(points.begin(), points.end());
  
      cout &lt;&lt; "\n\n";
      cout &lt;&lt; "Your points are\n\n";
  
      for(int i=0;i&lt;points.size();i++)
      {
          cout&lt;&lt;i+1&lt;&lt;": ";
          (*points[i]).print(); cout&lt;&lt;endl; // this is the printing gadget
      }
      for(int i=0; i&lt;points.size(); i++) 
      {
          delete points[i];
      }
      cout &lt;&lt; endl &lt;&lt; endl;
  
      return 0;
  
  }
  
  double Point2D::angle()
  {
      double Angle = atan2(y,x);
      if(Angle &lt; 0)
      {
          return Angle + 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679;
      }
      return Angle;
  }
  
  bool operator&lt; (Point2D a, Point2D b)
  {
      if (a.getx()*a.getx()+a.gety()*a.gety() &lt; b.getx()*b.getx()+b.gety()*b.gety())
      {
          return true;
      }
      else if (a.getx()*a.getx()+a.gety()*a.gety() &gt; b.getx()*b.getx()+b.gety()*b.gety())
      {
          return false;
      }
      if (a.getx()*a.getx()+a.gety()*a.gety() ==b.getx()*b.getx()+b.gety()*b.gety())
      {
          if (a.angle() &lt; b.angle())
          {
              return true;
          }
          else if (a.angle() &gt; b.angle())
          {
              return false;
          }
      }
      return true;
  }
  
  Point2D::Point2D() { x = 0; y = 0; return;}
  
  Point2D::Point2D(double a, double b) { x = a; y = b; return;}
  
  double Point2D::getx() { return x;}
  double Point2D::gety() { return y;}
  
  void Point2D::setx(double a) { x = a; return; }
  void Point2D::sety(double b) { y = b; return; }
  
  void Point2D::print() {
      cout&lt;&lt;"("&lt;&lt;x&lt;&lt;","&lt;&lt;y&lt;&lt;")";
      return;
  }
  
  void Point2D::print(int a) {
      print(); cout&lt;&lt;endl;
  }
  </code></pre>
  
  <p>What I'm having trouble with is either one of the following:</p>
  
  <blockquote>
    <p>sort</p>
    
    <p>angle()</p>
    
    <p>operator&lt;(Point2D a, Point2D b)</p>
    
    <p>Something different entirely...</p>
  </blockquote>
  
  <p>In particular, the following points:</p>
  
  <pre><code>x = 1
  y = 2
  x = 2
  y = 3
  x = 1.1
  y = 2.2
  x = -10
  y = 10
  x = -5
  y = -3
  x = -5
  y = 3
  x = 5
  y = -3
  x = 5
  y = 3
  x = 0
  y = 0
  </code></pre>
  
  <p>are not sorted in the correct order.</p>
  
  <p>Any help would be much appreciated. Thank you.</p>