Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve all the following: You are to design a class Line that implements a line, which is represented by the formula y = ax+b.

Please solve all the following:

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. 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.

I have provided two files bellow : 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 are to submit only the Line.cpp file.

In a separate file, 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

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

#include

#include "line.h"

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

{

} double Line::get_y(double z) const

{ }

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

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions

Question

What is an unadjusted trial balance? An adjusted trial balance?

Answered: 1 week ago

Question

Does the Medicare PPS payment under DRGs reduce costs? Discuss.

Answered: 1 week ago