Пример #1
0
        private void btnExec_Click(object sender, EventArgs e)
        {
            // Получить операции
            var operation = cboperation.Text;

            // Проверка на наличие операндов
            if (tbinput.Text != "")
            {
                //Проверка на последний символ
                if (tbinput.Text[tbinput.Text.Length - 1] == 32)
                {
                    tbinput.Text = tbinput.Text.Remove(tbinput.Text.Length - 1, 1);
                }
                // Получить операнды
                var values = tbinput.Text
                             .Split(' ')
                             .Select(Convert.ToDouble)
                             .ToArray();

                // Выполнить расчёт
                var result = Calc.Execute(operation, values);
                //Вывод результат
                lblresult.ForeColor = Color.Black;
                lblresult.Text      = "Результат: " + $"{result}";
            }
            else
            {
                lblresult.ForeColor = Color.Red;
                lblresult.Text      = "Ошибка: Отсутствуют операнды";
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Core.Calc calc = new Core.Calc();

            // найти файл с операцией

            // загрузить этот файл
            // найти в нем операцию

            // добавить операцию в калькулятор



            double[] values;

            string operation, operands;

            int accuracy = 0;

            string[] operations = calc.Operations
                                  .Select(o => o.Name)
                                  .ToArray();

            // Проверяем заполненность стартовой консоли
            if (args.Length == 0)
            {
                Console.WriteLine("List operations: ");
                foreach (var item in operations)
                {
                    Console.WriteLine(item);
                }
                Console.WriteLine("Enter operations: ");
                operation = Console.ReadLine();

                Console.WriteLine("Enter operands: ");
                operands = Console.ReadLine();

                Console.WriteLine("Enter accuracy: ");
                accuracy = int.Parse(Console.ReadLine());

                values = convertToDouble(operands.Split(new[] { " ", ";" }, StringSplitOptions.RemoveEmptyEntries));
            }
            else // Берем операцию и значения из стартовой консоли
            {
                operation = args[0].ToLower();
                values    = convertToDouble(args, 1);
            }

            // Результат операции
            var result = calc.Execute(operation, values);

            Console.WriteLine(result);

            Console.ReadKey();
        }
Пример #3
0
        // "1+1"
        // sum 12 32 34
        static void Main(string[] args)
        {
            double[] values;
            string   operation;

            var calc = new Core.Calc();

            // найти файл с операцией
            // загрузить этот файл

            // найти в нем операцию
            var type     = typeof(SumOperation);
            var memebers = type.GetMembers();

            // добавить операцию в калькулятор


            string[] operations = calc.Operations
                                  .Select(o => o.Name)
                                  .ToArray();

            if (args.Length == 0)
            {
                Console.WriteLine("Список операций:");

                foreach (var item in operations)
                {
                    Console.WriteLine(item);
                }
                Console.WriteLine("Введите операцию: ");


                operation = Console.ReadLine();

                Console.WriteLine("Введите аргументы через пробел: ");
                var operands = Console.ReadLine();
                values = ConvertToDouble(
                    operands.Split(new[] { " ", ";" }, StringSplitOptions.RemoveEmptyEntries)
                    );
            }
            else
            {
                operation = args[0].ToLower();
                values    = ConvertToDouble(args, 1);
            }

            var result = calc.Execute(operation, values);

            Console.WriteLine(result);

            Console.ReadKey();
        }
Пример #4
0
        private void btnExec_Click(object sender, EventArgs e)
        {
            // получить операнды
            var values = tbInput.Text
                         .Split(' ')
                         .Select(Convert.ToDouble)
                         .ToArray();

            // получить операцию
            var operation = cbOperation.Text;

            // делаем расчёт
            var result = Calc.Execute(operation, values);

            // Выводим результат
            lblResult.Text = $"{result}";
        }
Пример #5
0
        private void btnExec_Click(object sender, EventArgs e)
        {
            //получить операнды
            var values = tbInput.Text.Split(' ').Select(Convert.ToDouble).ToArray();

            //получить операции
            var operation = cbOperation.Text;

            //создаем калькулятор
            Calc = new Core.Calc();

            //делаем расчет
            var result = Calc.Execute(operation, values);

            //выводим результат
            //lblResult.Text = string.Format("Result = {0}", result);
            lblResult.Text = $"{result}";
        }
Пример #6
0
        //[DllImport("LukoilCalcFinance.dll")]
        //static extern string Name();

        //[DllImport("LukoilCalcFinance.dll")]
        //static extern double? Execute();

        static void Main(string[] args)
        {
            double[] values;
            var      calc = new Core.Calc();
            string   operands, operation;

            while (true)
            {
                string[] operations = calc.Operations
                                      .Select(o => o.Name)
                                      .ToArray();

                if (args.Length == 0)
                {
                    Console.WriteLine("Operation list: ");

                    foreach (var item in operations)
                    {
                        Console.WriteLine(item);
                    }

                    Console.WriteLine("Enter operation: ");
                    operation = Console.ReadLine();

                    Console.WriteLine("Enter operands (use space): ");
                    operands = Console.ReadLine();
                    values   = ConvertToDouble(
                        operands.Split(new[] { " ", ";" }, StringSplitOptions.RemoveEmptyEntries)
                        );
                }
                else
                {
                    operation = args[0].ToLower();
                    values    = ConvertToDouble(args, 1);
                }

                var result = calc.Execute(operation, values);
                Console.WriteLine(result);
            }
        }