A C# console application that evaluates mathematical expressions using two different strategies: Recursion and Stack-based evaluation.
- Basic Operations: Supports addition (
+), subtraction (-), multiplication (*), and division (/). - Parentheses: Handles nested parentheses
()for operation precedence. - Decimal Support: Can calculate expressions involving decimal numbers.
- Dual Strategies:
- Recursion: Evaluates expressions by breaking them down into smaller sub-expressions recursively.
- Stack: Evaluates expressions using a stack-based approach (Shunting-yard algorithm concept).
- .NET SDK (Compatible with C# console applications)
- Clone the repository.
- Navigate to the project directory.
- Run the application using
dotnet runor by building the solution and executing the binary.
dotnet run --project .Upon running, the application will:
- Read and evaluate expressions from
sample_expressions.txtif the file exists. - Enter an interactive mode where you can type expressions.
Input Format: Expressions must be space-delimited. Each operand and operator must be separated by a space.
Example:
1 + 2 * ( 3 + 4 )
Output:
The program displays the result calculated by both the Recursion and Stack implementations.
Recursion : 1 + 2 * ( 3 + 4 ) = 15
Stack : 1 + 2 * ( 3 + 4 ) = 15
Type STOP to exit the application.
Program.cs: Main entry point. Handles user input and file reading.Calculator.cs: Abstract base class defining theCalculatorinterface and common validation logic.RecursionCalculator.cs: Implementation using recursive logic.StackCalculator.cs: Implementation using stack-based logic.sample_expressions.txt: A text file containing sample expressions to be evaluated on startup.