rendered paste body//John Harrison, Assign 11
#include <iomanip>
#include <iostream>
#include <cmath>
using namespace std;
class Point
{
public:
double x,y;
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);
friend ostream& operator<<(ostream&, const Point&);
friend istream& operator>>(istream&, Point&);
Point operator + (Point&);
bool operator == (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 Point::distanceToOrigin()
{
return sqrt(pow(x, 2) + pow(y, 2));
}
double Point::distanceTo(Point p2)
{
return sqrt(pow((getX() - p2.getX()), 2) + pow((getY() - p2.getY()), 2));
}
void Point::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 Point::higherThan(Point p)
{
if(y > p.getY())
return true;
else
return false;
}
ostream& operator<<(ostream& osObj, const Point& p)
{
osObj << "(" << p.x << "," << p.y << ")";
}
istream& operator<<(istream& isObj, Point& p)
{
isObj >> p.x >> p.y;
}
Point Point::operator + (Point& p)
{
Point temp;
temp.x = x + p.x;
temp.y = y + p.y;
return temp;
}
bool Point::operator == (Point& p)
{
Point temp;
if (x == p.x & y == p.y)
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();
}