User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,526 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,805 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2058 | Replies: 0
Reply
Join Date: Aug 2004
Posts: 1
Reputation: paulm is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
paulm paulm is offline Offline
Newbie Poster

Understanding classes

  #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)
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 4:16 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC