Esempio n. 1
0
        static void Main(string[] args)
        {
            double x    = 0;
            double y    = 1;
            string com  = "";
            var    calc = new Calc();

            try
            {
                Console.WriteLine("Введите команду");
                com = Console.ReadLine();
                Console.WriteLine("Введите X");
                x = ToDouble(Console.ReadLine());
                Console.WriteLine("Введите Y");
                y = ToDouble(Console.ReadLine());
                var res = calc.Execute(com, new[] { x, y });

                Console.WriteLine(string.Format("{0}={1}", calc.LastOperationName, res));

                Console.ReadKey();
            }
            catch (NotSupportedException ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadKey();
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, i'm Калькулятор");

            var x    = 0d;
            var y    = 0d;
            var calc = new Calc();
            var oper = "sum";

            if (args.Length >= 2)
            {
                x = ToNumber(args[0], 70);
                if (args.Length >= 3)
                {
                    y = ToNumber(args[1], 83);
                }
                oper = args.Last();
            }
            else
            {
                #region Ввод данных

                Console.WriteLine("Введите Х");
                var strx = Console.ReadLine();
                x = ToNumber(strx);

                Console.WriteLine("Введите Y");
                var stry = Console.ReadLine();
                y = ToNumber(stry, 99);

                Console.WriteLine("Введите операцию");
                oper = Console.ReadLine();

                #endregion
            }

            try
            {
                var result = calc.Execute(oper, new[] { x, y });

                Console.WriteLine(String.Format("{0} = {1}", calc.LastOperationName, result));
                // *
                // sum = 5
                // Сумма = 5
            }
            catch (NotSupportedException ex)
            {
                Console.WriteLine(ex.Message);
            }


            Console.ReadKey();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("Hello, i'm ReactCalc!");
                Console.WriteLine("Enter action: Sum, Diff, Multiply, Div, Sqrt, Pow, Factorial!");
                var choose = Console.ReadLine();

                var calc = new Calc();

                double x        = 0.0;
                double y        = 0.0;
                string inputStr = "";

                if (args.Length == 2)
                {
                    x = toDouble(args[0], x);
                    y = toDouble(args[1], y);
                }
                else
                {
                    inputStr = inputData();
                    x        = toDouble(inputStr.Substring(0, inputStr.IndexOf(";")), x);
                    y        = toDouble(inputStr.Substring(inputStr.IndexOf(";") + 1, inputStr.Length - (inputStr.IndexOf(";") + 1)), x);
                }

                try
                {
                    var result = calc.Execute(choose, new[] { x, y });
                    Console.WriteLine(String.Format("{0} = {1}", calc.LastOperationName, result));
                }
                catch (NotSupportedException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                Console.WriteLine("Press any key to the next calculations");
                Console.ReadKey();
                Console.Clear();
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            double x    = 0;
            double y    = 0;
            var    calc = new Calc();
            var    oper = "Sum";

            if (args.Length > 0)
            {
                x = ToDouble(args[0], 1000);
                y = ToDouble(args[1], 999);
            }
            else
            {
                #region Ввод данных

                Console.Write("Введите x -> ");
                var strx = Console.ReadLine();
                x = ToDouble(strx, 100);

                Console.Write("Введите y -> ");
                var stry = Console.ReadLine();
                y = ToDouble(stry, 99);

                #endregion
            }

            while (true)
            {
                Console.WriteLine("1. Сумма Sum");
                Console.WriteLine("2. Разность Dif");
                Console.WriteLine("3. Произведение Mul");
                Console.WriteLine("4. Частное Div");
                Console.WriteLine("5. Квадратный корень Sqrt");
                Console.WriteLine("6. Возведение в степень Sqr");
                Console.WriteLine("7. Факториал Fact");
                Console.WriteLine("0. Выход Exit");
                Console.Write("-> ");
                oper = Console.ReadLine();

                if (oper == "Exit")
                {
                    return;
                }

                try
                {
                    var result = calc.Execute(oper, new[] { x, y });

                    var oper_desc = "";
                    foreach (var o in calc.Operations)
                    {
                        if (o.Name == oper)
                        {
                            oper_desc = o.Desc;
                        }
                    }

                    switch (oper)
                    {
                    case "Sum":
                    case "Dif":
                    case "Mul":
                    case "Div":
                    case "Sqr": Console.WriteLine($"{oper_desc}({x}, {y}) = {result}"); break;

                    case "Sqrt":
                    case "Fact": Console.WriteLine($"{oper_desc}({x}) = {result}"); break;

                    case "Exit": break;

                    default: Console.WriteLine("Ошибка"); break;
                    }
                }
                catch (NotSupportedException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                Console.WriteLine();
            }
        }