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 N3 { /// /// Логика взаимодействия для MainWindow.xaml /// public partial class MainWindow : Window { private List numbs = new List(); private float thisNum = 0; private float answer = 0; private bool operationsFlag = true; private string lastOperation = ""; private string NullException = "ошибка деления на 0"; private string stringShow = ""; private bool placeFlag = true;//флаг записи дробного числа private int placeNum = 0;//разряд числа после запятой public MainWindow() { InitializeComponent(); } /// /// Запись чисел /// private void NumClick(object sender, RoutedEventArgs e) { Button btn = (Button)sender; int num = Convert.ToInt32(btn.Content); if (placeNum == 0) { thisNum = thisNum * 10 + num; } else { float place = (float)Math.Pow(0.10, placeNum); placeNum++; thisNum = thisNum + num * place; } stringShow += num; TBshow.Text = stringShow; } /// /// Выполнение деятельности, по типу удаления и очищения элементов /// private void ActClick(object sender, RoutedEventArgs e) { Button btn = (Button)sender; string act = (string)btn.Content; switch (act) { case "C": //очищение всего { stringShow = ""; thisNum = 0; answer = 0; numbs = new List(); operationsFlag = true; lastOperation = ""; placeFlag = true; placeNum = 0; TBshow.Text = stringShow; TBanswer.Text = ""; TBanswer.Visibility = Visibility.Collapsed; break; } case ","://число с запятой { if (placeFlag) { placeFlag = false; placeNum = 1; stringShow += ","; TBshow.Text = stringShow; } break; } case "="://решение уравнения { if (lastOperation != "") { otherOperation("="); } else if (operationsFlag) { answer += thisNum; } TBanswer.Text = "= " + answer; TBanswer.Visibility = Visibility.Visible; break; } } } private void newNum() { numbs.Add(thisNum); thisNum = 0; placeFlag = true; placeNum = 0; } /// /// Операции над элементами /// private void OperationClick(object sender, RoutedEventArgs e) { Button btn = (Button)sender; string operation = (string)btn.Content; if (operationsFlag) { answer += thisNum; operationsFlag = false; lastOperation = ""; } switch (operation) { case "√x": { if (!operationsFlag) { answer = OperationClass.extract(answer); stringShow = "√(" + stringShow + ")"; TBshow.Text = stringShow; } operationsFlag = true; newNum(); break; } case "x^2": { if (!operationsFlag) { answer = OperationClass.power(answer); stringShow = "(" + stringShow + ")^2"; TBshow.Text = stringShow; } operationsFlag = true; newNum(); break; } case "log10(x)": { if (!operationsFlag) { if (answer < 0) { TBanswer.Text = "Число не может быть отрицательным"; } answer = OperationClass.logorifm(answer); stringShow = "log10(" + stringShow + ")"; TBshow.Text = stringShow; operationsFlag = true; } newNum(); break; } case "sin": { if (!operationsFlag) { answer = OperationClass.sinus(answer); stringShow = "sin(" + stringShow + ")"; TBshow.Text = stringShow; } operationsFlag = true; newNum(); break; } case "ctg": { if (!operationsFlag) { answer = OperationClass.cotangent(answer); stringShow = "ctg(" + stringShow + ")"; TBshow.Text = stringShow; } operationsFlag = true; newNum(); break; } default: { stringShow += operation; TBshow.Text = stringShow; newNum(); break; } } if (lastOperation == "") lastOperation = operation; else otherOperation(operation); } private void otherOperation(string operation) { switch (lastOperation) { case "+": { if (!operationsFlag) { answer = OperationClass.sum(answer, thisNum); } newNum(); break; } case "-": { if (!operationsFlag) { answer = OperationClass.difference(answer, thisNum); } newNum(); break; } case "/": { if (!operationsFlag) { answer = OperationClass.quotient(answer, thisNum); } newNum(); break; } case "*": { if (!operationsFlag) { answer = OperationClass.product(answer, thisNum); } newNum(); break; } case "%": { if (!operationsFlag) { answer = OperationClass.procent(answer, thisNum); } newNum(); break; } } if (operation != "=") lastOperation = operation; } } }