bochkareffsasha

my lab3 inf

Nov 28th, 2021 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. auto findY1ellipse(float x) // Создадим функцию для поиска у эллипса
  7. {
  8.     const float x0 = 11.9012f; // Введем переменные
  9.     const int y0 = 3;
  10.     const int a = 30;
  11.     const int b = 37;
  12.     const int a2 = 900;
  13.  
  14.     double y = b * sqrt(1 - (x - x0) * (x - x0) / a2) + y0;  // выразим у
  15.     y = (int)(y * 10000) / 10000.; //  Округлим для нашей точности в 0.0001
  16.  
  17.  
  18.     return y;
  19. }
  20.  
  21. auto findY2ellipse(float x) // Создадим функцию для поиска у эллипса
  22. {
  23.     const float x0 = 11.9012f; // Введем переменные
  24.     const int y0 = 3;
  25.     const int a = 30;
  26.     const int b = 37;
  27.     const int a2 = 900;
  28.  
  29.     double y = b * sqrt(1 - (x - x0) * (x - x0) / a2);  // выразим у
  30.     y = (int)(y * 10000) / 10000.; //  Округлим для нашей точности в 0.0001
  31.     float y2 = -1*y + y0;
  32.  
  33.     return y2;
  34. }
  35.  
  36. auto findY1circle(float x)
  37. {
  38.     const int x0 = -11;
  39.     const float y0 = -12.3423f;
  40.     const int r2 = 729;
  41.  
  42.     double y = sqrt(r2 - (x - x0)*(x - x0));
  43.     y = (int)(y * 10000) / 10000.; //  Округлим для нашей точности в 0.0001
  44.     return y + y0;
  45. }
  46.  
  47. auto findY2circle(float x)
  48. {
  49.     const int x0 = -11;
  50.     const float y0 = -12.3423f;
  51.     const int r2 = 729;
  52.  
  53.     double y = -1 * sqrt(r2 - (x - x0) * (x - x0));
  54.     y = (int)(y * 10000) / 10000.; //  Округлим для нашей точности в 0.0001
  55.    
  56.     return y + y0;
  57. }
  58.  
  59.  
  60. int main()
  61. {
  62.     setlocale(LC_ALL, "Russian");
  63.  
  64.     for (float x = -18; x <= 20; x += 0.0001)
  65.     {
  66.         float Y1e = findY1ellipse(x);
  67.         float Y2e = findY2ellipse(x);
  68.         float Y1c = findY1circle(x);
  69.         float Y2c = findY2circle(x);
  70.  
  71.         if ((Y1c / Y1e < 1.00001) and (Y1c / Y1e > 0.999999)) {
  72.             cout << "Первая точка:" << endl;
  73.             cout << "координата X = " << x << endl;
  74.             cout << "координата Y = " << Y1e << endl;
  75.             cout << "" << endl;
  76.         }
  77.  
  78.         if ((Y2c / Y2e < 1.00000001) and (Y2c / Y2e > 0.99999999)) {
  79.             cout << "Вторая точка:" << endl;
  80.             cout << "координата X = " << x << endl;
  81.             cout << "координата Y = " << Y2e << endl;
  82.             cout << "" << endl;
  83.             cout << "Работу выполнил Бочкарев А.Н. КЗИ-21-1б" << endl;
  84.         }
  85.  
  86.  
  87.     }
  88.    
  89. }
Add Comment
Please, Sign In to add comment