Exemplo n.º 1
0
        private void InfixNotationButton_Click(object sender, EventArgs e)
        {
            ListExpresstionTextBox.Clear();
            Notation ntn = new InfixNotation();

            ShowExpression(ntn);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                //IExpression exp = new DivExp(new ConstExp(0), MonomialExp.createInstance(3, 0));
                IExpression exp = new DivExp(new MulExp(new ConstExp(10), MonomialExp.createInstance(3, 0)), new AddExp(new MulExp(MonomialExp.createInstance(5, 2), new ConstExp(4)), MonomialExp.createInstance(3, 2)));
                //IExpression exp = new DivExp(MonomialExp.createInstance(3, 2), new ConstExp(-2));
                double eValue = exp.evaluate(3);
                Console.WriteLine("Value:");
                Console.WriteLine("The value of expression when x = 3 : {0}", eValue);
                // ---------------
                Console.WriteLine("\nNotations:");
                INotation infixNtn  = new InfixNotation();
                INotation prefixNtn = new PrefixNotation();
                INotation posfixNtn = new PosfixNotation();

                Console.WriteLine("Infix Notation: {0}", exp.toString(infixNtn));

                Console.WriteLine("Prefix Notation: {0}", exp.toString(prefixNtn));

                Console.WriteLine("Posfix Notation: {0}", exp.toString(posfixNtn));

                // ---------------
                Console.WriteLine("\nDerivative with notations:");
                Console.WriteLine("Infix Notation: {0}", exp.derive().toString(infixNtn));

                Console.WriteLine("Prefix Notation: {0}", exp.derive().toString(prefixNtn));

                Console.WriteLine("Posfix Notation: {0}", exp.derive().toString(posfixNtn));
            }
            catch (Exception e)
            {
                Console.WriteLine("Error : {0}", e.Message);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            // (3x^2 + 7) / (4x^3 + 5)
            Expression exp = new DivExpr(
                                new AddExpr(
                                    MonomialExpr.createObject(3, 2),
                                    ConstExpr.createObject(7)),
                                new AddExpr(
                                    MonomialExpr.createObject(4, 3),
                                    ConstExpr.createObject(5)));

            InfixNotation infix = new InfixNotation();
            PrefixNotation prefix = new PrefixNotation();
            PostfixNotation postfix = new PostfixNotation();

            Console.WriteLine(exp.ToString(infix));
            Console.WriteLine(exp.ToString(prefix));
            Console.WriteLine(exp.ToString(postfix));
        }
Exemplo n.º 4
0
        private void DeriveButton_Click(object sender, EventArgs e)
        {
            ListExpresstionTextBox.Clear();

            Notation   ntn      = new InfixNotation();
            Expression constExp = new ConstExp(double.Parse(ConstExpressionTextBox.Text));
            Expression monoExp  = GetMonoExpression(MonomialExpressionTextBox.Text);

            Expression binExp1 = GetMonoExpression(BinaryExpression1TextBox.Text);
            Expression binExp2 = GetMonoExpression(BinaryExpression2TextBox.Text);
            Expression binExp  = null;

            constExp = constExp.Derive();
            monoExp  = monoExp.Derive();

            ListExpresstionTextBox.AppendText(constExp.toString(ntn) + "\n");
            ListExpresstionTextBox.AppendText(monoExp.toString(ntn) + "\n");


            string ope = OperatorTextBox.Text;

            switch (ope)
            {
            case "+":
                binExp = new AddExp(binExp1, binExp2).Derive();
                break;

            case "-":
                binExp = new MinusExp(binExp1, binExp2).Derive();
                break;

            case "*":
                binExp = new MulExp(binExp1, binExp2).Derive();
                break;

            case "/":
                binExp = new DivExp(binExp1, binExp2).Derive();
                break;
            }
            ListExpresstionTextBox.AppendText(binExp.toString(ntn) + "\n");
        }