## Assignment 1: Points and Lines

Create a class

Pointand a classLine. The Point class deals with points in a Cartesian coordinate system, the class Line deals with Lines in the plane. Recall that a line is determined either by two points or by a point and the slope or by a point and the y-intercept.First, let’s focus on the Point class and figure out its fields and methods.

Fields: x and y coordinate of a point, both double valuesMethods: display, getX, setX, getY, setY as usual. We also might need a method ‘distance’ which computer the distance of the current point to the origin.Here is the declaration of the class Point. Please add comments where appropriate before turning in the assignment:

#include <iostream.h> #include <math.h> #ifndef POINT #define POINT class Point { private: double x, y; // x and y are the (x,y) coordinates of a point public: Point(void); // Constructors public: Point(double, double); public: void setX(double); // Methods public: void setY(double); public: double getX(void); public: double getY(void); public: void display(void); // display method without linefeed public: double distance(void); // distance to origin }; // all method implementations go here and are left as homework #endifAfter the method implementations have been added, we need a test program to test this class. Assuming we have saved our above class as

Point.cpp, a simple test program could look as follows:#include <iostream.h> #include "Point.cpp" int main(void) { Point P, Q(3,3); cout << "The following points are defined \n"; P.display(); cout << "\t"; Q.display(); cout << "\n"; cout << "changing coordinates of point P to (-1, -1)\n"; P.setX(-1); P.setY(-1); P.display(); cout << "\n"; cout << "Distance of P to origin should be sqrt(2): " << P.distance() << "\n"; return 0; }Next, let’s concentrate on the Line class.Recall from your calculus or pre-calculus class that a line is completely defined by:

two points, or the slope and one point, or the slope and the y-intercept Therefore, we have three options for storing enough information to uniquely determine a line - i.e. we will give our class at least three appropriate constructors. Please implement a line class as follows:

Class Name:- Line
Fields:slopeandintercept(double types)Constructors:

Line(void)to initialize slope and intercept to zeroLine(double, double)to initialize a line using slope and y-interceptLine(double, Point)to initialize a line using the slope and a pointLine(Point, Point)to initialize a line using two pointsMethods:

display(void)displays the line in slope-intercept formsetSlope(double)sets the slope of line to the input valuesetIntercept(double)sets the y-intercept of the line to the input valuegetSlope(void)returns the slope of the linegetIntercept(void)returns the y-intercept of the linecontainsPoint(Point)returns 1 if the line contains the input point, 0 otherwiseisPerpendicularTo(Line)returns 1 if the line is perpendicular to the input line, 0 otherwiseisParallelTo(Line)returns 1 if the line is parallel to the input line, 0 otherwiseNote that the Line class needs to know about the Point class. Therefore, the Line class should start as follows:

#include <iostream.h> // needed for the display method #include "Point.cpp" // so that this class knows about Points #ifndef LINE #define LINE // class declaration and implementation here #endifAlso create a small test program to test your line class. To summarize: you must turn in four files for this assignment:

(bgw)

Point.cppcontains the Point class Line.cppcontains the Line class linetst.cpptest program for Line class