#include #include #include "point.h" /** * @param x latitude location value * @param y longitute location value * @return returns a point in x and y location. * It fills the location information of a point. */ Point* mkpt(int x, int y) { Point *p = new Point(); p->xval = x; p->yval = y; return p; } /** * @param a start point * @param b end point * @return distance between a and b points * It uses Pythagorean theorem to figure out the distance to another point. */ double dist(Point a, Point b) { int xd = a.xval - b.xval; int yd = a.yval - b.yval; return sqrt(xd*xd + yd*yd); } /** * @param a first point * @param b second point * @return new point with a and b location added * It adds the x and y value of point a and b and returns a new point with new location */ Point *add(Point *a, Point *b) { return mkpt(a->xval + b->xval, a->yval + b->yval); } /** * @param a first point * @param b second point * @return new point with a and b location subtracted * It subtracts the x and y value of point a and b and returns a new point with new location */ Point *sub(Point a, Point b) { return mkpt(a.xval - b.xval, a.yval - b.yval); } /** * @param a x value * @param b y value * @param p new point to be made * It moves to point p by adding value of p's x and y to a and b */ void move(Point *p, double a, double b) { p->xval += a; p->yval += b; } /** * @param A point to be printed. * Print the point to standard output. The class ostream is a base class * for output streams of various types. */ void print(Point p) { printf("(%d,%d)", p.xval, p.yval); } /** * @param x first point * @param op operation * @param y second point * @param z third point * Print a line of the form x op y = z, where x, y, and z are points. */ void prline(Point x, char *op, Point y, Point z) { print(x); printf(" %s ", op); print(y); printf(" = "); print(z); printf("\n"); }