Advertisement
Proff_Ust

Lab1_new

Dec 25th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3.  
  4. using namespace std;
  5. class Tline
  6. {
  7. private:
  8.     float a,b,c;
  9. public:
  10.     Tline()
  11.     {
  12.         a = 0;
  13.         b = 0;
  14.         c = 0;
  15.     }
  16.  
  17.     Tline(float newa, float newb, float newc)
  18.     {
  19.         a = newa;
  20.         b = newb;
  21.         c = newc;
  22.     }
  23.  
  24.     int printLine()
  25.     {
  26.         if((this->b>=0)&&(this->c>=0))
  27.             cout<<this->a<<"x+"<<this->b<<"y+"<<this->c<<"=0"<<endl;
  28.         else
  29.             if((this->b<0)&&(this->c>0))
  30.                 cout<<this->a<<"x"<<this->b<<"y+"<<this->c<<"=0"<<endl;
  31.             else
  32.                 if((this->c<0)&&(this->b>0))
  33.                     cout<<this->a<<"x+"<<this->b<<"y"<<this->c<<"=0"<<endl;
  34.                 else
  35.                     cout<<this->a<<"x"<<this->b<<"y"<<this->c<<"=0"<<endl;
  36.  
  37.  
  38.         return 0;
  39.     }
  40.  
  41.     bool checkDot(float x, float y)
  42.     {
  43.         return bool((this->a*x+this->b*y+c)==0);
  44.     }
  45. };
  46.  
  47. int main()
  48. {
  49.     setlocale(LC_ALL,"RU");
  50.     float a, b, c, x, y;
  51.     cout<<"Введите коэффициенты уравнения прямой"<<endl;
  52.     cout<<"a=";
  53.     cin>>a;
  54.     cout<<"b=";
  55.     cin>>b;
  56.     cout<<"c=";
  57.     cin>>c;
  58.     Tline *line = new Tline(a,b,c);
  59.     line->printLine();
  60.     cout<<"Введите координаты точки для проверки принадлежности к прямой"<<endl;
  61.     cout<<"x=";
  62.     cin>>x;
  63.     cout<<"y=";
  64.     cin>>y;
  65.     cout<<line->checkDot(x,y);
  66.     system("pause");
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement