Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is for C++ Implement a Line class that uses two points which represent a line. Given: #ifndef LINE_H_ #define LINE_H_ #include #include using namespace

This is for C++

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

Deliverables

Line.h

Line.cpp

testLine.cpp - systematically create functions to test all functions created in your Line class. (minimum 3 tests per function)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions