コード例 #1
0
ファイル: Contoller.cs プロジェクト: zdmitchell/Calculator
        /// <summary>
        /// Applies an operator to preEntry and entry
        /// </summary>
        /// <param name="operationText">Text representing the operation</param>
        public void Operation(string operationText)
        {
            if (numBase != "dec")
            {
                Entry    = ProgrammerFunctions.ConvertBase(Entry, numBase, "dec");
                PreEntry = ProgrammerFunctions.ConvertBase(PreEntry, preEntryBase, "dec");
            }

            if (enteredNum)
            {
                preEntryBase = numBase;
                if (first)
                {
                    PreEntry = Entry;
                }
                else
                {
                    if (operation == "+")
                    {
                        PreEntry = StandardFunctions.Add(PreEntry, Entry);
                    }
                    else if (operation == "-")
                    {
                        PreEntry = StandardFunctions.Subtract(PreEntry, Entry);
                    }
                    else if (operation == "*")
                    {
                        PreEntry = StandardFunctions.Multiply(PreEntry, Entry);
                    }
                    else if (operation == "/")
                    {
                        PreEntry = StandardFunctions.Divide(PreEntry, Entry);
                    }
                }
            }

            if (numBase != "dec")
            {
                PreEntry = ProgrammerFunctions.ConvertBase(PreEntry, "dec", numBase);
                //preEntryBase = numBase;
            }

            Entry      = "0";
            operation  = operationText;
            first      = false;
            enteredNum = false;
        }
コード例 #2
0
ファイル: Contoller.cs プロジェクト: zdmitchell/Calculator
        /// <summary>
        /// Finds new display based on previous operator
        /// </summary>
        public void Equals()
        {
            if (numBase != "dec")
            {
                Entry    = ProgrammerFunctions.ConvertBase(Entry, numBase, "dec");
                PreEntry = ProgrammerFunctions.ConvertBase(PreEntry, preEntryBase, "dec");
            }

            if (operation == "+")
            {
                Entry = StandardFunctions.Add(PreEntry, Entry);
            }
            else if (operation == "-")
            {
                Entry = StandardFunctions.Subtract(PreEntry, Entry);
            }
            else if (operation == "*")
            {
                Entry = StandardFunctions.Multiply(PreEntry, Entry);
            }
            else if (operation == "/")
            {
                Entry = StandardFunctions.Divide(PreEntry, Entry);
            }
            else if (operation == "exp")
            {
                Entry = ScientificFunctions.GenericExponent(PreEntry, Entry);
            }
            else if (operation == "root")
            {
                Entry = ScientificFunctions.GenericRoot(PreEntry, Entry);
            }
            else if (operation == "log")
            {
                Entry = ScientificFunctions.GenericLog(PreEntry, Entry);
            }
            else if (operation == "power")
            {
                Entry = ScientificFunctions.ScientificNotation(Entry);
            }
            else if (operation == "i")
            {
                Entry = StandardFunctions.IntegerDivide(PreEntry, Entry);
            }
            else if (operation == "mod")
            {
                Entry = StandardFunctions.Mod(PreEntry, Entry);
            }

            PreEntry = Entry;

            if (numBase != "dec")
            {
                Entry    = ProgrammerFunctions.ConvertBase(Entry, "dec", numBase);
                PreEntry = ProgrammerFunctions.ConvertBase(PreEntry, "dec", numBase);
            }

            first      = true;
            overwrite  = true;
            operation  = "";
            enteredNum = false;
        }