using BaseCalculator; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Calculator { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { textBox1.Text += "1"; } private void button3_Click(object sender, EventArgs e) { textBox1.Text += "3"; } private void button5_Click(object sender, EventArgs e) { textBox1.Text += "5"; } private void button9_Click(object sender, EventArgs e) { textBox1.Text += "9"; } private void button10_Click(object sender, EventArgs e) { textBox1.Text += "0"; } private void button8_Click(object sender, EventArgs e) { textBox1.Text += "8"; } private void button7_Click(object sender, EventArgs e) { textBox1.Text += "7"; } private void button6_Click(object sender, EventArgs e) { textBox1.Text += "6"; } private void button4_Click(object sender, EventArgs e) { textBox1.Text += "4"; } private void button2_Click(object sender, EventArgs e) { textBox1.Text += "2"; } private void button11_Click(object sender, EventArgs e) { textBox1.Text += "+"; } private void textBox1_TextChanged(object sender, EventArgs e) { } private void label2_Click(object sender, EventArgs e) { } private void button12_Click(object sender, EventArgs e) { textBox1.Text += "-"; } private void button16_Click(object sender, EventArgs e) { textBox1.Text += "("; } private void button15_Click(object sender, EventArgs e) { textBox1.Text += ")"; } private void button14_Click(object sender, EventArgs e) { textBox1.Text += "/"; } private void button13_Click(object sender, EventArgs e) { textBox1.Text += "*"; } private void button18_Click(object sender, EventArgs e) { textBox1.Text += "%"; } private void button19_Click(object sender, EventArgs e) { textBox1.Text = " "; textBox2.Text = " "; } private void button20_Click(object sender, EventArgs e) { textBox1.Text = " "; } private void button17_Click(object sender, EventArgs e) { try { string expression = textBox1.Text; Analaizer.expression = expression; if (!Analaizer.CheckCurrency()) { textBox2.Text = "Некорректные скобки"; return; } expression = expression.Replace(" " , ""); expression = expression.Replace("(", ""); expression = expression.Replace(")", ""); if (expression.StartsWith("sin(",StringComparison.OrdinalIgnoreCase) && expression.EndsWith(")")) { string innerExpression = expression.Substring(4,expression.Length - 5); if (double.TryParse(innerExpression,out double angle)) { double result = CalcClass.Sinus(angle); textBox2.Text = result.ToString("F6"); return; } else { textBox2.Text = "некорректный аргумент для sin"; return; } } if (expression.StartsWith("cos(", StringComparison.OrdinalIgnoreCase) && expression.EndsWith(")")) { string innerExpression = expression.Substring(4, expression.Length - 5); if (double.TryParse(innerExpression, out double angle)) { double result = CalcClass.Cosinus(angle); textBox2.Text = result.ToString("F6"); return; } else { textBox2.Text = "некорректный аргумент для cos"; return; } } if (expression.Contains('+')) { string[] parts = expression.Split('+'); if (parts.Length >= 2) { long a = long.Parse(parts[0]); long b = long.Parse(parts[1]); int result = CalcClass.Add(a, b); textBox2.Text = result.ToString(); } } else if (expression.Contains('-')) { string[] parts = expression.Split('-'); if (parts.Length >= 2) { long a = long.Parse(parts[0]); long b = long.Parse(parts[1]); int result = CalcClass.Sub(a, b); textBox2.Text = result.ToString(); } } else if (expression.Contains('*')) { string[] parts = expression.Split('*'); if (parts.Length == 2) { long a = long.Parse(parts[0]); long b = long.Parse(parts[1]); int result = CalcClass.Mult(a, b); textBox2.Text = result.ToString(); } } else if (expression.Contains('/')) { string[] parts = expression.Split('/'); if (parts.Length == 2) { long a = long.Parse(parts[0]); long b = long.Parse(parts[1]); int result = CalcClass.Div(a, b); textBox2.Text = result.ToString(); } } else if (expression.Contains('²')) { string[] parts = expression.Split('²'); if (parts.Length == 2) { long a = long.Parse(parts[0]); double result = CalcClass.Square(a); textBox2.Text = result.ToString(); } } else if (expression.Contains('!')) { string[] parts = expression.Split('!'); if (parts.Length == 2) { long a = long.Parse(parts[0]); long result = CalcClass.Factor((int)a); textBox2.Text = result.ToString(); } } else if (expression.Contains('%')) { string[] parts = expression.Split('%'); if (parts.Length == 2) { long a = long.Parse(parts[0]); long b = long.Parse(parts[1]); int result = CalcClass.Mod(a, b); textBox2.Text = result.ToString(); } } else if (expression.Contains('³')) { string[] parts = expression.Split('³'); if (parts.Length == 2) { long a = long.Parse(parts[0]); double result = CalcClass.Cube(a); textBox2.Text = result.ToString(); } } else if (expression.Contains("cos")) { string[] parts = expression.Split("cos".ToCharArray()); long a = long.Parse(parts[0]); double result = CalcClass.Cosinus(a); textBox2.Text = result.ToString(); } else if (expression.Contains("sin")) { string[] parts = expression.Split("sin".ToCharArray()); long a = long.Parse(parts[0]); double result = CalcClass.Sinus(a); textBox2.Text = result.ToString(); } else { textBox2.Text = "Ошибка, неверный формат выражения"; } } catch (Exception ex) { textBox2.Text = $"ошибка: {ex.Message}"; } } private void button20_Click_1(object sender, EventArgs e) { if (this.BackColor == Color.FromArgb(192, 255, 255)) { this.BackColor = Color.FromArgb(64, 64, 64); button20.Text = "🌑"; label2.ForeColor = Color.White; label3.ForeColor = Color.White; } else { this.BackColor = Color.FromArgb(192, 255, 255); button20.Text = "☀"; label2.ForeColor = Color.Black; label3.ForeColor = Color.Black; } } private void Form1_Load(object sender, EventArgs e) { } private void label3_Click(object sender, EventArgs e) { } private void button21_Click(object sender, EventArgs e) { { textBox1.Text += "²"; } } private void button22_Click(object sender, EventArgs e) { { textBox1.Text += CalcClass.Pi; } } private void button23_Click(object sender, EventArgs e) { { textBox1.Text += "!"; } } private void button24_Click(object sender, EventArgs e) { { textBox1.Text += "%"; } } private void button25_Click(object sender, EventArgs e) { { textBox1.Text += "³"; } } private void button26_Click(object sender, EventArgs e) { if (textBox1.Text.Length > 0) textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1); textBox2.Text = string.Empty; } private void textBox2_TextChanged(object sender, EventArgs e) { } private void textBox1_TextChanged_1(object sender, EventArgs e) { } private void button18_Click_1(object sender, EventArgs e) { { textBox1.Text += "sin"; } } private void button27_Click(object sender, EventArgs e) { { textBox1.Text += "cos"; } } } }