Пример #1
0
        static void Main(string[] args)
        {
            CalcMath Math  = new CalcMath();
            string   input = Console.ReadLine();

            while (input != null && input != "")
            {
                int      i            = 0;
                string   stringNumber = "";
                double[] number       = new double[1000];
                int      position     = 0;
                //Zpracování vstupu
                while (i < input.Length)
                {
                    char character = input[i];
                    if (!char.IsDigit(character) && !char.IsWhiteSpace(character))
                    {
                        Console.WriteLine("Špatný vstup.");
                        Console.ReadKey(true);
                        Environment.Exit(0);
                    }
                    if (char.IsDigit(character))
                    {
                        stringNumber += character;
                    }
                    if ((char.IsWhiteSpace(character) || input.Length == (1 + i)) && stringNumber != "")
                    {
                        number[position] = double.Parse(stringNumber);
                        position++;
                        stringNumber = "";
                    }
                    i++;
                }
                //Směrodatná odchylka
                double average = 0;
                for (int n = 0; n < position; n++)
                {
                    average = Math.Add(average, number[n]);
                }
                average = Math.Divide(average, position);
                double sum = 0;
                for (int n = 0; n < position; n++)
                {
                    number[n] = Math.Multipy(Math.Subtract(number[n], average), Math.Subtract(number[n], average));
                    sum       = Math.Add(sum, number[n]);
                }
                double result = Math.Divide(sum, position);
                result = Math.Root(result, 2);
                Console.WriteLine(result.ToString());
                input = Console.ReadLine();
            }
        }
Пример #2
0
        public void TestAddition()
        {
            int expected = 5;
            int actual   = CalcMath.Add(2, 3);

            Assert.AreEqual(expected, actual);
        }
Пример #3
0
 public void TestAdd()
 {
     Assert.AreEqual(0, mathclass.Add(0, 0), PRECISION);
     Assert.AreEqual(-1, mathclass.Add(1, -2), PRECISION);
     Assert.AreEqual(1, mathclass.Add(0.5, 0.5), PRECISION);
     Assert.AreEqual(double.PositiveInfinity, mathclass.Add(double.PositiveInfinity, 5), PRECISION);
     Assert.AreEqual(double.NegativeInfinity, mathclass.Add(double.NegativeInfinity, 5), PRECISION);
     Assert.IsTrue(double.IsNaN(mathclass.Add(double.NaN, 5)));
     Assert.IsTrue(double.IsNaN(mathclass.Add(double.PositiveInfinity, double.NegativeInfinity)));
 }
Пример #4
0
        private double eval(double rightOp, double leftOp, char operand)
        {
            switch (operand)
            {
            case '+':
                return(o_mathLib.Add(leftOp, rightOp));

            case '-':
                return(o_mathLib.Subtract(leftOp, rightOp));

            case '*':
                return(o_mathLib.Multipy(leftOp, rightOp));

            case '/':
                return(o_mathLib.Divide(leftOp, rightOp));

            case '^':
                return(o_mathLib.Pow(leftOp, rightOp));

            case '@':
                return(o_mathLib.Root(rightOp, leftOp));

            case '%':
                return(o_mathLib.Modulo(leftOp, rightOp));

            case 'L':
                return(o_mathLib.Log(rightOp));

            case 'n':
            case 'N':
                return(o_mathLib.Multipy(-1, rightOp));

            case 'p':
            case 'P':
                return(rightOp);

            case '!':
                byte byteVal = 0;
                try { byteVal = Convert.ToByte(rightOp); }
                catch
                {
                    // TODO: Chyba
                    return(double.NaN);
                }
                return(o_mathLib.Fact(byteVal));

            default:
                return(double.NaN);
            }
        }
        public static int calculate(int firstOpNum, int secondOpNum, string myOperator)
        {
            switch (myOperator)
            {
            case "+":
                return(CalcMath.Add(firstOpNum, secondOpNum));

            case "-":
                return(CalcMath.Subtract(firstOpNum, secondOpNum));

            case "/":
                return(CalcMath.Divide(firstOpNum, secondOpNum));

            case "*":
                return(CalcMath.Multiply(firstOpNum, secondOpNum));

            case "%":
                return(CalcMath.Modulus(firstOpNum, secondOpNum));

            default:
                return(0);
            }
        }