Advertisement
RobertDeMilo

YB2.12 Общие рекомендации по декомпозиции программы и написанию юнит тестов

Oct 30th, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     double a, b, c, D, x1, x2;
  9.     cin >> a >> b >> c;
  10.  
  11.     D = b * b - 4 * a * c;
  12.  
  13.     if ((a == 0 && c == 0) || (b == 0 && c == 0))
  14.     {
  15.         cout << 0;
  16.     }
  17.     else if (a == 0)
  18.     {
  19.         cout << -(c / b);
  20.     }
  21.     else if (b == 0)
  22.     {
  23.         cout << " ";
  24.     }
  25.     else if (c == 0)
  26.     {
  27.         cout << 0 << " " << -(b / a);
  28.     }
  29.     else if (D < 0)
  30.     {
  31.         cout << " ";
  32.     }
  33.     else if (D == 0)
  34.     {
  35.         x1 = ((-1 * b) + sqrt(D)) / (2 * a);
  36.         cout << x1;
  37.     }
  38.     else if (D > 0)
  39.     {
  40.         x1 = ((-1 * b) + sqrt(D)) / (2 * a);
  41.         x2 = ((-1 * b) - sqrt(D)) / (2 * a);
  42.         cout << x1 << " " << x2;
  43.     }
  44. }
  45.  
  46. //#include<iostream>
  47. //#include<cmath>
  48. //
  49. //using namespace std;
  50. //
  51. //void SolveQuadraticEquation(double a, double b, double c)
  52. //{
  53. //
  54. //}
  55. //void SolveLinearEquation(double b, double c)
  56. //{
  57. //  // b * x + c = 0
  58. //  if (b != 0)
  59. //  {
  60. //      cout << -c / b;
  61. //  }
  62. //}
  63. //
  64. //int main()
  65. //{
  66. //  double a, b, c;
  67. //  cin >> a >> b >> c;
  68. //
  69. //  if (a != 0)
  70. //  {
  71. //      SolveQuadraticEquation(a, b, c);
  72. //  }
  73. //  else
  74. //  {
  75. //      SolveLinearEquation(b, c);
  76. //  }
  77. //  return 0;
  78. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement