Advertisement
Hamikadze

Untitled

Sep 30th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. // LETIINF3.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "cmath"
  6. #include "iostream"
  7.  
  8. double a, b, r;
  9.  
  10. double f_line(double x)
  11. {
  12.     double x1 = 0;
  13.     double y1 = b;
  14.     double x2 = 2 * a;
  15.     double y2 = -b;
  16.     return  ((y1 - y2)*x + (x1*y2 - x2*y1)) / (x1 - x2);
  17. }
  18. double s_line(double x)
  19. {
  20.     double x1 = 2 * a;
  21.     double y1 = -b;
  22.     double x2 = 4 * a;
  23.     double y2 = b;
  24.     return  ((y1 - y2)*x + (x1*y2 - x2*y1)) / (x1 - x2);
  25. }
  26. double get_y(double x)
  27. {
  28.     if (x <= 0)
  29.     {
  30.         return get_y(4 * a - fmod(x, 4 * a));
  31.     }
  32.     else {
  33.         if (x <= 2 * a)
  34.         {
  35.             return  f_line(x);
  36.         }
  37.         else
  38.         {
  39.             if (x <= 4 * a)
  40.             {
  41.                 return s_line(x);
  42.             }
  43.             else
  44.             {
  45.                 return get_y(fmod(x, 4 * a));
  46.             }
  47.         }
  48.     }
  49. }
  50.  
  51. void main()
  52. {
  53.     double x, y;
  54.     std::cout << "a - 1\n";
  55.     //std::cin >> a;
  56.     a = 1;
  57.     std::cout << "b - 1\n";
  58.     //std::cin >> b;
  59.     b = 1;
  60.     std::cout << "x - ";
  61.     std::cin >> x;
  62.  
  63.     y = get_y(x);
  64.     y = y == -0 ? fabs(y) : y;
  65.     std::cout << y << "\n";
  66.     system("PAUSE");
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement