/Calculator_library

A cpp library to evaluate infix notation

Primary LanguageC++

Infix to Postfix Conversion & Postfix Evaluation

Intro

C++ program that parses Infix Notation (usual mathematical expressions) to Reverse Polish Notation (Postfix notation) and then evaluates it.

Examples of Infix Conversion to Postfix

  • Infix : 2+3*6 | Postfix : 2 3 6 * +
  • Infix : (2+3)*6 | Postfix : 2 3 + 6 *
  • Infix : (-2-3)6 | Sanitized Infix : (0 -2 - 3) * 6

Supported mathematical operations

  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Absolute Value (denoted by the symbol m)
  • Square Root (denoted by the symbol t)
  • Sin, Cos, Tan (denoted by symbols s, c and t respectively)
  • Power (denoted by the symbol ^)
  • Modulus

Usage

  • Create an instance of InfixCalculator which takes in the Infix string as a parameter
  • Call method evalPostfix() which return evaluated Postfix as string

Possible Improvements

  • Postfix value can be stored as a List<String> (depiction and not actual syntax) instead of a string

Bugs

  • Trigonometric values of negative numbers are not properly evaluated (that's what I think).

Additional Note

The code doesn't cover all the edge cases and it for the one using this library to find out what edge cases are missing.

Acknowledgements