123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- 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
- {
- /// <summary>
- /// Логика взаимодействия для MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- Fun.ItemsSource = new List<string>()
- {
- "+", "-", "*", "/", "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;
- }
- }
- }
- }
|