Advertisement
Waliul

Line (Shajed)

Jun 8th, 2021
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class Line
  5. {
  6.     double x1, y1, x2, y2;
  7. public:
  8.     Line()
  9.     {}
  10.     Line(double _x1, double _y1, double _x2, double _y2)
  11.     {
  12.         x1 = _x1, y1 = _y1, x2 = _x2, y2 = _y2;
  13.     }
  14.     double getSlope()
  15.     {
  16.         double sl;
  17.         sl = (y2 - y1) / (x2 - x1);
  18.         if((x2 - x1) == 0)
  19.             cout<<"The line is parallel to Y.";
  20.         return sl;
  21.     }
  22.     double getInsectofYaxis()
  23.     {
  24.         double m, i, j, k, n;
  25.         m = getSlope();
  26.         i = m * (-1 * x1);
  27.         i += y1;
  28.         return i;
  29.     }
  30.     bool CheckColinear(double x, double y)
  31.     {
  32.         double m, i, j, k, n;
  33.         m = getSlope();
  34.         i = y - y1;
  35.         j = x - x1;
  36.         k = m * j;
  37.         if(i == k)
  38.             return true;
  39.         return false;
  40.     }
  41. };
  42.  
  43. int main()
  44. {
  45.     Line line1(2, 3, 6, 4);
  46.     cout<<line1.getSlope()<<endl;
  47.     cout<<line1.getInsectofYaxis()<<endl;
  48.     bool ck = line1.CheckColinear(4, 3.5);
  49.     if(ck == false)
  50.         cout<<"The point doesn't exists on the line.\n";
  51.     else
  52.         cout<<"The point exists on the line!!\n";
  53.     return 0;
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement