Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include using namespace std; class EqualLines: public exception { public: const char * what () const throw(); }; class ParallelLines: public exception { public:

#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; };

//This is the header file which I can`t change.

.cpp file is

// line.cpp // Author:

#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 }

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 prov

ide the

implementation of the

Line

c

lass. You will also need to fill in the declaration and

code for the two exception classes.

You are to submit 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. Do not submit this file.

This is the question help.

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 Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions

Question

Build trust and credibility

Answered: 1 week ago

Question

What did they do? What did they say?

Answered: 1 week ago