paulm 0 Newbie Poster

I am having difficulty with this problem with setting up the classes. If you could shed some light to get me started that would be great! :rolleyes:


Design a Line class that uses Point objects point.h. Include a slope()
member function that throws an exception for undefined (vertical) slopes.
Add exception specifications to Line and Point, and derive exception class
LineError from the the standard exception class. Use the following program
to test your solution.


// slope.cpp
#include
#include


#include "Line.h"


using namespace std;


int main() {
try {
Point a(3,5);
Point b(6,10);
Point c(3,10);


Line s(a,b);
Line t(a,c);


double s_slope = s.slope();
cout << "Line s has slope " << s_slope << endl;


double t_slope = t.slope();
cout << "Line t has slope " << t_slope << endl;
}
catch (const exception & e) {
cout << e.what() << endl;
return 1;
}


return 0;
}

Output:
Line s has slope 1.66667
Line: undefined slope for xcoords (3,3)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.