Question: Implement a Line class that uses two points which represent a line. Given: #ifndef LINE_H_ #define LINE_H_ #include #include using namespace std; struct Point{ double

Implement a Line class that uses two points which represent a line. Given:

#ifndef LINE_H_ #define LINE_H_ #include  #include  using namespace std; struct Point{ double x; double y; Point(double a = 0, double b = 0){ x = a; y = b;} void display(ostream& out){ out << "(" << x << "," << y << ")"; } }; class Line{ private: Point p1, p2; public: Line(); Line(Point, Point); void setFirstPoint(Point); void setSecondPoint(Point); Point getFirstPoint() const; Point getSecondPoint() const; bool slope(double& m) const; bool yIntercept(double& b) const; bool isParallel(Line) const; bool isCollinear(Line) const; bool isPerpendicular(Line) const; Point intersect(Line) const; void display(ostream&) const; }; #endif /* LINE_H_ */

Design and implement a classed called Line that has the following fields and methods.

Fields: point p1, p2

Methods;

Line()

-default constructor - initialize points to (0,0) and (1,1)

Line(Point a, Point b)

-constructor - set p1 and p2 to Points a and b respectively.

void setFirstPoint(Point a)

-set p1 to a

void setSecondPoint(Point a)

-set p2 to a

Point getFirstPoint() const

-return a copy of p1

Point getSecondPoint() const

-return a copy of p2

bool slope(double& m) const

-return true is there is a slope, false otherwise

-store the value of the slope in m

bool yIntercept(double& b) const

-return true is there is a y-intercept, false otherwise

-store the value of the y-intercept in b

bool isParallel(Line) const

-return true is the lines are parallel, false otherwise

bool isCollinear(Line) const

-return true is the lines are collinear, false otherwise

bool isPerpendicular(Line) const

-return true is the lines are perpendicular, false otherwise

Point intersect(Line) const

-return the Point where the two lines intersect

-precondition: the lines intersect

void display(ostream&) const

-prints the equation of the line (in slope intercept form) to the output stream

Required: Line.H

Required: Line.cpp (implementation file)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!