Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a class Line that implements a line, which is represented by the formula

ID: 3658801 • Letter: D

Question

Design a class Line that implements a line, which is represented by the formula y = ax+b. Your class should store a and b as double member variables. Write a member function intersect(?) that returns the x coordinate at which this line intersects line ?. If the two lines are parallel, then your function should throw an exception Parallel. Write a C++ program that creates a number of Line objects and tests each pair for intersection. Your program should print an appropriate error message for parallel lines.

Explanation / Answer

#include #include #include using namespace std; class Line{ double a,b; public: Line(); Line(double,double); void seta(double); void setb(double); double geta(); double getb(); double intersect(Line); }; Line::Line(){ a=0;b=0; } Line::Line(double A,double B){ a=A; b=B; } void Line::seta(double A){a=A;} void Line::setb(double B){b=B;} double Line::geta(){return a;} double Line::getb(){return b;} double Line::intersect(Line L){ try{ if (a==L.geta()){ throw a; } else{ return ((L.getb()-b)/(a-L.geta())); } } catch( double Parallel){ couty; Line Three(x,y); cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote