Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- class Line
- {
- double x1, y1, x2, y2;
- public:
- Line()
- {}
- Line(double _x1, double _y1, double _x2, double _y2)
- {
- x1 = _x1, y1 = _y1, x2 = _x2, y2 = _y2;
- }
- double getSlope()
- {
- double sl;
- sl = (y2 - y1) / (x2 - x1);
- if((x2 - x1) == 0)
- cout<<"The line is parallel to Y.";
- return sl;
- }
- double getInsectofYaxis()
- {
- double m, i, j, k, n;
- m = getSlope();
- i = m * (-1 * x1);
- i += y1;
- return i;
- }
- bool CheckColinear(double x, double y)
- {
- double m, i, j, k, n;
- m = getSlope();
- i = y - y1;
- j = x - x1;
- k = m * j;
- if(i == k)
- return true;
- return false;
- }
- };
- int main()
- {
- Line line1(2, 3, 6, 4);
- cout<<line1.getSlope()<<endl;
- cout<<line1.getInsectofYaxis()<<endl;
- bool ck = line1.CheckColinear(4, 3.5);
- if(ck == false)
- cout<<"The point doesn't exists on the line.\n";
- else
- cout<<"The point exists on the line!!\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement