Understanding classes

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2004
Posts: 1
Reputation: paulm is an unknown quantity at this point 
Solved Threads: 0
paulm paulm is offline Offline
Newbie Poster

Understanding classes

 
0
  #1
Aug 9th, 2004
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)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC