Filage

lab5

Oct 20th, 2023
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. double TakeNum(const int MIN, const int MAX) {
  7.     const string ERROR_CHOISE = "Проверьте корректность введнных данных!\n";
  8.     bool isIncorrect;
  9.     double num;
  10.     do {
  11.         isIncorrect = false;
  12.         cin >> num;
  13.         if (cin.fail()) {
  14.             isIncorrect = true;
  15.             cout << ERROR_CHOISE;
  16.             cin.clear();
  17.             while (cin.get() != '\n');
  18.         }
  19.         if (!isIncorrect && cin.get() != '\n') {
  20.             cin.clear();
  21.             while (cin.get() != '\n');
  22.             cout << ERROR_CHOISE;
  23.             isIncorrect = true;
  24.         }
  25.         if (!isIncorrect && (num < MIN || num > MAX)) {
  26.             isIncorrect = true;
  27.             cout << ERROR_CHOISE;
  28.         }
  29.     } while (isIncorrect);
  30.     return num;
  31. }
  32.  
  33. int main() {
  34.     setlocale(LC_ALL, "Rus");
  35.     double x, y;
  36.     int R2 = 2, R1 = 1;
  37.  
  38.     cout << "Вариант 6\n";
  39.  
  40.     cout << "Задание 1.6\n";
  41.         cout << "Введите X\n";
  42.         x = TakeNum(-10000, 10000);
  43.         if (x > 7)
  44.             x *= 2;
  45.         cout << "X = " << x << '\n';
  46.  
  47.     cout << "Задание 2.6 \n";
  48.         cout << "Введите X, Y\n";
  49.         x = TakeNum(-10000, 10000);
  50.         y = TakeNum(-10000, 10000);
  51.         if ((pow(x, 2) + pow(y, 2)) == 1)
  52.             cout << "На границе\n";
  53.         else if((pow(x, 2) + pow(y, 2)) < 1)
  54.             cout << "Да\n";
  55.         else
  56.             cout << "Нет\n";
  57.  
  58.     cout << "Задание 3.6\n";
  59.         cout << "Введите X\n";
  60.         x = TakeNum(-10000, 10000);
  61.         if (x <= -1)
  62.             cout << (y = cos(pow(x, 2))) << '\n';
  63.         else if (x >= 3)
  64.             cout << (y = 2 / x) << '\n';
  65.         else
  66.             cout << (y = -fabs(x)) << '\n';
  67.  
  68.     cout << "Задание 4.6\n";
  69.         cout << "Введите X\n";
  70.         x = TakeNum(-10000, 10000);
  71.         if (x <= -6 && x >= -7)
  72.             cout << "y = 1";
  73.         else if (x > -6 && x <= -4)
  74.             cout << "y = " << (y = -0.5 * x - 2);
  75.         else if (x > -4 && x <= 0)
  76.             cout << "y = " << (y = sqrt(R2 * R2 - pow((-2 - x), 2)));
  77.         else if (x > 0 && x < 2)
  78.             cout << "y = " << (y = -sqrt(R1 * R1 - pow((1 - x), 2)));
  79.         else if (x >= 2 && x <= 3)
  80.             cout << "y = " << (y = -x + 2);
  81.         else
  82.             cout << "Нет значений";
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment