Question: C++ || DO NOT ALTER LINE.H. || Only change line.cpp. You are to design a class Line that implements a line, which is represented by

C++ || DO NOT ALTER LINE.H. || Only change line.cpp.

You are to 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 and write a member function intersect() such that L.intersect(K) returns the x coordinate of the unique point at which lines L and K intersect. If there is not a unique such point, the function should throw an appropriate exception.

Your function should throw an exception if the two lines are the same and hence have an infinite number of common points; or are parallel and hence have no point of intersection. For this, you will need subclasses EqualLines and ParallelLiines of the class RunTimeException (declaration on page 97 of the text). The message part of the exceptions should be "The lines are equal: infinite intersection" for EqualLines and "The lines are parallel: no intersection" for ParallelLiines. When either exception is caught, the messages will be printed. This will occur in the program that uses the Line class. The class methods should not produce any output.

//line.h file

#include using namespace std;

class RuntimeException { // generic run-time exception private: string errorMsg; public: RuntimeException(const string& err) { errorMsg = err; } string getMessage() const { return errorMsg; } };

class EqualLines: public RuntimeException { public:

};

class ParallelLines: public RuntimeException { public:

};

class Line { public: Line(double slope, double y_intercept): a(slope), b(y_intercept) {}; double intersect(const Line L) const throw(ParallelLines, EqualLines); double getSlope() const {return a;}; double getIntercept() const {return b;}; // return the y-coordinate of the point with x-coordinate z: double get_y(double z) const; private: double a; double b; };

//line.cpp file

// Programmer: // Last modification date:

#include #include "line.h"

double Line::intersect(const Line L) const throw(ParallelLines, EqualLines) { }

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!