Advertisement
Balda

Ветвление и функции, возвращающие 1 результат

Jan 14th, 2014
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. float max(float x, float y, float z);
  7. float min(float x, float y, float z);
  8. float SystemOfTheEquations(float a1, float b1, float c1, float a2, float b2, float c2);
  9. float condition(float a, float b);
  10.  
  11. int main()
  12. {
  13.     setlocale(LC_ALL, "Russian");
  14.     float x, y, z, a, b, a1, a2, b1, b2, c1, c2;
  15.     cout << "X: ";
  16.     cin >> x;
  17.     cout << "Y: ";
  18.     cin >> y;
  19.     cout << "Z: ";
  20.     cin >> z;
  21.     cout << "Мин: " << min(x, y, z) << endl;
  22.     cout << "Макс: " << max(x, y, z) << endl << endl;
  23.     cout << "Параметры первого уравнения: ";
  24.     cin >> a1 >> b1 >> c1;
  25.     cout << "Параметры второго уравнения: ";
  26.     cin >> a2 >> b2 >> c2;
  27.     SystemOfTheEquations(a1, b1, c1, a2, b2, c2);
  28.     cout << endl;
  29.     cout << "A: ";
  30.     cin >> a;
  31.     cout << "B: ";
  32.     cin >> b;
  33.     x = condition(a, b);
  34.     if (x == 0) cout << "Данные не из того промежутка. Решений нет." << endl;
  35.     else cout << "X: " << x << endl;
  36. }
  37.  
  38. float condition(float a, float b)
  39. {
  40.     float x;
  41.     if ((1 <= fabs(a) && (fabs(a) <= 4)))
  42.     {
  43.         if (a > b) x = a + 2 / b + 4;
  44.         else if (a <= b) x = a + b;
  45.         return x;
  46.     }
  47.     else
  48.     {
  49.         return x = 0;
  50.     }
  51.    
  52. }
  53.  
  54. float max(float x, float y, float z)
  55. {
  56.     float max = x;
  57.     if (y > max) max = y;
  58.     if (z > max) max = z;
  59.     return max;
  60. }
  61.  
  62. float min(float x, float y, float z)
  63. {
  64.     float min = x;
  65.     if (y < min) min = y;
  66.     if (z < min) min = z;
  67.     return min;
  68. }
  69.  
  70. float SystemOfTheEquations(float a1, float b1, float c1, float a2, float b2, float c2)
  71. {
  72.     if (fabs(a1 * b2 - a2 * b1) >= 0.0001)
  73.     {
  74.         cout << "x = " << (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1) << '\n';
  75.         cout << "y = " << (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1) << '\n';
  76.     }
  77.     else
  78.     {
  79.         cout << "Условие не выполнено. Решений нет." << endl;
  80.     }
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement