Skip to content

hylimR/BasicCalculator

Repository files navigation

Ideagen Calculator

A C# console application that evaluates mathematical expressions using two different strategies: Recursion and Stack-based evaluation.

Features

  • 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).

Getting Started

Prerequisites

  • .NET SDK (Compatible with C# console applications)

Running the Application

  1. Clone the repository.
  2. Navigate to the project directory.
  3. Run the application using dotnet run or by building the solution and executing the binary.
dotnet run --project .

Usage

Upon running, the application will:

  1. Read and evaluate expressions from sample_expressions.txt if the file exists.
  2. 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.

Project Structure

  • Program.cs: Main entry point. Handles user input and file reading.
  • Calculator.cs: Abstract base class defining the Calculator interface 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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages