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 LR4
{
///
/// Логика взаимодействия для 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:
result.Text = Plus(a, b).ToString();
break;
case 1:
result.Text = Minus(a, b).ToString();
break;
case 2:
result.Text = Divide(a, b).ToString();
break;
case 3:
result.Text = Multiply(a, b).ToString();
break;
case 4:
result.Text = Power(a, b).ToString();
break;
case 5:
result.Text = Root(a).ToString();
break;
case 6:
result.Text = Percent(a, b).ToString();
break;
case 7:
result.Text = Log(a, b).ToString();
break;
case 8:
result.Text = Sin(a).ToString();
break;
case 9:
result.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 Multiply(double a, double b)
{
return a * b;
}
static public double Divide(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;
}
}
}
}