Advertisement
programusy

Untitled

Apr 13th, 2023
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15.  
  16. namespace WpfApp3
  17. {
  18. /// <summary>
  19. /// Interaction logic for MainWindow.xaml
  20. /// </summary>
  21. public partial class MainWindow : Window
  22. {
  23. public MainWindow()
  24. {
  25. InitializeComponent();
  26. }
  27.  
  28. private void oblicz_Click(object sender, RoutedEventArgs e)
  29. {
  30. double a = Convert.ToDouble(paramter_a.Text);
  31. double b = Convert.ToDouble(paramter_b.Text);
  32. double c = Convert.ToDouble(paramter_c.Text);
  33.  
  34. if (a != 0) funkcjaKwadratowa(a, b, c);
  35. else if (b != 0) fukncjaLiniowa(b, c);
  36. else rownanie(c);
  37.  
  38. }
  39.  
  40. private void rownanie(double a)
  41. {
  42. komentarz.Content = String.Format("Rozwiazywanie rownania f(x) = {0}", a);
  43.  
  44.  
  45. if (a == 0)
  46. {
  47. out_x1.Content = "inf.";
  48. out_x2.Content = "inf.";
  49. }
  50.  
  51. else
  52. {
  53. out_x1.Content = "brak";
  54. out_x2.Content = "brak";
  55. }
  56. }
  57.  
  58. private void fukncjaLiniowa(double a, double b)
  59. {
  60. komentarz.Content = String.Format("Rozwiazywanie rownania f(x) = {0}x + {1}", a, b);
  61.  
  62. out_x1.Content = (-b) / a;
  63. out_x2.Content = "brak";
  64. }
  65.  
  66. private void funkcjaKwadratowa(double a, double b, double c)
  67. {
  68. komentarz.Content = String.Format("Rozwiazywanie rownania f(x) = {0}x^2 + {1}x + {2}", a, b, c);
  69.  
  70. double delta = (b * b) - (4 * a * c);
  71. if (delta > 0)
  72. {
  73. double x1 = (-b - Math.Sqrt(delta) / (2 * a));
  74. double x2 = (-b + Math.Sqrt(delta) / (2 * a));
  75.  
  76. out_x1.Content = x1;
  77. out_x2.Content = x2;
  78. }
  79.  
  80. else if (delta == 0)
  81. {
  82. out_x1.Content = (-b) / (2 * a);
  83. out_x2.Content = "brak";
  84. }
  85.  
  86. else
  87. {
  88. out_x1.Content = "brak";
  89. out_x2.Content = "brak";
  90. }
  91. }
  92. }
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement