negtab

1.19.1 C++

Sep 11th, 2024 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     double x;
  9.     double y;
  10.     bool isTrue;
  11.     bool isNotCorrect;
  12.  
  13.     x = 0.0;
  14.     y = 0.0;
  15.     isTrue = false;
  16.  
  17.     cout << "Это программа считает, принадлежит ли точка множеству D" << endl;
  18.  
  19.     do {
  20.         cout << "Введите координату x от -1.00 до 1.00" << endl;
  21.         isNotCorrect = false;
  22.         cin >> x;
  23.         if (cin.fail())
  24.         {
  25.             isNotCorrect = true;
  26.             cin.clear();
  27.             while (cin.get() != '\n');
  28.             cout << "Пожалуйста, вводите числа" << endl;
  29.         }
  30.     }
  31.     while(isNotCorrect);
  32.  
  33.     do {
  34.         cout << "Введите координату y от -1.00 до 1.00" << endl;
  35.         isNotCorrect = false;
  36.         cin >> y;
  37.         if (cin.fail())
  38.         {
  39.             isNotCorrect = true;
  40.             cin.clear();
  41.             while (cin.get() != '\n');
  42.             cout << "Пожалуйста, вводите числа" << endl;
  43.         }
  44.     }
  45.     while(isNotCorrect);
  46.  
  47.     if( (((y == -1 || y == 0) && (x == 1 || x == -1))) || (y == 1 && x == 0)) // точки краёв зоны D
  48.     {
  49.         isTrue = true;
  50.     }
  51.     else
  52.     {
  53.         if (y < 0 && y > -1) // точки под осью X
  54.         {
  55.             if(x > -1 && x < 1)
  56.             {
  57.                 isTrue = true;
  58.             }
  59.         }
  60.         else // точки над осью x
  61.         {
  62.             if ((abs(y) + abs(x) < 1) || (abs(y) + abs(x) == 1))
  63.             {
  64.                 isTrue = true;
  65.             }
  66.         }
  67.     }
  68.  
  69.  
  70.     if(isTrue)
  71.     {
  72.         cout << "Точка принадлежит области D" << endl;
  73.     }
  74.     else
  75.     {
  76.         cout << "Точка не принадлежит области D" << endl;
  77.     }
  78.     return 0;
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment