本次代写是C#算数表达式解析器相关的一个assignment
Assignment Instructions:
Read each step’s instructions carefully before you write any code.
In this assignment you will create the ExpressionTree class in your logic engine DLL. You will
create a standalone console application as well, to demo its functionality. The ExpressionTree class will
implement an arithmetic expression parser that builds a tree for the expression. This tree can then be
used for evaluation of the expression. The parsing aspect of this assignment is simplified and you will
extend the parser in the next homework. But the entire evaluation functionality, including setting
variable values, will be implemented in this assignment.
Create a class named ExpressionTree in the CptS321 namespace. (Do not create a class named
expTree, EXPTREE, etc. Make a class name that is an EXACT match including casing. Part of this
assignment is likely to be tested automatically and it will not give you credit if it cannot find the class.)
Create this class in your logic engine DLL. The console app for this assignment just references your
engine DLL and provides a simple menu for testing. The console application, the logic engine DLL, and
your test project are to be submitted for grading. Include the following functions in the ExpressionTree
class, again with EXACT signatures matching:
● public ExpressionTree(string expression)
Implement this constructor to construct the tree from the specific expression
● public void SetVariable(string variableName, double variableValue)
Sets the specified variable within the ExpressionTree variables dictionary
● public double Evaluate()
Implement this method with no parameters that evaluates the expression to a double
value
Create a console application that presents a menu when run. As another reminder, this app
references your engine DLL. This menu must contain the following options:
1. The option to enter an expression string. You may assume that only valid expressions will be
entered with no whitespaces. Simplified expressions are used for this assignment and the
assumptions you are allowed to make are discussed later on.
2. The option to set a variable value in the expression. This must prompt for both the variable
name and then the variable value.
3. The option to evaluate to the expression to a numerical value.
4. The option to quit.
5. Should the user enter an “option” that isn’t one of these 4, simply ignore it. As trivial as this may
seem it is vital should the assignment be tested with an automated grading app.
● On that note, also avoid use of Console.ReadKey() as it can be problematic when grading
with an automated app. Simply fall through to the end of main after the quit option is
selected.
The screenshot below shows what this might look like:
Requirement Details:
Support simplified expressions:
● For this assignment all expressions will be simplified next to what you’ll have to support in the
next homework. As stated earlier, this assignment is primarily about getting the correct
evaluation logic in place for the tree.
● Assume expressions will NOT have any parentheses
● Assume expressions will only have a single type of operator, but can have any number of
instances of that operator in the expression
o Example 1: expression could be “A+B+C1+Hello+6”
o Example 2: expression could be “C2-9-B2-27”
o Example 3: expression could NOT be “X+Y-Z” because that has two different types of
operators: + and –
● (In the next assignment you’ll have to support all valid arithmetic expressions)
● Support operators +,-,*, and / for addition, subtraction, multiplication, and division, respectively.
Again, only one type will be present in an expression that the user enters.
● Parse the expression that the user enters and build the appropriate tree in memory