Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            calculator cal = new calculator();

            double a = 10;
            double b = 5;

            double result;
            double resultDivide;

            result = cal.Add(a, b);
            Console.WriteLine("Add result: " + result);

            result = cal.Subtract(a, b);
            Console.WriteLine("Subtract result: " + result);

            result = cal.Multiply(a, b);
            Console.WriteLine("Multiply result: " + result);

            result = cal.Power(a, b);
            Console.WriteLine("Power result: " + result);

            resultDivide = cal.Divide(a, b);
            Console.WriteLine("Divide result: " + resultDivide);
        }
Ejemplo n.º 2
0
        public static double Calculate(string s)
        {
            List <string> list = new List <string>();

            list = s.Split().ToList();
            calculator g = new calculator(Convert.ToDouble(list[0]), Convert.ToDouble(list[2]));

            switch (list[1])

            {
            case "+":
                Addition(g);
                break;

            case "-":
                Subtraction(g);
                break;

            case "*":
                Multiplication(g);
                break;

            case "/":
                Вivision(g);
                break;

            default:
                throw new ArgumentException(String.Format("Invalid"));
            }

            return(g.answer);
        }
Ejemplo n.º 3
0
        static resultOperationContainer calculateOperation(string option, string[] arguments)
        {
            resultOperationContainer calcOperation = new resultOperationContainer();

            try {
                calculator mathOp = new calculator();
                switch (option)
                {
                case "1":
                case "sum":
                {
                    calcOperation = mathOp.mathOperation(arguments[0], arguments[1], "1");
                }; break;

                case "2":
                case "subtract":
                {
                    calcOperation = mathOp.mathOperation(arguments[0], arguments[1], "2");
                }; break;

                case "3":
                case "multiply":
                {
                    calcOperation = mathOp.mathOperation(arguments[0], arguments[1], "3");
                }; break;

                case "4":
                case "divide":
                {
                    calcOperation = mathOp.mathOperation(arguments[0], arguments[1], "4");
                }; break;

                case "0":
                {
                    exitApplication(0);
                }; break;

                default:
                {
                    calcOperation.errorMessage = "Invalid option";
                    calcOperation.success      = false;
                }
                break;
                }
            }
            catch (Exception exc) {
                calcOperation.exception = exc;
                calcOperation.success   = false;
            }
            return(calcOperation);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            calculator calc = new calculator();



            //Console.WriteLine(calc.Add(5,1));
            //Console.WriteLine(calc.Subtract(5, 4));
            //Console.WriteLine(calc.Multiply(5, 2));
            //Console.WriteLine(calc.Power(6, 1));
            //Console.WriteLine(calc.Add(5, 10));
            Console.WriteLine(calc.Add(12, 1));
            //Console.WriteLine(calc.Power(-1, 0.05));
            //Console.WriteLine(calc.Power(2, 1.2));
            // Console.WriteLine(calc.Power(-2, 12));
            Console.WriteLine(calc.Divide(0));

            //Console.WriteLine(calc.Add(2));
            //Console.WriteLine(calc.Subtract(2));
        }
Ejemplo n.º 5
0
 private static void Вivision(calculator Obj)
 {
     Obj.answer = Obj.x / Obj.y;
 }
Ejemplo n.º 6
0
 private static void Subtraction(calculator Obj)
 {
     Obj.answer = Obj.x - Obj.y;
 }
Ejemplo n.º 7
0
 private static void Multiplication(calculator Obj)
 {
     Obj.answer = Obj.x * Obj.y;
 }
Ejemplo n.º 8
0
 private static void Addition(calculator Obj)
 {
     Obj.answer = Obj.x + Obj.y;
 }