All pastes #764994 Raw Edit

Something

public text v1 · immutable
·published 2007-11-07 18:58 UTC
rendered paste body
#include <iomanip>
#include <iostream>
#include <cmath>
class Point
{
private:
   double x;
   double y;
public:
   Point()
   {
       x = 0;
       y = 0;
   }
   Point(double ix, double iy)
   {
       x = ix;
       y = iy;
   }
   void setPoint(double, double);
   void showPoint();
   void setX(double);
   void setY(double);
   double getX();
   double getY();
   double distanceToOrigin();
   double distanceTo(Point);
   void quadrant();
   bool higherThan(Point);
};
void Point::setPoint(double nx, double ny)
{
   x = nx;
   y = ny;  
}
void Point::showPoint()
{
   cout << "(" << x << "," << y << ")" << endl;
}
void Point::setX(double ix)
{
   x=ix;
}
void Point::setY(double iy)
{
   y=iy;
}
double Point::getX()
{
   return x;
}
double Point::getY()
{
   return y;
}
double distanceToOrigin(Point p)
{
   return sqrt((x*x + y*y));
}
double distanceTo(Point p2)
{
   return sqrt(pow((x - p2.getX()), 2) + pow((y - p2.getY()), 2));
}
double quadrant()
{
   
   if(x > 0 && y > 0)
		cout << "in quadrant 1" << endl;
   else if(x < 0 && y > 0)
		cout << "in quadrant 2" << endl;
   else if(x < 0 && y < 0)
		cout << "in quadrant 3" << endl;
   else if(x > 0 && y < 0)
		cout << "in quadrant 4" << endl;
   else
   {
		cout << "on an axis" << endl;
   }    
}
bool higherThan(Point p)
{
   if(y > p.getY())
     return true;
   else 
     return false;
}
int main()
{
    Point p1(4,6);
    Point p2(3,3);
    Point p3(-4,0);
    Point p4(3,-2);
    Point p5();
    p5.setPoint(0,-1);
    Point p6=p3;
    p2.showPoint();
    cout << "p2 coords: x = " << p2.getX() << ", y = " << p2.getY() << "." << endl;
    cout << "p3 distance to origin is " << p3.distanceToOrigin() << endl;
    cout << "Distance from p4 to p6 is " << p4.distanceTo(p6) << endl;
    p1.quadrant();
    p2.quadrant();
    p3.quadrant();
    if(p1.higherThan(p2) == 1)
    cout << "p1 is higher than p2.";
    else
    cout << "p2 is higher than p1.";
    if(p3.higherThan(p5) == 1)
    cout << "p3 is higher than p5.";
    else
    cout << "p5 is higher than p3.";
    
    cin.get();
    cin.get();
}