A command-line calculator that supports basic arithmetic operations, mathematical constants, and user-defined variables.
- Basic arithmetic operations:
+,-,*,/,^(exponentiation) - Built-in mathematical constants:
PI,E - User-defined variables
- Expression evaluation with proper operator precedence
- Parentheses support for complex expressions
This project uses a Makefile for building. Make sure you have g++ installed with C++17 support.
# Build the project
make
# Build and run
make run
# Clean build artifacts
make clean
# Build debug version
make debug
# Build optimized release version
make releaseAfter building, run the calculator:
./build/calculator2+3 # Addition: 5
2*3+4 # Multiplication with addition: 10
PI*2 # Using built-in constants: 6.28319
(1+2)*3 # Parentheses: 9
2^3 # Exponentiation: 8The calculator supports user-defined variables:
Calculator calc;
calc.setVariable("x", 5.0);
// Now you can use 'x' in expressionsmain.cpp- Entry point and demonstration codeCalculator.cpp- Calculator implementationCalculator.hpp- Calculator class definitionMakefile- Build configurationsupport.cpp- Additional utility functions (not used in main build)
- C++17 compatible compiler (g++, clang++)
- Standard C++ libraries
The calculator uses the shunting yard algorithm to convert infix notation to postfix notation, then evaluates the postfix expression using a stack-based approach.