Question: C++ CODE: DO NOT ALTER Line.h ONLY ADD CODE TO Line.cpp You are to design a class Line that implements a line in the plane,

C++ CODE:

DO NOT ALTER Line.h ONLY ADD CODE TO Line.cpp

You are to design a class Line that implements a line in the plane, 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 is such a point exists. If there is not a unique such point, the function should throw an appropriate exception.

The two possible exceptional situations are where 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 built-in exception class. Since each exception is very specific and only ever needs a single message, there is no need to use the text's RuntimeException class.

EqualLines should provide the string "The lines are equal: infinite intersection" and ParallelLiines should provide the string "The lines are parallel: no intersection" When either exception is caught, the message should be printed. This will occur in the program that uses the Line class.

You will be provided two files: line.h containing the declarations for all the needed classes; and a partially completed file line.cpp where you should provide the implementation of the Line class. You will also need to fill in the declaration and code for the two exception classes. You are to alter only the Line.cpp file.

In a separate file, you should create a test program that creates a number of Line objects and tests each pair for intersection. You should use this program to test your classes.

Line.h

#include

#include

using namespace std;

class EqualLines: public exception

{

public:

const char * what () const throw();

};

class ParallelLines: public exception

{

public:

const char * what () const throw();

};

class Line {

public:

Line(double slope, double y_intercept): a(slope), b(y_intercept) {};

double intersect(const Line L) const;

private:

double a;

double b;

};

Line.cpp

#include

#include "line.h"

const char * EqualLines::what() const throw()

{

// supply the code below

}

const char *ParallelLines::what() const throw ()

{

// supply the code below

};

double Line::intersect(const Line L) const

{

// supply the code below

}

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!