943,838 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2897
  • C++ RSS
Aug 9th, 2004
0

Understanding classes

Expand Post »
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)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
paulm is offline Offline
1 posts
since Aug 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: window () is not working at all
Next Thread in C++ Forum Timeline: pop3 server component





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC