Beispiel #1
0
    private FiveDigitInt Merge(CalculatorItem obj_1, CalculatorItem obj_2)
    {
        switch (obj_2.operation)
        {
        case Calculator.operations.Plus:
        {
            return(obj_1.number + obj_2.number);
        }

        case Calculator.operations.Minus:
        {
            return(obj_1.number - obj_2.number);
        }

        case Calculator.operations.Multiply:
        {
            return(obj_1.number * obj_2.number);
        }

        case Calculator.operations.Divide:
        {
            return(obj_1.number / obj_2.number);
        }

        case Calculator.operations.Mod:
        {
            return(obj_1.number % obj_2.number);
        }
        }
        return(null);
    }
Beispiel #2
0
        public ActionResult Get([FromBody] CalculatorItem data)
        {
            try
            {
                string url = "https://waterfootprint.org/calculator-extended";
                using (var webClient = new WebClient())
                {
                    var pars = new NameValueCollection();
                    pars.Add("Country_ID", data.Country_ID.ToString());
                    pars.Add("cereal", data.cereal.ToString());
                    pars.Add("meat", data.meat.ToString());
                    pars.Add("income", data.income.ToString());
                    pars.Add("bathnumber", data.bathnumber.ToString());
                    pars.Add("carweek", data.carweek.ToString());
                    pars.Add("coffee", data.coffee.ToString());
                    pars.Add("diary", data.diary.ToString());
                    pars.Add("dishminute", data.dishminute.ToString());
                    pars.Add("dishnumber", data.dishnumber.ToString());
                    pars.Add("dishweek", data.dishweek.ToString());
                    pars.Add("egg", data.egg.ToString());
                    pars.Add("fat", data.fat.ToString());
                    pars.Add("fruit", data.fruit.ToString());
                    pars.Add("gardenminute", data.gardenminute.ToString());
                    pars.Add("gardenweek", data.gardenweek.ToString());
                    pars.Add("laundryload", data.laundryload.ToString());
                    pars.Add("poolcapacity", data.poolcapacity.ToString());
                    pars.Add("poolnumber", data.poolnumber.ToString());
                    pars.Add("rinsingminute", data.rinsingminute.ToString());
                    pars.Add("root", data.root.ToString());
                    pars.Add("showerminute", data.showerminute.ToString());
                    pars.Add("showernumber", data.showernumber.ToString());
                    pars.Add("sugar", data.sugar.ToString());
                    pars.Add("tap1", data.tap1.ToString());
                    pars.Add("tea", data.tea.ToString());
                    pars.Add("vegetable", data.vegetable.ToString());
                    var    response   = webClient.UploadValues(url, pars);
                    string str        = Encoding.UTF8.GetString(response);
                    var    startIndex = str.IndexOf("InstanceBeginEditable");
                    str        = str.Substring(startIndex);
                    startIndex = str.IndexOf("<br>");
                    for (int i = 0; i < 4; i++)
                    {
                        str        = str.Substring(startIndex + 4);
                        startIndex = str.IndexOf("<br>");
                    }

                    startIndex = str.IndexOf("</font>");
                    str        = str.Substring(0, startIndex);
                    var answer = new
                    {
                        total = str
                    };
                    return(Ok(answer));
                }
            }
            catch (Exception e)
            {
                return(StatusCode(512));
            }
        }
Beispiel #3
0
    public static string Calculate(string expression)
    {
        List <CalculatorItem> calculate_objects_buf = new List <CalculatorItem>();


        Recount(expression, ref calculate_objects_buf);

        for (int i = 0; i < calculate_objects_buf.Count; i++)
        {
            if (calculate_objects_buf[i].number == 0)
            {
                if (calculate_objects_buf[i].operation == Calculator.operations.Divide || calculate_objects_buf[i].operation == Calculator.operations.Mod)
                {
                    return("ERROR");
                }
            }
        }

        List <CalculatorItem> calculate_objects = new List <CalculatorItem>();



        for (int i = 0; i < calculate_objects_buf.Count; i++)
        {
            if (IsFirstClassOperation(calculate_objects_buf[i].operation))
            {
                //Debug.Log("До - " + calculate_objects[calculate_objects.Count - 1].number.ToString());
                calculate_objects[calculate_objects.Count - 1] += calculate_objects_buf[i];
                //Debug.Log("После - " + calculate_objects[calculate_objects.Count - 1].number.ToString());
            }
            else
            {
                calculate_objects.Add(calculate_objects_buf[i]);
            }
        }


        CalculatorItem result = new CalculatorItem();


        for (int i = 0; i < calculate_objects.Count; i++)
        {
            result += calculate_objects[i];
        }


        return(result.number.ToString());
    }
Beispiel #4
0
    //Пересчет всех чисел и операций
    public static void Recount(string expression, ref List <CalculatorItem> calculate_objects)
    {
        char   buf_operation;
        string buf_number = "";

        if (expression[0] == '-')
        {
            buf_operation = expression[0];
        }
        else
        {
            buf_number   += expression[0];
            buf_operation = '+';
        }


        for (int i = 1; i < expression.Length - 1; i++)
        {
            if (!IsOperation(expression[i]))
            {
                buf_number += expression[i];
            }
            else
            {
                CalculatorItem buf_object = new CalculatorItem(buf_number, buf_operation);
                calculate_objects.Add(buf_object);
                buf_number    = "";
                buf_operation = expression[i];
            }
        }

        if (!IsOperation(expression[expression.Length - 1]))
        {
            buf_number += expression[expression.Length - 1];
            CalculatorItem buf_object = new CalculatorItem(buf_number, buf_operation);
            calculate_objects.Add(buf_object);
        }
        else if (buf_number != "")
        {
            CalculatorItem buf_object = new CalculatorItem(buf_number, buf_operation);
            calculate_objects.Add(buf_object);
        }
    }
        public float sum(CalculatorItem number)
        {
            var result = number.A + number.B;

            return(result);
        }
        public float divide(CalculatorItem number)
        {
            var result = number.A / number.B;

            return(result);
        }
        public float multiply(CalculatorItem number)
        {
            var result = number.A * number.B;

            return(result);
        }
        public float substract(CalculatorItem number)
        {
            var result = number.A - number.B;

            return(result);
        }
Beispiel #9
0
 private CalculatorItem(CalculatorItem obj_1, CalculatorItem obj_2)
 {
     this.number    = Merge(obj_1, obj_2);
     this.operation = obj_1.operation;
 }
        public ActionResult <float> DivideElements(CalculatorItem number)
        {
            var result = _services.divide(number);

            return(result);
        }
        public ActionResult <float> MultiplyElements(CalculatorItem number)
        {
            var result = _services.multiply(number);

            return(result);
        }
        public ActionResult <float> SubstractElements(CalculatorItem number)
        {
            var result = _services.substract(number);

            return(result);
        }
Beispiel #13
0
 public Task <int> Delete(CalculatorItem item) => _database.DeleteAsync(item);
Beispiel #14
0
 public Task <int> Insert(CalculatorItem item) =>
 item.Id != 0 ? _database.UpdateAsync(item) : _database.InsertAsync(item);