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); } }
private void PrefixNotationButton_Click(object sender, EventArgs e) { ListExpresstionTextBox.Clear(); Notation ntn = new PrefixNotation(); ShowExpression(ntn); }
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)); }