•
•
•
•
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
![]() |
•
•
Join Date: Aug 2004
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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)
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)
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Extending A Class (Python)
- Help with C++ Classes (C++)
- everything abt container classes (C)
- Understanding Classes (VB.NET)
- Understanding ASP classes (ASP Tutorials)
- Difficulty understanding Object Orientated File Streaming (C++)
- Java Expert (Needed) (Java)
Other Threads in the C++ Forum
- Previous Thread: window () is not working at all
- Next Thread: pop3 server component


Linear Mode