| | |
Understanding classes
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2004
Posts: 1
Reputation:
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)
![]() |
Similar Threads
- Classes help.. (Python)
- The Philosophy behind C# ???????? (Geeks' Lounge)
- PHP Classes (PHP)
- How to learn Java (Java)
- Extending A Class (Python)
- Help with C++ Classes (C++)
- Understanding Classes (VB.NET)
- Java Expert (Needed) (Java)
Other Threads in the C++ Forum
- Previous Thread: window () is not working at all
- Next Thread: pop3 server component
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





