Пример #1
0
        private void button_factorial_Click(object sender, EventArgs e)
        {
            int  Kontrola = 0;
            bool Vysledok = Int32.TryParse(result.Text, out Kontrola);

            if (Vysledok == true)
            {
                if ((int.Parse(result.Text) >= 0) && (int.Parse(result.Text) <= 17))
                {
                    if (result.Text != "Chyba")
                    {
                        value       = MatLib.factorial(int.Parse(result.Text)); //Pretypovanie int->String
                        result.Text = (value).ToString();                       //Pretypovanie Double->String
                    }
                }
                else
                {
                    result.Text           = "Chyba";
                    number_pressed        = false;
                    second_number_pressed = false;
                }
            }
            else
            {
                result.Text           = "Chyba";
                number_pressed        = false;
                second_number_pressed = false;
            }
        }
Пример #2
0
 private void button_Square_Click(object sender, EventArgs e)
 {
     if (result.Text != "Chyba")
     {
         value       = MatLib.square(Double.Parse(result.Text)); //Pretypovanie Double->String
         result.Text = (value).ToString();                       //Pretypovanie Double->String
     }
 }
Пример #3
0
 private void button_log_Click(object sender, EventArgs e)
 {
     if ((result.Text != "Chyba") && (int.Parse(result.Text) > 0))
     {
         value       = MatLib.log10(Double.Parse(result.Text)); //Pretypovanie Double->String
         result.Text = (value).ToString();                      //Pretypovanie Double->String
     }
     else
     {
         result.Text           = "Chyba";
         number_pressed        = false;
         second_number_pressed = false;
         value         = 0;
         equal_pressed = false;
     }
 }
Пример #4
0
 private void button_sqrt_Click(object sender, EventArgs e)
 {
     if (Double.Parse(result.Text) >= 0)
     {
         if (result.Text != "Chyba")
         {
             value       = MatLib.sqrt(Double.Parse(result.Text)); //Pretypovanie Double->String
             result.Text = (value).ToString();                     //Pretypovanie Double->String
         }
     }
     else
     {
         result.Text           = "Chyba";
         number_pressed        = false;
         second_number_pressed = false;
     }
 }
Пример #5
0
        /**
         * @brief Vykona operaciu
         */
        private void Operator_click(object sender, EventArgs e)
        {
            if (result.Text != "Chyba")
            {
                if (number_pressed == true && second_number_pressed)
                {
                    // TODO Zlucenie s Button_equals_Click?

                    switch (operation)
                    {
                    case "+":
                        //value = (value + Double.Parse(result.Text)); //Pretypovanie Double->String
                        value                 = MatLib.add(value, Double.Parse(result.Text)); //Pretypovanie Double->String
                        result.Text           = (value).ToString();                           //Pretypovanie Double->String
                        second_number_pressed = false;                                        //Vykonany operator -> Druhe cislo = False(Vyhybanie sa cyklicej operacii bez dalsieho cisla)
                        break;

                    case "-":
                        //value = (value - Double.Parse(result.Text)); //Pretypovanie Double->String
                        value                 = MatLib.subtract(Double.Parse(result.Text), value); //Pretypovanie Double->String
                        result.Text           = (value).ToString();                                //Pretypovanie Double->String
                        second_number_pressed = false;                                             //Vykonany operator -> Druhe cislo = False(Vyhybanie sa cyklicej operacii bez dalsieho cisla)
                        break;

                    case "*":
                        //value = (value * Double.Parse(result.Text)); //Pretypovanie Double->String
                        if (second_number_pressed == true)
                        {
                            value                 = MatLib.multiply(value, Double.Parse(result.Text)); //Pretypovanie Double->String
                            result.Text           = (value).ToString();                                //Pretypovanie Double->String
                            second_number_pressed = false;                                             //Vykonany operator -> Druhe cislo = False(Vyhybanie sa cyklicej operacii bez dalsieho cisla)
                        }
                        break;

                    case "/":
                        //value = (value / Double.Parse(result.Text)); //Pretypovanie Double->String
                        if (second_number_pressed == true)
                        {
                            if (result.Text == "0")
                            {
                                result.Text           = "Chyba";
                                number_pressed        = false;
                                second_number_pressed = false;
                            }
                            else
                            {
                                value                 = MatLib.divide(value, Double.Parse(result.Text)); //Pretypovanie Double->String
                                result.Text           = (value).ToString();                              //Pretypovanie Double->String
                                second_number_pressed = false;                                           //Vykonany operator -> Druhe cislo = False(Vyhybanie sa cyklicej operacii bez dalsieho cisla)
                            }
                        }
                        break;

                    case "xʸ":
                        value       = MatLib.power(value, int.Parse(result.Text)); //Pretypovanie Integer->String
                        result.Text = (value).ToString();                          //Pretypovanie Double->String
                        break;

                    case "ʸ√x":
                        if (value >= 0)
                        {
                            value       = MatLib.genroot(value, int.Parse(result.Text)); //Pretypovanie Integer->String
                            result.Text = (value).ToString();                            //Pretypovanie Double->String
                        }
                        else
                        {
                            result.Text           = "Chyba";
                            number_pressed        = false;
                            second_number_pressed = false;
                        }
                        break;
                    }
                    value = 0; //Nulovanie vysledku a zabranenie duplicite pri viacnasobnej rovnakej operacii
                               //operation = "";
                }
            }
            Button Button_Name = (Button)sender;

            operation = Button_Name.Text; //Operacia podla nazvu tlacitka
            if (result.Text != "Chyba")
            {
                value = Double.Parse(result.Text); //Pretypovanie String->Double
            }
            operation_pressed = true;              //Operacia vykonana
            //number_pressed = false; //Vykonany operator -> Cislo = False(Vyhybanie sa cyklicej operacii bez dalsieho cisla)
            //equal_pressed = false;
        }
Пример #6
0
        /**
         * @brief Vykona matematicku operatciu na zaklade nazvu tlačitka
         * @note Program si nepamata posledne zvolene cislo, preto
         *       po vykonanej operacii je vysledok konecny -> Nie je mozne v operacii
         *       dalej pokracovat alebo pripadne na vysledok nadviazat bez zadania dalsej operacie!
         *       Priklad:
         *       Nebude fungovat: "5" "+" "6" "=" "5" "="
         *       Bude fungovat: "5" "+" "6" "=" "+" "5" "="
         */
        private void Button_equals_Click(object sender, EventArgs e)
        {
            if (operation_pressed == true)
            { //Osetrenie duplicity vysledku po kombinacii "5" + "6" "+" "="
                value = 0;
            }
            if (result.Text != "Chyba")
            {
                switch (operation)
                {
                case "+":
                    //value = (value + Double.Parse(result.Text)); //Pretypovanie Double->String
                    value       = MatLib.add(value, Double.Parse(result.Text)); //Pretypovanie Double->String
                    result.Text = (value).ToString();                           //Pretypovanie Double->String
                    break;

                case "-":
                    //value = (value - Double.Parse(result.Text)); //Pretypovanie Double->String
                    value       = MatLib.subtract(value, Double.Parse(result.Text)); //Pretypovanie Double->String
                    result.Text = (value).ToString();                                //Pretypovanie Double->String
                    break;

                case "*":
                    //value = (value * Double.Parse(result.Text)); //Pretypovanie Double->String
                    value       = MatLib.multiply(value, Double.Parse(result.Text)); //Pretypovanie Double->String
                    result.Text = (value).ToString();                                //Pretypovanie Double->String
                    break;

                case "/":
                    //value = (value / Double.Parse(result.Text)); //Pretypovanie Double->String
                    if (result.Text == "0")
                    {
                        result.Text           = "Chyba";
                        number_pressed        = false;
                        second_number_pressed = false;
                    }
                    else
                    {
                        value       = MatLib.divide(value, Double.Parse(result.Text)); //Pretypovanie Double->String
                        result.Text = (value).ToString();                              //Pretypovanie Double->String
                    }
                    break;

                case "xʸ":
                    value       = MatLib.power(value, int.Parse(result.Text)); //Pretypovanie Integer->String
                    result.Text = (value).ToString();                          //Pretypovanie Double->String
                    break;

                case "ʸ√x":
                    if (value >= 0)
                    {
                        value       = MatLib.genroot(value, int.Parse(result.Text)); //Pretypovanie Integer->String
                        result.Text = (value).ToString();                            //Pretypovanie Double->String
                    }
                    else
                    {
                        result.Text           = "Chyba";
                        number_pressed        = false;
                        second_number_pressed = false;
                    }
                    break;
                }
            }
            value                 = 0;     //Nulovanie vysledku a zabranenie duplicite pri viacnasobnej rovnakej operacii
            number_pressed        = false; //Vykonany sucet -> Cislo = False(Vyhybanie sa cyklickemu scitavaniu bez dalsieho cisla)
            second_number_pressed = false;
            //operation_pressed = false; //nove
            equal_pressed = true;
        }