using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace Calculator { /// /// Логика взаимодействия для MainWindow.xaml /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); Fun.ItemsSource = new List() { "+", "-", "*", "/", "x^y", "√", "%", "Log", "sin", "Ctg" }; } private void Result(object sender, RoutedEventArgs e) { int a = Convert.ToInt32(x1.Text); int b = Convert.ToInt32(x2.Text); int sel = Fun.SelectedIndex; switch(sel) { case 0: Res.Text = Plus(a,b).ToString(); break; case 1: Res.Text = Minus(a, b).ToString(); break; case 2: Res.Text = Divide(a, b).ToString(); break; case 3: Res.Text = Multiply(a, b).ToString(); break; case 4: Res.Text = Power(a, b).ToString(); break; case 5: Res.Text = Root(a).ToString(); break; case 6: Res.Text = Percent(a, b).ToString(); break; case 7: Res.Text = Log(a, b).ToString(); break; case 8: Res.Text = Sin(a).ToString(); break; case 9: Res.Text = Ctg(a, b).ToString(); break; default: MessageBox.Show("Выберите функцию"); break; } } #region Функции static public double Plus(double a, double b) { return a + b; } static public double Minus(double a, double b) { return a - b; } static public double Divide(double a, double b) { return a / b; } static public double Multiply(double a, double b) { return a * b; } static public double Power(double a, double b) { return Math.Pow(a, b); } static public double Root(double a) { return Math.Sqrt(a); } static public double Percent(double a, double b) { return a / 100 * b; } static public double Log(double a, double b) { return Math.Log(a, b); } static public double Sin(double a) { return Math.Sin(a); } static public double Ctg(double a, double b) { return Math.Cos(a) / Math.Sin(b); } #endregion private void Fun_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (Fun.SelectedItem.ToString()=="sin" || Fun.SelectedItem.ToString() == "√") { x2.Visibility = Visibility.Collapsed; } else { x2.Visibility= Visibility.Visible; } } } }