The Truth Table Generator is a C++ program that utilizes object-oriented programming and data structures to generate a truth table for a provided logical expression. The program supports the following logical operators: NOT, AND, and OR. It also includes the ability to resolve brackets using a stack, resulting in a postfix expression.
- Logical expression evaluation: The program can evaluate logical expressions containing NOT, AND, and OR operators.
- Bracket resolution: The program can handle expressions with brackets by resolving them using a stack and converting the expression to postfix notation.
- Truth table generation: Given a logical expression, the program generates a truth table with all possible combinations of inputs and the corresponding output values.
- User-friendly interface: The program provides a user-friendly interface to input the logical expression and view the generated truth table.
To use the Truth Table Generator, follow these steps:
- Clone the repository or download the source code files.
- Open the terminal and navigate to the project directory.
- Compile the source code using a C++ compiler:
g++ truth_table_generator.cpp -o truth_table_generator
- Run the program:
./truth_table_generator
- Follow the instructions provided by the program to enter the logical expression.
- View the generated truth table.
The Truth Table Generator requires a C++ compiler that supports C++11 or higher.
- Input the logical expression following the provided syntax guidelines:
- Use '~' for NOT operator.
- Use '^' for AND operator.
- Use '|' for OR operator.
- Enclose sub-expressions in brackets '(' and ')'.
- Use uppercase letters for variables.
- Separate each expression or variable with spaces.
Example:
(~A ^ B) | (C ^ D)
- Press Enter to generate the truth table.
- The program will display the truth table showing all possible combinations of inputs and the corresponding output values.
Enter the logical expression: (~A ^ B) | (C ^ D)
A | B | C | D | Result |
---|---|---|---|---|
0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 0 |
0 | 0 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 0 |
0 | 1 | 0 | 0 | 1 |
0 | 1 | 0 | 1 | 1 |
0 | 1 | 1 | 0 | 0 |
0 | 1 | 1 | 1 | 1 |
1 | 0 | 0 | 0 | 0 |
1 | 0 | 0 | 1 | 0 |
1 | 0 | 1 | 0 | 0 |
1 | 0 | 1 | 1 | 0 |
1 | 1 | 0 | 0 | 1 |
1 | 1 | 0 | 1 | 1 |
1 | 1 | 1 | 0 | 1 |
1 | 1 | 1 | 1 | 1 |
Contributions to the Truth Table Generator project are welcome! If you have any ideas, bug fixes, or enhancements, please open an issue or submit a pull request on the project's GitHub repository.
When contributing, please follow the code style and structure of the existing project and ensure that your changes are well-documented.
The Truth Table Generator is licensed under the MIT License. See the LICENSE
file for more information.
If you have any questions or suggestions regarding the Truth Table Generator, please contact m.muneeb.ur.rehman.2000@gmail.com. I appreciate your feedback!
Thank you for using the Truth Table Generator! We hope it helps you generate truth tables efficiently for your logical expressions. Happy analyzing!