/// <summary> /// Removes the last expression component from the expresssion /// </summary> /// <param name="displayString">The string bound to the string displayed in the ui</param> public void Delete(DisplayString displayString) { if (expressionString.Length != 0) { switch (expressionString[expressionString.Length - 1]) { case ')': parenOpenCount++; break; case '(': parenOpenCount--; //check for sin, cos, tan, sqrt and delete more characters is detected if (expressionString.Length > 2) { switch (expressionString[expressionString.Length - 2]) { case 'n': //sin and tan case 's': //cos expressionString.Remove(expressionString.Length - 3, 3); break; case 't': //sqrt expressionString.Remove(expressionString.Length - 4, 4); break; } } break; case '\uDF0B': //pi Technically 2 characters in ascii expressionString.Remove(expressionString.Length - 1, 1); break; } expressionString.Remove(expressionString.Length - 1, 1); } displayString.Display = expressionString.ToString(); }
public MainWindow() { InitializeComponent(); expressionCharGroups = new Dictionary <ExpressionComponent, ButtonGroup>(); errorDisplay = new DisplayString(); inputDisplay = new DisplayString(); outputDisplay = new DisplayString(); inputExpression = new Expression(inputDisplay); //Create dictionary of sets of buttons expressionCharGroups.Add(ExpressionComponent.Constants, new ButtonGroup(new Button[] { btnE, btnPi })); expressionCharGroups.Add(ExpressionComponent.Digits, new ButtonGroup(new Button[] { btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9 })); expressionCharGroups.Add(ExpressionComponent.Decimal, new ButtonGroup(new Button[] { btnDecimal })); expressionCharGroups.Add(ExpressionComponent.Minus, new ButtonGroup(new Button[] { btnMinus })); expressionCharGroups.Add(ExpressionComponent.Operators, new ButtonGroup(new Button[] { btnPlus, btnMultiply, btnDivide, btnExponent })); expressionCharGroups.Add(ExpressionComponent.ParenClose, new ButtonGroup(new Button[] { btnParenRight })); expressionCharGroups.Add(ExpressionComponent.ParenOpen, new ButtonGroup(new Button[] { btnParenLeft, btnSin, btnCos, btnTan, btnSqrt })); displayError.DataContext = errorDisplay; displayIn.DataContext = inputDisplay; displayOut.DataContext = outputDisplay; SetButtonStateButtons(); }
/// <summary> /// Clears the expression string /// </summary> /// <param name="displayString">The string bound to the string displayed in the ui</param> public void Clear(DisplayString displayString) { expressionString.Clear(); displayString.Display = ""; }
public Expression(DisplayString input) { expressionString = new StringBuilder(); this.input = input; }