public static double GetResult(Calculation Calc)
        {
            switch (Calc.GetOperation())
            {
            case "+":
                Calc.SetResult(Operations.Sum(Calc.GetInputA(), Calc.GetInputB()));
                Console.WriteLine("The Result is: " + Calc.GetResult());
                return(Calc.GetResult());

            case "-":
                Calc.SetResult(Operations.Difference(Calc.GetInputA(), Calc.GetInputB()));
                Console.WriteLine("The Result is: " + Calc.GetResult());
                return(Calc.GetResult());

            case "/":
                Calc.SetResult(Operations.Division(Calc.GetInputA(), Calc.GetInputB()));
                Console.WriteLine("The Result is: " + Calc.GetResult());
                return(Calc.GetResult());

            case "*":
                Calc.SetResult(Operations.Multiplication(Calc.GetInputA(), Calc.GetInputB()));
                Console.WriteLine("The Result is: " + Calc.GetResult());
                return(Calc.GetResult());

            case ">/":
                Calc.SetResult(Operations.Sqrt(Calc.GetInputA()));
                Console.WriteLine("The Result is: " + Calc.GetResult());
                return(Calc.GetResult());

            case "^2":
                Calc.SetResult(Operations.Squared(Calc.GetInputA()));
                Console.WriteLine("The Result is: " + Calc.GetResult());
                return(Calc.GetResult());

            default:
                double _result = Operations.Unassigned(Calc.GetInputA(), Calc.GetInputB());
                Console.WriteLine("Operation unassigned. Enter a valid operation.");
                return(_result);


                /* case "+":
                 * _result = Operations.Sum(Calc.GetInputA(),Calc.GetInputB());
                 * Console.WriteLine("The Result is: "+_result);
                 * return _result;
                 * case "-":
                 * _result = Operations.Difference(Calc.GetInputA(), Calc.GetInputB());
                 * Console.WriteLine("The Result is: " + _result);
                 * return _result;
                 * case "/":
                 * _result = Operations.Division(Calc.GetInputA(), Calc.GetInputB());
                 * Console.WriteLine("The Result is: " + _result);
                 * return _result;
                 * case "*":
                 * _result = Operations.Multiplication(Calc.GetInputA(), Calc.GetInputB());
                 * Console.WriteLine("The Result is: " + _result);
                 * return _result;
                 * case ">/":
                 * _result = Operations.Sqrt(Calc.GetInputA());
                 * Console.WriteLine("The Result is: " + _result);
                 * return _result;
                 * case "^2":
                 * _result = Operations.Squared(Calc.GetInputA());
                 * Console.WriteLine("The Result is: " + _result);
                 * return _result;
                 * case "History":
                 * InputHistory _proc = new InputHistory();
                 * Console.WriteLine(_proc.GetHistory());
                 * return;
                 * default:
                 * _result = Operations.Unassigned(Calc.GetInputA(),Calc.GetInputB());
                 * Console.WriteLine("Operation unassigned. Enter a valid operation.");
                 * return _result;
                 */
            }
        }
Exemplo n.º 2
0
 public void AddHistory(Calculation calc)
 {
     CalcList.Add(calc);
 }
Exemplo n.º 3
0
 public void InsertHistory(Calculation calc, int a)
 {
     CalcList.Insert(a, calc);
     CalcList.RemoveAt(a);
 }
Exemplo n.º 4
0
        public void Start()
        {
            // pub.PubOp(calc);

            /*  string userInput="end";
             * try
             * {*/

            var pub = new ConsolePub();
            var sub = new ConsoleSub(pub);

            while (true)
            {
                Console.WriteLine("Please choose an operation(+,-,/,*,>/ for square root, ^2 for squaring the number), or view the history of calculations with 'History', and change the history with 'Modify History'");
                string userInput = Console.ReadLine();
                int    count     = 0;
                //  userInput = calc.GetOperation();
                //change cases to call methods in pub
                // Console.WriteLine(e.Message);

                /*    }
                 *  catch(Exception e)
                 *  {
                 *      pub.PubFailed(e);
                 *  }*/

                Calculation calc = new Calculation();

                switch (userInput)
                {
                case "+":
                    calc.SetOperation(userInput);
                    pub.PubAdd(getInput(calc), userInput);
                    break;

                case "-":
                    calc.SetOperation(userInput);
                    pub.PubSub(getInput(calc), userInput);
                    break;

                case "/":
                    calc.SetOperation(userInput);
                    pub.PubDiv(getInput(calc), userInput);
                    break;

                case "*":
                    calc.SetOperation(userInput);
                    pub.PubMult(getInput(calc), userInput);
                    break;

                case ">/":
                    calc.SetOperation(userInput);
                    pub.PubSqrt(getInput(calc), userInput);
                    break;

                case "^2":
                    calc.SetOperation(userInput);
                    pub.PubPow(getInput(calc), userInput);
                    break;

                case "History":
                    //pub.PubHist(calc, userInput);
                    InputHistory.GetInstance().ViewHistory();
                    break;

                case "Modify History":
                    ChangeHistory hist = new ChangeHistory();
                    hist.CHistory(count);
                    break;

                case "end":
                    System.Environment.Exit(1);
                    break;

                default:
                    Console.WriteLine("Invalid operation. Enter a valid operation");
                    break;
                }
            }
        }