Ejemplo n.º 1
0
        private double ProcessUnaryOperation(operations operation)
        {
            switch (operation)
            {
            case operations.Sin:
                return(Math.Sin(_operand1));

            case operations.Cos:
                return(Math.Cos(_operand1));

            case operations.Tan:
                return(Math.Tan(_operand1));

            case operations.Squared:
                return(Math.Pow(_operand1, 2));

            case operations.SqareRoot:
                return(Math.Sqrt(_operand1));

            case operations.Pi:
                return(3.14159265359 * (_operand1));

            default:
                DisplayContent = "That is not a known Operation";
                return(0);
            }
        }
Ejemplo n.º 2
0
        public PointerMaths GetPointer(operations operation)
        {
            PointerMaths pointerMaths = null;

            switch (operation)
            {
            case operations.Add:
                pointerMaths = Add;
                break;

            case operations.Sub:
                pointerMaths = Sub;
                break;

            case operations.Mul:
                pointerMaths = Mul;
                break;

            case operations.Div:
                pointerMaths = Div;
                break;

            case operations.All:
                pointerMaths += Add;
                pointerMaths += Sub;
                pointerMaths += Mul;
                pointerMaths += Div;
                break;

            default:
                break;
            }

            return(pointerMaths);
        }
Ejemplo n.º 3
0
    public void setParameters(string _task, float _correctAnswer, int _rangeOfNumbers, FMC_Settings.numberType _numberTypeFront, FMC_Settings.numberType _numberTypeBack, operations _operation, taskTypes _taskType, float _timeSpecification, int _lastNumber)
    {
        task              = _task;
        correctAnswer     = Mathf.RoundToInt(_correctAnswer);
        rangeOfNumbers    = _rangeOfNumbers;
        numberTypeFront   = _numberTypeFront;
        numberTypeBack    = _numberTypeBack;
        operation         = _operation;
        taskType          = _taskType;
        timeSpecification = _timeSpecification;
        answeredUsingBomb = false;
        lastNumber        = _lastNumber;

        wrongAnswerSelection = new float[] { -1, -1, -1 };
        if (rangeOfNumbers >= 10)
        {
            wrongAnswerSelection[0] = Random.Range(0, rangeOfNumbers + 1);
            wrongAnswerSelection[1] = Random.Range(0, rangeOfNumbers + 1);
            wrongAnswerSelection[2] = Random.Range(0, rangeOfNumbers + 1);

            while (wrongAnswerSelection[0] == correctAnswer)
            {
                wrongAnswerSelection[0] = Random.Range(0, rangeOfNumbers + 1);
            }
            while (wrongAnswerSelection[1] == correctAnswer || wrongAnswerSelection[1] == wrongAnswerSelection[0])
            {
                wrongAnswerSelection[1] = Random.Range(0, rangeOfNumbers + 1);
            }
            while (wrongAnswerSelection[2] == correctAnswer || wrongAnswerSelection[2] == wrongAnswerSelection[0] || wrongAnswerSelection[2] == wrongAnswerSelection[1])
            {
                wrongAnswerSelection[2] = Random.Range(0, rangeOfNumbers + 1);
            }
        }
    }
Ejemplo n.º 4
0
 /* test une valeur de mood */
 public bool TestValue(string name,operations type, int value)
 {
     Debug.Log("testing " + name + " " + type + " " + value);
     if (type == operations.SUP)
         return ((int)moods[name] >= value);
     else
        return ((int)moods[name] <= value);
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            operations execute = new operations(Add);

            execute += Difference;
            execute += Product;
            execute += Quotient;
            execute.Invoke(80, 20);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Displays the given text in the result box.
 /// </summary>
 private void showError(string text)
 {
     resultBox.Text = text;
     previousText   = null;
     operationCheck = false;
     clearNext      = true;
     updateEquationBox("");
     currentOperation = operations.NULL;
     resetFontSize();
 }
Ejemplo n.º 7
0
        private void buttonROOT_Click(object sender, EventArgs e)
        {
            if (operation == operations.ROOT && !eq)
            {
                Execute();
                eq = false;
            }

            n          = double.Parse(textBox.Text);
            operation  = operations.ROOT;
            new_number = true;
            RemoveComa();
        }
Ejemplo n.º 8
0
    public static bool IsFirstClassOperation(operations operation)
    {
        switch (operation)
        {
        case operations.Multiply:
        case operations.Divide:
        case operations.Mod:
        {
            return(true);
        }
        }

        return(false);
    }
Ejemplo n.º 9
0
        private void buttonADD_Click(object sender, EventArgs e)
        {
            if (operation == operations.ADD && !eq)
            {
                Execute();
                eq = false;
            }

            n = 0;
            double.TryParse(textBox.Text, out n);
            operation  = operations.ADD;
            new_number = true;
            RemoveComa();
        }
Ejemplo n.º 10
0
        private double logik(double value, operations operation)
        {
            bool unarn;

            if (operation == operations.sq ||
                operation == operations.sq_root ||
                operation == operations.sin ||
                operation == operations.cos ||
                operation == operations.tg ||
                operation == operations.ctg)
            {
                unarn = true;
            }
            else
            {
                unarn = false;
            }
            if (this.first == 0)
            {
                set_first(value);
                set_oper(operation);
                if (unarn)
                {
                    f_calculate();
                }
                return(this.first);
            }
            if (this.operation != operations.empty)
            {
                set_second(value);
                f_calculate();
                set_oper(operation);
                if (unarn)
                {
                    f_calculate();
                }
                return(this.first);
            }
            else
            {
                if (value != this.first)
                {
                    set_first(value);
                }
                set_oper(operation);
                return(this.first);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Deals with double operand function clicks.
        /// </summary>
        private void doubleOperandFunction(object sender, RoutedEventArgs e)
        {
            if (errors.Contains(resultBox.Text))
            {
                return;
            }

            if (operationCheck && !isOldText)
            {
                calculateResult();
            }

            Button button = (Button)sender;

            operationCheck = true;
            previousText   = resultBox.Text;
            string buttonText = button.Content.ToString();
            string equation   = previousText + " " + buttonText + " ";

            switch (buttonText)
            {
            case "/":
                currentOperation = operations.DIVISION;
                break;

            case "x":
                currentOperation = operations.MULTIPLICATION;
                break;

            case "-":
                currentOperation = operations.SUBTRACTION;
                break;

            case "+":
                currentOperation = operations.ADDITION;
                break;

            case "x^y":
                currentOperation = operations.POWER;
                break;
            }
            updateEquationBox(equation);
            resetFontSize();
            showText(resultBox.Text);
            isOldText = true;
        }
Ejemplo n.º 12
0
        private void SetOperation(object obj)
        {
            operations operation = CurrentOperator(obj.ToString());

            if (double.TryParse(operandstring, out double result))
            {
                if (BianaryOperatons.ContainsValue(operation))
                {
                    if (operation == operations.Equals)
                    {
                        _operand2       = result;
                        DisplayContent  = ProcessBinaryOperation(_binaryOperator).ToString();
                        _binaryOperator = operations.None;
                    }
                    else if (operation == operations.Precent)
                    {
                        _operand2       = result;
                        _binaryOperator = operations.Precent;
                        DisplayContent  = ProcessBinaryOperation(_binaryOperator).ToString();
                    }
                    else
                    {
                        _operand1       = result;
                        _binaryOperator = operation;
                        operandstring   = "";
                        DisplayContent  = "";
                    }
                }
                else if (UnaryOperations.ContainsValue(operation))
                {
                    _operand1      = result;
                    DisplayContent = ProcessUnaryOperation(operation).ToString();
                }
                else
                {
                    DisplayContent = "That is not a known Operation";
                }

                operandstring = DisplayContent;
            }
            else
            {
                DisplayContent = "Please enter a real number.";
            }
        }
Ejemplo n.º 13
0
        public static double getResult(operations op)
        {
            switch (op)
            {
            case operations.plus: return(last = mem1 + mem2);

            case operations.minus: return(last = mem1 - mem2);

            case operations.mult: return(last = mem1 * mem2);

            case operations.div: return(last = mem1 / mem2);

            case operations.sqrt: return(last = Math.Sqrt(mem1));

            case operations.pow: return(last = Math.Pow(mem1, mem2));

            case operations.inv: return(last = -mem1);
            }
            return(0);
        }
        public void TestMethod1(operations MathOperation, int num1, int num2, int result)
        {
            switch (MathOperation)
            {
            case operations.Add:
                Assert.AreEqual(result, Math_Add.iAdd(num1, num2));
                break;

            case operations.Subtract:
                Assert.AreEqual(result, Math_Sub.iSubtract(num1, num2));
                break;

            case operations.Multiply:
                Assert.AreEqual(result, Math_Mul.iMultiply(num1, num2));
                break;

            case operations.Divide:
                Assert.AreEqual(result, Math_Div.iDivide(num1, num2));
                break;
            }
        }
Ejemplo n.º 15
0
        public void SetStripButtonState(operations operationType)
        {
            //Disable all and set default text
            this.CreateStripButton.Enabled       = false;
            this.AlterStripButton.Enabled        = false;
            this.DropStripButton.Enabled         = false;
            this.QueryStripButton.Enabled        = false;
            this.exportToolStripMenuItem.Enabled = false;

            if (operationType == operations.New)
            {
                //Enable/Disable Buttons
                CreateStripButton.Enabled = true;
            }
            else if (operationType == operations.Show)
            {
                this.AlterStripButton.Enabled        = true;
                this.DropStripButton.Enabled         = true;
                this.QueryStripButton.Enabled        = true;
                this.exportToolStripMenuItem.Enabled = true;
            }
        }
Ejemplo n.º 16
0
    public static string Operation(operations operation)
    {
        switch (operation)
        {
        case operations.Plus:
            return("+");

        case operations.Minus:
            return("-");

        case operations.Multiply:
            return("*");

        case operations.Divide:
            return(":");

        case operations.Mod:
            return("%");
        }

        return("+");
    }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            Console.WriteLine("Escribe un número del 0 al 5");
            int        input     = Convert.ToInt32(Console.ReadLine());
            operations selection = (operations)input;

            switch (selection)
            {
            case operations.suma:
                Console.WriteLine("Has elegido suma.");
                break;

            case operations.resta:
                Console.WriteLine("Has elegido resta.");
                break;

            case operations.multiplicación:
                Console.WriteLine("Has elegido multiplicación");
                break;

            case operations.división:
                Console.WriteLine("Has elegido división.");
                break;

            case operations.raíz2:
                Console.WriteLine("Has elegido Raíz Cuadrada");
                break;

            case operations.potencia:
                Console.WriteLine("Has elegido Potencia");
                break;

            default:
                Console.WriteLine("Caso no contemplado.");
                break;
            }
        }
Ejemplo n.º 18
0
        static double enumOperation(double a, double b, operations op)
        {
            double rezult = 0;

            switch ((int)op)
            {
            case 0:
                rezult = a + b;
                break;

            case 1:
                rezult = a - b;
                break;

            case 2:
                rezult = a * b;
                break;

            case 3:
                rezult = a / b;
                break;
            }
            return(rezult);
        }
Ejemplo n.º 19
0
        protected XmlRequestsBase(operations operation)
        {
            XmlRequest = new XmlDocument();
            XmlDeclaration declaration = XmlRequest.CreateXmlDeclaration("1.0", "UTF-8", null);

            XmlRequest.AppendChild(declaration);
            XmlNode MDaemonEl   = XmlRequest.CreateElement(_xmlElement.MDaemon.ToString());
            XmlNode ApiEl       = XmlRequest.CreateElement(_xmlElement.API.ToString());
            XmlNode RequestEl   = XmlRequest.CreateElement(_xmlElement.Request.ToString());
            XmlNode OperationEl = XmlRequest.CreateElement(_xmlElement.Operation.ToString());

            Parameters = XmlRequest.CreateElement(_xmlElement.Parameters.ToString());

            XmlRequest.AppendChild(MDaemonEl);
            MDaemonEl.AppendChild(ApiEl);
            ApiEl.AppendChild(RequestEl);
            RequestEl.AppendChild(OperationEl);
            RequestEl.AppendChild(Parameters);

            OperationEl.InnerText = operation.ToString();

            XmlAttribute requestVerboseAtt  = XmlRequest.CreateAttribute(_xmlAttribute.verbose.ToString());
            XmlAttribute requestEchoAtt     = XmlRequest.CreateAttribute(_xmlAttribute.echo.ToString());
            XmlAttribute requestVersionAtt  = XmlRequest.CreateAttribute(_xmlAttribute.version.ToString());
            XmlAttribute requestEncodingAtt = XmlRequest.CreateAttribute(_xmlAttribute.encoding.ToString());

            requestVerboseAtt.InnerText  = requestVerbose;
            requestEchoAtt.InnerText     = requestEcho;
            requestVersionAtt.InnerText  = requestVersion;
            requestEncodingAtt.InnerText = requestEncoding;

            RequestEl.Attributes.Append(requestVerboseAtt);
            RequestEl.Attributes.Append(requestEchoAtt);
            RequestEl.Attributes.Append(requestVersionAtt);
            RequestEl.Attributes.Append(requestEncodingAtt);
        }
Ejemplo n.º 20
0
        private double ProcessBinaryOperation(operations operation)
        {
            switch (operation)
            {
            case operations.Add:
                return(_operand1 + _operand2);

            case operations.Subtract:
                return(_operand1 - _operand2);

            case operations.Multiply:
                return(_operand1 * _operand2);

            case operations.Divide:
                return(_operand1 / _operand2);

            case operations.Precent:
                return(_operand1 * (_operand2 / 100));

            default:
                DisplayContent = "That is not a known Operation";
                return(0);
            }
        }
Ejemplo n.º 21
0
        public string input(string number, operations operation)
        {
            double value = Convert.ToDouble(number);

            return(Convert.ToString(logik(value, operation)));
        }
Ejemplo n.º 22
0
 void set_oper(operations operation)
 {
     this.operation = operation;
 }
Ejemplo n.º 23
0
 public void clear()
 {
     this.first     = 0;
     this.second    = 0;
     this.operation = operations.empty;
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Calculates the result by solving the previousText and current text in the result
        /// box with the operand in currentOperation.
        /// </summary>
        private void calculateResult()
        {
            if (currentOperation == operations.NULL)
            {
                return;
            }

            double a = double.Parse(previousText);   // first operand
            double b = double.Parse(resultBox.Text); // second operand
            double result;

            switch (currentOperation)
            {
            case operations.DIVISION:
                result = a / b;
                break;

            case operations.MULTIPLICATION:
                result = a * b;
                break;

            case operations.ADDITION:
                result = a + b;
                break;

            case operations.SUBTRACTION:
                result = a - b;
                break;

            case operations.POWER:
                result = Math.Pow(a, b);
                break;

            default:
                return;
            }

            if (errors.Contains(resultBox.Text))
            {
                return;
            }

            operationCheck = false;
            previousText   = null;
            string equation;

            // If a function button was not clicked during a mathematical operation then the equation box will have the text with the
            // format <operand a> <operation> <operand b as a number> else <operand a> <operation> <func>(<operand b>)
            if (!functionCheck)
            {
                equation = equationBox.Text + b.ToString();
            }
            else
            {
                equation      = equationBox.Text;
                functionCheck = false;
            }
            updateEquationBox(equation);
            showText(result.ToString());
            currentOperation = operations.NULL;
            isResult         = true;
        }
Ejemplo n.º 25
0
        public void SetStripButtonState(operations operationType)
        {
            //Disable all and set default text
            this.CreateStripButton.Enabled = false;
            this.AlterStripButton.Enabled = false;
            this.DropStripButton.Enabled = false;
            this.QueryStripButton.Enabled = false;
            this.exportToolStripMenuItem.Enabled = false;

            if (operationType == operations.New)
            {
                //Enable/Disable Buttons
                CreateStripButton.Enabled = true;
            }
            else if (operationType == operations.Show)
            {
                this.AlterStripButton.Enabled = true;
                this.DropStripButton.Enabled = true;
                this.QueryStripButton.Enabled = true;
                this.exportToolStripMenuItem.Enabled = true;
            }

        }
Ejemplo n.º 26
0
 protected static readonly IBlockOperation s_unsetBlock = new BlockOperation(
     operations: ImmutableArray <IOperation> .Empty, locals: default, semanticModel: null, syntax: null, type: null, constantValue: null, isImplicit: true);
Ejemplo n.º 27
0
        /// <summary>
        /// Standard run-method. Call this for the 'talk'-action.
        /// </summary>
        /// <param name="args">The commandline-parameters.</param>
        public override void Run(string[] args)
        {
            operations operation = operations.help;

            string username  = "";
            string myName    = "";
            bool   propagate = false;

            try
            {
                for (int i = 1; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "-lo":
                    case "-logout":
                        operation = operations.logout;
                        username  = args[++i].Trim();
                        break;

                    case "-l":
                    case "-login":
                        operation = operations.login;
                        username  = args[++i].Trim();
                        break;

                    case "-r":
                    case "-register":
                        operation = operations.newuser;
                        username  = args[++i].Trim();
                        if ((args.Length > i + 1) && (args[++i] == "-p"))
                        {
                            propagate = true;
                        }
                        break;

                    case "-u":
                        operation = operations.talk;
                        myName    = args[++i].Trim();
                        username  = args[++i].Trim();
                        break;

                    case "-h":
                        Help();
                        return;

                    default:
                        textWriter.WriteLine("Error: invalid parameter");
                        break;
                    }
                }
            }
            catch
            {
                textWriter.WriteLine("Error: invalid parameter");
                return;
            }

            switch (operation)
            {
            case operations.logout:
                LogoutUser(username);
                break;

            case operations.login:
                LoginUser(username, new TalkMessageListener(textWriter));
                break;

            case operations.newuser:
                CreateUser(username, propagate);
                textWriter.WriteLine("(wait 20 sec for RDV SRDI indexing).");
                for (int i = 1; i < 20; i++)
                {
                    Thread.Sleep(1000);
                    textWriter.Write(".");
                }
                textWriter.WriteLine();
                break;

            case operations.talk:
                TalkToUser(myName, username);
                break;

            default:
                textWriter.WriteLine("Error: invalid parameter");
                break;
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Standard run-method. Call this for the 'search'-action.
        /// </summary>
        /// <param name="args">The commandline-parameters.</param>
        public override void Run(string[] args)
        {
            String peerID = null;
            String attr   = "Name";
            String val    = @"*";
            //String query = null;
            //String infile = null;
            Int32 num = 10;

            try
            {
                if (args.Length == 1)
                {
                    operation = operations.local;
                }
                else
                {
                    for (int i = 1; i < args.Length; i++)
                    {
                        switch (args[i])
                        {
                        case "-p":
                            operation = operations.remote;
                            peerID    = args[++i].Trim();
                            break;

                        case "-r":
                            operation = operations.remote;
                            break;

                        case "-f":
                            operation = operations.flush;
                            break;

                        case "-a":
                            operation = operations.local;
                            attr      = args[++i].Trim();
                            break;

                        case "-n":
                            operation = operations.local;
                            num       = Convert.ToInt32(args[++i].Trim());
                            break;

                        case "-v":
                            operation = operations.local;
                            val       = args[++i].Trim();
                            break;

                        /*case "-q":
                         *  operation = operations.remote;
                         *  query = args[++i].Trim();
                         *  break;*/
                        /*case "-i":
                         *  operation = operations.remote;
                         *  infile = args[++i].Trim();
                         *  query = ReadQueryFile(infile);
                         *  break;*/
                        case "-h":
                            operation = operations.help;
                            break;

                        default:
                            textWriter.WriteLine("Error: invalid parameter");
                            return;
                        }
                    }
                }
            }
            catch
            {
                textWriter.WriteLine("Error: invalid parameter");
                return;
            }

            switch (operation)
            {
            case operations.remote:
                PeerSearch(peerID, attr, val, num /*, query*/);
                break;

            case operations.local:
                PeerSearch(peerID, attr, val, num /*, query*/);
                break;

            case operations.flush:
                textWriter.WriteLine("Flushing...");
                discovery.FlushAdvertisements(null, DiscoveryService.DISC_ADV);
                break;

            case operations.help:
                Help();
                return;
            }
        }
Ejemplo n.º 29
0
 private void button_handler(operations operation)
 {
     textBox1.Text = calculate.input(textBox1.Text, operation);
     flag          = true;
 }
Ejemplo n.º 30
0
 private void button1_Click(object sender, EventArgs e)
 {
     nowOperation = operations.Node;
 }
Ejemplo n.º 31
0
 private void button3_Click(object sender, EventArgs e)
 {
     nowOperation = operations.Path;
 }
Ejemplo n.º 32
0
        public static bool Compare(Nullable <bool> condition1, Nullable <bool> condition2, operations operation)
        {
            if (operation == operations.AND)
            {
                return(condition1 == true && condition2 == true);
            }

            if (operation == operations.OR)
            {
                return(condition1 == true || condition2 == true);
            }

            MainWindow.error("Some error occurred parsing your conditions", true);

            return(false);
        }