Example #1
0
        //----------------------------------------------------------------------------
        //--------------------------End of scientific calculator----------------------
        //----------------------------------------------------------------------------

        //----------------------------------------------------------------------------
        //--------------------------Start of Programmer calculator--------------------
        //----------------------------------------------------------------------------

        public void changeBase(string newBase)
        {
            string preNumBase = numBase;

            numBase = newBase;

            Entry = ProgrammerFunctions.ConvertBase(Entry, preNumBase, numBase);

            first      = true;
            enteredNum = true;
            overwrite  = true;
        }
Example #2
0
        /// <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;
        }
Example #3
0
 static void Main()
 {
     Console.WriteLine(ProgrammerFunctions.ConvertBase("1001", "bin", "oct"));
     Console.ReadLine();
 }
Example #4
0
        /// <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;
        }