This repository is to practice GUI implementation of c++, so maybe each folder is not a big project, just a small scale project for practice. If you think it's helpful for you, you can just download them and welcome to leave any comments to suggest (or criticize) or ask me questions. I will answer you when I am available.
The basic calculator is designed to perform arithmetic operations such as addition, subtraction, multiplication, and division, as well as advanced mathematical functions like square roots and factorials. It takes user input in a simple string format and evaluates the expression while ensuring correct operator precedence and error handling for invalid inputs. The user interface features buttons for digits and operators, allowing for a straightforward interaction.
- Basic Operations:
- Addition (
+
) - Subtraction (
-
) - Multiplication (
*
orx
) - Division (
/
)
- Addition (
- Advanced Operations:
- Square root (
√
) - Factorial (
!
) - Power (
^
)
- Square root (
- Error Handling:
- Detects invalid expressions (e.g., missing operators, invalid characters).
- Provides user feedback when an error occurs.
-
Input Parameters:
QString expression
: A string containing the mathematical expression to be evaluated (e.g.,"8 + 5"
or"√ 4 + 3!"
).
-
Output Parameters:
double result
: The calculated result of the evaluated expression. If the expression is invalid, an error message is returned instead.
-
Auxiliary Parameters (if applicable):
bool isError
: A flag to indicate whether an error occurred during evaluation, useful for handling error feedback.
-
Valid Input:
- Input:
"7 + 3 * 2"
- Output:
13
- Input:
-
Invalid Input:
- Input:
"5 +"
- Output:
"Invalid expression: Expected a number after operator at position 2"
- Input:
This is just a source code from QT getStarted tutorial. (I just wanted to give it a try, and also shared here for lazy humans like me.)