/// <summary> /// Metóda btn_neg_Click, ktorá je volaná pri stlačení tlačidla negácie. /// Metóda obráti znamienko čísla nachádzajúceho sa v textBoxe výsledoku pomocou metódy volanej z matematickej knižnice. /// Nastaví sa font podľa velkosti výsledku a priorita kliknutia na tlačidlo enter. /// </summary> /// <param name="sender">Objekt, ktorý sa posiela do danej metódy</param> /// <param name="e">Dáta udalosti, ktoré sa posielajú do danej metódy</param> private void btn_neg_Click(object sender, EventArgs e) { MathHead mh = new MathHead(); resultBox.Text = mh.Neg(Double.Parse(resultBox.Text)).ToString(); resultValue = Double.Parse(resultBox.Text); NewFont(); btn_enter.Focus(); }
//testovanie MathHead Faktorial public void Function_Fakt() { MathHeadFunctiones mh = new MathHeadFunctiones(); Assert.AreEqual(120, mh.Fact(5)); Assert.AreEqual(1, mh.Fact(1)); Assert.AreEqual(1, mh.Fact(0)); Assert.AreEqual(479001600, mh.Fact(12)); // Doplnit osetrenie ak faqtorial sa == zaporne cislo }
//testovanie MathHead Krat public void Function_Ml() { MathHeadFunctiones mh = new MathHeadFunctiones(); Assert.AreEqual(2, mh.Mul(2, 1)); Assert.AreEqual(-81, mh.Mul(9, -9)); Assert.AreEqual(60, mh.Mul(-6, -10)); Assert.AreEqual(-42, mh.Mul(-42, 1)); Assert.AreEqual(0, mh.Mul(0, 1987)); Assert.AreEqual(400000000, mh.Mul(20000, 20000)); Assert.AreEqual(-100000000, mh.Mul(-100000000, 1)); Assert.AreEqual(44.1, mh.Mul(6.3, 7)); }
//testovanie MathHead ^2 public void Function_SQRT() { MathHeadFunctiones mh = new MathHeadFunctiones(); Assert.AreEqual(144, mh.Sqrt(12)); Assert.AreEqual(64000000, mh.Sqrt(8000)); Assert.AreEqual(4, mh.Sqrt(2)); Assert.AreEqual(1, mh.Sqrt(1)); Assert.AreNotEqual(-9, mh.Sqrt(-3)); Assert.AreNotEqual(-64, mh.Sqrt(-8)); Assert.AreNotEqual(-64000000, mh.Sqrt(-8000)); }
//testovanie MathHead negacie public void Function_Neg() { MathHeadFunctiones mh = new MathHeadFunctiones(); Assert.AreEqual(-1, mh.Negacia(1)); Assert.AreEqual(-100000000, mh.Negacia(100000000)); Assert.AreEqual(0, mh.Negacia(0)); Assert.AreEqual(5000, mh.Negacia(-5000)); Assert.AreNotEqual(-500, mh.Negacia(-500)); Assert.AreNotEqual(48, mh.Negacia(48)); Assert.AreNotEqual(1, mh.Negacia(1)); Assert.AreEqual(4.5, mh.Negacia(-4.5)); Assert.AreEqual(-9.6, mh.Negacia(9.6)); }
//testovanie MathHead scitavanie public void Function_Sum() { MathHeadFunctiones mh = new MathHeadFunctiones(); Assert.AreEqual(-1, mh.Sum(1, -2)); Assert.AreNotEqual(10, mh.Sum(5, 6)); Assert.AreEqual(984, mh.Sum(983, 1)); Assert.AreEqual(2000, mh.Sum(1965, 35)); Assert.AreEqual(-100, mh.Sum(-50, -50)); Assert.AreEqual(0, mh.Sum(-659, 659)); Assert.AreEqual(0, mh.Sum(0, 0)); Assert.AreEqual(-50, mh.Sum(-78, 28)); Assert.AreEqual(450000000, mh.Sum(400000000, 50000000)); Assert.AreEqual(-300000000, mh.Sum(-150000000, -150000000)); }
//testovanie MathHead Odmocnina public void Function_Root() { MathHeadFunctiones mh = new MathHeadFunctiones(); Assert.AreEqual(3, mh.Root(9, 2)); Assert.AreEqual(9, mh.Root(81, 2)); Assert.AreEqual(0, mh.Root(0, 5)); Assert.AreEqual(60000000, mh.Root(60000000, 1)); Assert.AreEqual(3.9, mh.Root(59.319, 3), esp); Assert.AreEqual(12, mh.Root(144, 2)); Assert.AreEqual(1000, mh.Root(1000000, 2)); Assert.AreNotEqual(45, mh.Root(456, 9)); Assert.AreNotEqual(74, mh.Root(978, 2)); // pridat osetrenie pre vstup mensi ako 0 }
//testovanie MathHead vypocet s exponentom public void Function_Exp() { MathHeadFunctiones mh = new MathHeadFunctiones(); Assert.AreEqual(9, mh.Exp(3, 2)); Assert.AreEqual(42875, mh.Exp(35, 3)); Assert.AreEqual(147008443, mh.Exp(43, 5)); Assert.AreEqual(25, mh.Exp(-5, 2)); Assert.AreEqual(-125, mh.Exp(-5, 3)); Assert.AreEqual(0.729, mh.Exp(0.9, 3), esp); Assert.AreEqual(3.652264, mh.Exp(1.54, 3)); Assert.AreNotEqual(745, mh.Exp(9, 5)); Assert.AreNotEqual(0.56, mh.Exp(1.26, 4)); Assert.AreNotEqual(654, mh.Exp(7, 6)); Assert.AreNotEqual(1231456, mh.Exp(53, 2)); }
//testovanie MathHead scitavanie public void Function_Sub() { MathHeadFunctiones mh = new MathHeadFunctiones(); Assert.AreEqual(0, mh.Sub(1, 1)); Assert.AreEqual(-1, mh.Sub(0, 1)); Assert.AreEqual(1, mh.Sub(1, 0)); Assert.AreEqual(0, mh.Sub(-5, -5)); Assert.AreEqual(150000000, mh.Sub(150000001, 1)); Assert.AreEqual(-189000000, mh.Sub(-300000000, -111000000)); Assert.AreEqual(687, mh.Sub(743, 56)); Assert.AreEqual(-42, mh.Sub(-40, 2)); Assert.AreEqual(5.364, mh.Sub(6, 0.636)); Assert.AreEqual(-765.315, mh.Sub(-1000, -234.685)); Assert.AreEqual(897, mh.Sub(800, -97)); Assert.AreEqual(0, mh.Sub(0, 0)); }
//testovanie MathHead Delenie public void Function_Div() { MathHeadFunctiones mh = new MathHeadFunctiones(); Assert.AreEqual(39, mh.Div(156, 4)); Assert.AreEqual(1.8, mh.Div(9, 5)); Assert.AreEqual(-2, mh.Div(-6, 3)); Assert.AreEqual(129301, mh.Div(129301, 1)); Assert.AreEqual(2.25, mh.Div(9, 4)); Assert.AreEqual(2.25, mh.Div(-9, -4)); Assert.AreEqual(1000000, mh.Div(10000000, 10)); Assert.AreEqual(0.5, mh.Div(800, 1600)); Assert.AreEqual(-8, mh.Div(72, -9)); Assert.AreNotEqual(12, mh.Div(698, 68)); Assert.AreNotEqual(145, mh.Div(100000000, 78000000)); // pridat delenie 0 !!! }
/// <summary> /// Metóda btn_op_Click, ktorá je volaná pri stlačení tlačidla operácie. Metóda vykoná predchádzajúcu operáciu (pokiaľ existuje). /// Vypočíta operáciu pomocou metód volaných z matematickej knižnice. Ošetruje chybové stavy. /// Nastavuje nadchádzajúcu operáciu na základe aktuálne kliknutej operácie. Pokiaľ bola operácia stlačená bezprostredne pred akutálnou operáciou, /// stará operácie je prepísaná novou (aktuálne stlačenou operáciou). /// </summary> /// <param name="sender">Objekt, ktorý sa posiela do danej metódy</param> /// <param name="e">Dáta udalosti, ktoré sa posielajú do danej metódy</param> private void btn_op_Click(object sender, EventArgs e) { MathHead mh = new MathHead(); Button button = (Button)sender; if (operationPressed == true && (operation == "+" || operation == "-" || operation == "*" || operation == "/" || operation == "^" || operation == "\u221A")) { operation = button.Text; lbl_history.Text = lbl_history.Text.Remove(lbl_history.Text.Length - 1) + operation; } else { if (enterPressed == true) { operation = button.Text; lbl_history.Text = historyValue.ToString() + operation; enterPressed = false; } else { try { Double.Parse(resultBox.Text); } catch (FormatException) { Error(0); return; } historyStringValue = Double.Parse(resultBox.Text); switch (operation) { case "+": if (button.Text == "^" || button.Text == "\u221A" || button.Text == "*" || button.Text == "/") { betweenValue = historyValue; historyValue = Double.Parse(resultBox.Text); oldOperation = operation; operation = button.Text; } else { resultValue = mh.Add(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; } break; case "^": try { Int32.Parse(resultBox.Text); } catch (FormatException) { Error(2); return; } if (Int32.Parse(resultBox.Text) < 0) { Error(2); return; } switch (oldOperation) { case "+": resultValue = betweenValue + mh.Exp(historyValue, Int32.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; betweenValue = 0; oldOperation = ""; break; case "-": resultValue = betweenValue - mh.Exp(historyValue, Int32.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; betweenValue = 0; oldOperation = ""; break; case "*": resultValue = betweenValue * mh.Exp(historyValue, Int32.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; betweenValue = 0; oldOperation = ""; break; case "/": resultValue = betweenValue / mh.Exp(historyValue, Int32.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; betweenValue = 0; oldOperation = ""; break; default: resultValue = mh.Exp(historyValue, Int32.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; oldOperation = ""; break; } break; case "\u221A": if (historyValue == 0) { Error(4); return; } if (Double.Parse(resultBox.Text) < 0) { Error(1); return; } switch (oldOperation) { case "+": resultValue = betweenValue + mh.Root(Double.Parse(resultBox.Text), historyValue); resultBox.Text = resultValue.ToString(); historyValue = resultValue; betweenValue = 0; oldOperation = ""; break; case "-": resultValue = betweenValue - mh.Root(Double.Parse(resultBox.Text), historyValue); resultBox.Text = resultValue.ToString(); historyValue = resultValue; betweenValue = 0; oldOperation = ""; break; case "*": resultValue = betweenValue * mh.Root(Double.Parse(resultBox.Text), historyValue); resultBox.Text = resultValue.ToString(); historyValue = resultValue; betweenValue = 0; oldOperation = ""; break; case "/": resultValue = betweenValue / mh.Root(Double.Parse(resultBox.Text), historyValue); resultBox.Text = resultValue.ToString(); historyValue = resultValue; betweenValue = 0; oldOperation = ""; break; default: resultValue = mh.Root(Double.Parse(resultBox.Text), historyValue); resultBox.Text = resultValue.ToString(); historyValue = resultValue; oldOperation = ""; break; } break; case "-": if (button.Text == "^" || button.Text == "\u221A" || button.Text == "*" || button.Text == "/") { betweenValue = historyValue; historyValue = Double.Parse(resultBox.Text); oldOperation = operation; operation = button.Text; } else { resultValue = mh.Sub(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; } break; case "*": if (button.Text == "^" || button.Text == "\u221A" || button.Text == "/") { betweenValue = historyValue; historyValue = Double.Parse(resultBox.Text); oldOperation = operation; operation = button.Text; } else { switch (oldOperation) { case "+": resultValue = betweenValue + mh.Mul(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; betweenValue = 0; oldOperation = ""; break; case "-": resultValue = betweenValue - mh.Mul(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; betweenValue = 0; oldOperation = ""; break; case "/": resultValue = betweenValue / mh.Mul(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; betweenValue = 0; oldOperation = ""; break; default: if (historyValue == 0) { historyValue = 1; } resultValue = mh.Mul(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; oldOperation = ""; break; } } break; case "/": if (button.Text == "^" || button.Text == "\u221A" || button.Text == "*") { betweenValue = historyValue; historyValue = Double.Parse(resultBox.Text); oldOperation = operation; operation = button.Text; } else { if (Double.Parse(resultBox.Text) == 0) { Error(4); return; } switch (oldOperation) { case "+": resultValue = betweenValue + mh.Div(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; betweenValue = 0; oldOperation = ""; break; case "-": resultValue = betweenValue - mh.Div(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; betweenValue = 0; oldOperation = ""; break; case "*": resultValue = betweenValue * mh.Div(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; betweenValue = 0; oldOperation = ""; break; default: resultValue = mh.Div(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; oldOperation = ""; break; } } break; default: historyValue = historyStringValue; break; } if (funcPressed == true) { lbl_history.Text = historyStringValue.ToString() + button.Text; } else { lbl_history.Text = lbl_history.Text + historyStringValue.ToString() + button.Text; } operation = button.Text; } } funcPressed = false; enterPressed = false; operationPressed = true; NewFont(); maxChar = false; btn_enter.Focus(); }
/// <summary> /// Metóda btn_enter_Click, ktorá je volaná pri stlačení tlačidla "rovná sa". Má za úlohu zistiť naposledy kliknutú operáciu /// a na základe nej vypočítať výsledok a ukončiť sekvenciu operácií. Tento výsledok sa následne vypíše do textBox výsledku a do histórie sa vypíše história operácií /// zakončená posledným číslom a znaminekom rovnosti. Ošetruje aj chybové stavy. /// </summary> /// <param name="sender">Objekt, ktorý sa posiela do danej metódy</param> /// <param name="e">Dáta udalosti, ktoré sa posielajú do danej metódy</param> private void btn_enter_Click(object sender, EventArgs e) { MathHead mh = new MathHead(); try { Double.Parse(resultBox.Text); } catch (FormatException) { Error(0); return; } historyStringValue = Double.Parse(resultBox.Text); switch (operation) { case "+": resultValue = mh.Add(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; break; case "-": resultValue = mh.Sub(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; break; case "*": switch (oldOperation) { case "+": resultValue = betweenValue + mh.Mul(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; betweenValue = 0; oldOperation = ""; break; case "-": resultValue = betweenValue - mh.Mul(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; betweenValue = 0; oldOperation = ""; break; case "/": resultValue = betweenValue / mh.Mul(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; betweenValue = 0; oldOperation = ""; break; default: resultValue = mh.Mul(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; oldOperation = ""; break; } break; case "^": try { Int32.Parse(resultBox.Text); } catch (FormatException) { Error(2); return; } if (Int32.Parse(resultBox.Text) < 0) { Error(2); return; } switch (oldOperation) { case "+": resultValue = betweenValue + mh.Exp(historyValue, Int32.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; betweenValue = 0; oldOperation = ""; break; case "-": resultValue = betweenValue - mh.Exp(historyValue, Int32.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; betweenValue = 0; oldOperation = ""; break; case "*": resultValue = betweenValue * mh.Exp(historyValue, Int32.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; betweenValue = 0; oldOperation = ""; break; case "/": resultValue = betweenValue / mh.Exp(historyValue, Int32.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; betweenValue = 0; oldOperation = ""; break; default: resultValue = mh.Exp(historyValue, Int32.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; oldOperation = ""; break; } break; case "\u221A": if (historyValue == 0) { Error(4); return; } if (Double.Parse(resultBox.Text) < 0) { Error(1); return; } switch (oldOperation) { case "+": resultValue = betweenValue + mh.Root(Double.Parse(resultBox.Text), historyValue); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; betweenValue = 0; oldOperation = ""; break; case "-": resultValue = betweenValue - mh.Root(Double.Parse(resultBox.Text), historyValue); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; betweenValue = 0; oldOperation = ""; break; case "*": resultValue = betweenValue * mh.Root(Double.Parse(resultBox.Text), historyValue); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; betweenValue = 0; oldOperation = ""; break; case "/": resultValue = betweenValue / mh.Root(Double.Parse(resultBox.Text), historyValue); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; betweenValue = 0; oldOperation = ""; break; default: resultValue = mh.Root(Double.Parse(resultBox.Text), historyValue); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; oldOperation = ""; break; } break; case "/": if (Double.Parse(resultBox.Text) == 0) { Error(4); return; } else { switch (oldOperation) { case "+": resultValue = betweenValue + mh.Div(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; betweenValue = 0; oldOperation = ""; break; case "-": resultValue = betweenValue - mh.Div(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; betweenValue = 0; oldOperation = ""; break; case "*": resultValue = betweenValue * mh.Div(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; betweenValue = 0; oldOperation = ""; break; default: resultValue = mh.Div(historyValue, Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; lbl_history.Text = lbl_history.Text + historyStringValue + "="; oldOperation = ""; break; } } break; } if (double.IsInfinity(resultValue)) { Error(2); return; } NewFont(); enterPressed = true; operationPressed = false; operation = ""; maxChar = false; btn_enter.Focus(); }
/// <summary> /// Metóda btn_fact_Click, ktorá je volaná pri stlačení tlačidla "x!". Metóda počíta faktorial čísla pomocou metódy Fact() volanej z matematickej knižnice /// Ošetruje chybové stavy, pridá funkciu do histórie a výsledok vypíše do textBoxu výsledku. /// </summary> /// <param name="sender">Objekt, ktorý sa posiela do danej metódy</param> /// <param name="e">Dáta udalosti, ktoré sa posielajú do danej metódy</param> private void btn_fact_Click(object sender, EventArgs e) { MathHead mh = new MathHead(); if (enterPressed == true) { lbl_history.Text = ""; enterPressed = false; } double x; if (Double.TryParse(resultBox.Text, out x)) { if (x < 0) { lbl_history.Text = ""; historyStringValue = 0; historyValue = 0; resultBox.Font = new Font(resultBox.Font.FontFamily, 20); resultBox.Text = "Neplatný vstup"; errorCode = 1; funcPressed = false; operationPressed = false; enterPressed = true; operation = ""; return; } } try { UInt64.Parse(resultBox.Text); } catch (FormatException) { Error(1); return; } catch (OverflowException) { Error(3); return; } switch (operation) { case "+": lbl_history.Text = lbl_history.Text + "fact(" + UInt64.Parse(resultBox.Text) + ")"; resultValue = historyValue + mh.Fact(UInt64.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; break; case "-": lbl_history.Text = lbl_history.Text + "fact(" + UInt64.Parse(resultBox.Text) + ")"; resultValue = historyValue - mh.Fact(UInt64.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; break; case "*": lbl_history.Text = lbl_history.Text + "fact(" + UInt64.Parse(resultBox.Text) + ")"; resultValue = historyValue * mh.Fact(UInt64.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; break; case "/": lbl_history.Text = lbl_history.Text + "fact(" + UInt64.Parse(resultBox.Text) + ")"; resultValue = historyValue / mh.Fact(UInt64.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; break; default: if (funcPressed == true) { lbl_history.Text = "fact(" + historyString + ")"; } else { lbl_history.Text = lbl_history.Text + "fact(" + UInt64.Parse(resultBox.Text) + ")"; } resultValue = mh.Fact(UInt64.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; break; } if (resultValue == 0) { Error(3); return; } historyString = lbl_history.Text; operationPressed = false; operation = ""; funcPressed = true; NewFont(); maxChar = false; btn_enter.Focus(); }
/// <summary> /// Metóda btn_sqrt_Click, ktorá je volaná pri stlačení tlačidla "x2". Metóda počíta druhú mocninu čísla pomocou metódy Sqrt() volanej z matematickej knižnice. /// Ošetruje chybové stavy, pridá funkciu do histórie a výsledok vypíše do textBoxu výsledku. /// </summary> /// <param name="sender">Objekt, ktorý sa posiela do danej metódy</param> /// <param name="e">Dáta udalosti, ktoré sa posielajú do danej metódy</param> private void btn_sqrt_Click(object sender, EventArgs e) { MathHead mh = new MathHead(); if (enterPressed == true) { lbl_history.Text = ""; enterPressed = false; } try { Double.Parse(resultBox.Text); } catch (FormatException) { Error(1); return; } catch (OverflowException) { Error(3); return; } if (double.IsInfinity(historyValue) || double.IsInfinity(double.Parse(resultBox.Text))) { Error(3); return; } switch (operation) { case "+": lbl_history.Text = lbl_history.Text + "sqrt(" + Double.Parse(resultBox.Text) + ")"; resultValue = historyValue + mh.Sqrt(Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; break; case "-": lbl_history.Text = lbl_history.Text + "sqrt(" + Double.Parse(resultBox.Text) + ")"; resultValue = historyValue - mh.Sqrt(Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; break; case "*": lbl_history.Text = lbl_history.Text + "sqrt(" + Double.Parse(resultBox.Text) + ")"; resultValue = historyValue * mh.Sqrt(Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; break; case "/": lbl_history.Text = lbl_history.Text + "sqrt(" + Double.Parse(resultBox.Text) + ")"; resultValue = historyValue / mh.Sqrt(Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; break; default: if (funcPressed == true) { lbl_history.Text = "sqrt(" + historyString + ")"; } else { lbl_history.Text = lbl_history.Text + "sqrt(" + Double.Parse(resultBox.Text) + ")"; } resultValue = mh.Sqrt(Double.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; break; } if (double.IsInfinity(resultValue)) { Error(3); return; } historyString = lbl_history.Text; operationPressed = false; operation = ""; funcPressed = true; NewFont(); maxChar = false; btn_enter.Focus(); }