954,219 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Understanding classes

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)

paulm
Newbie Poster
1 post since Aug 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You