This project is a C++ console application that performs various operations on arithmetic expressions, such as conversion between infix, postfix, and prefix notations, as well as the evaluation of these expressions. It provides a menu-driven interface for the user to interact with.
- Infix to Postfix Conversion
- Infix to Prefix Conversion
- Postfix Evaluation
- Prefix Evaluation
- Postfix to Infix Conversion
- Prefix to Infix Conversion
- Store and Select Expressions
- C++ Compiler (e.g., g++)
- Clone the repository or download the source code.
- Navigate to the directory containing the source code.
- Compile the program using a C++ compiler:
g++ -o expression_converter main.cpp -lm
Run the compiled executable:
./expression_converter
You will be presented with a menu that offers several options for manipulating and evaluating arithmetic expressions.
-
Enter a new expression
- Allows you to input a new infix expression which gets stored in the list of expressions.
-
Select an expression
- Allows you to choose an existing infix expression from the stored list.
-
Postfix Calculations
- Provides a submenu for postfix operations:
- Convert to postfix
- Evaluate postfix expression
- Postfix to infix conversion
- Provides a submenu for postfix operations:
-
Prefix Calculations
- Provides a submenu for prefix operations:
- Convert to prefix
- Evaluate prefix expression
- Prefix to infix conversion
- Provides a submenu for prefix operations:
-
Exit
- Exits the application.
- Expressions are stored in vectors, allowing you to manage multiple expressions and switch between them as needed.
- Infix to Postfix and Infix to Prefix conversions are performed using stack data structures to handle operator precedence and parentheses.
- Both postfix and prefix evaluations prompt the user to enter values for the operands, then compute the result using a stack-based approach.
- Both postfix and prefix expressions can be converted back to infix notation to verify correctness or for further manipulation.
-
Entering a new expression
Enter a new expression: (a+b)*(c+d)
-
Selecting an expression
1. a+b 2. (a+b)*(c+d) Select an expression: 2
-
Postfix Calculations
****** POSTFIX MENU ***** 1. Convert to postfix 2. Evaluate postfix expression 3. Postfix to infix conversion ************************* Choose an option: 1 Postfix expression: ab+cd+*
- Ensure the maximum size of the stack (defined by
#define MAX 50
) is not exceeded to prevent overflow. - The program currently supports single-character operands (a-z, 0-9) and basic arithmetic operators (+, -, *, /, ^).
Feel free to fork the repository and submit pull requests for any enhancements or bug fixes.
This project is open-source and available under the MIT License.
For any questions or support, please contact the project maintainer.