Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- class Grid {
- public:
- bool parallel(Grid& line) {
- return line.slope == slope;
- }
- float slope;
- };
- class Segment: public Grid {
- public:
- Segment(float _x1 = 0, float _y1 = 0, float _x2 = 0, float _y2 = 0) {
- x1 = _x1;
- x2 = _x2;
- y1 = _y1;
- y2 = _y2;
- slope = (_y2 - _y1) / (_x2 - _x1);
- length = sqrt(pow(_x2 - _x1, 2) + pow(_y2 - _y1, 2));
- }
- float length, x1, x2, y1, y2;
- };
- class Line: public Grid {
- public:
- Line(float _slope) {
- slope = _slope;
- }
- };
- int main() {
- Line l_one(5);
- Line l_two(5);
- cout << l_one.parallel(l_two) << endl; /* true, they have the same slope */
- Segment s_one(1, 2, 50, 100);
- Segment s_two(-50, -100, 0, 0);
- cout << s_one.parallel(s_two) << endl; /* true, they also have the same slope */
- }
Advertisement
Add Comment
Please, Sign In to add comment