MainWindow.xaml.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. namespace LR4
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для MainWindow.xaml
  19. /// </summary>
  20. public partial class MainWindow : Window
  21. {
  22. public MainWindow()
  23. {
  24. InitializeComponent();
  25. Fun.ItemsSource = new List<string>()
  26. {
  27. "+", "-", "/", "*", "x^y", "√", "%", "log", "sin", "ctg"
  28. };
  29. }
  30. private void Result(object sender, RoutedEventArgs e)
  31. {
  32. int a = Convert.ToInt32(x1.Text);
  33. int b = Convert.ToInt32(x2.Text);
  34. int sel = Fun.SelectedIndex;
  35. switch (sel)
  36. {
  37. case 0:
  38. result.Text = Plus(a, b).ToString();
  39. break;
  40. case 1:
  41. result.Text = Minus(a, b).ToString();
  42. break;
  43. case 2:
  44. result.Text = Divide(a, b).ToString();
  45. break;
  46. case 3:
  47. result.Text = Multiply(a, b).ToString();
  48. break;
  49. case 4:
  50. result.Text = Power(a, b).ToString();
  51. break;
  52. case 5:
  53. result.Text = Root(a).ToString();
  54. break;
  55. case 6:
  56. result.Text = Percent(a, b).ToString();
  57. break;
  58. case 7:
  59. result.Text = Log(a, b).ToString();
  60. break;
  61. case 8:
  62. result.Text = Sin(a).ToString();
  63. break;
  64. case 9:
  65. result.Text = Ctg(a, b).ToString();
  66. break;
  67. default:
  68. MessageBox.Show("Выберите функцию");
  69. break;
  70. }
  71. }
  72. #region Функции
  73. static public double Plus(double a, double b)
  74. {
  75. return a + b;
  76. }
  77. static public double Minus(double a, double b)
  78. {
  79. return a - b;
  80. }
  81. static public double Multiply(double a, double b)
  82. {
  83. return a * b;
  84. }
  85. static public double Divide(double a, double b)
  86. {
  87. return a / b;
  88. }
  89. static public double Power(double a, double b)
  90. {
  91. return Math.Pow(a, b);
  92. }
  93. static public double Root(double a)
  94. {
  95. return Math.Sqrt(a);
  96. }
  97. static public double Percent(double a, double b)
  98. {
  99. return a / 100 * b;
  100. }
  101. static public double Log(double a, double b)
  102. {
  103. return Math.Log(a, b);
  104. }
  105. static public double Sin(double a)
  106. {
  107. return Math.Sin(a);
  108. }
  109. static public double Ctg(double a, double b)
  110. {
  111. return Math.Cos(a) / Math.Sin(b);
  112. }
  113. #endregion
  114. private void Fun_SelectionChanged(object sender, SelectionChangedEventArgs e)
  115. {
  116. if (Fun.SelectedItem.ToString() == "sin" || Fun.SelectedItem.ToString() == "√")
  117. {
  118. x2.Visibility = Visibility.Collapsed;
  119. }
  120. else
  121. {
  122. x2.Visibility = Visibility.Visible;
  123. }
  124. }
  125. }
  126. }