一个命令行程序可以计算一元二次方程和二元一次方程
二次方程答案格式X=
Output下类似下面的example即可
calc X = 2 + 4 * 3 – 6
Becomes X = 2 + 12 – 6
Which results in X = 8
calc X^2 + 2X^2 = 27
Becomes 3X^2 = 27
Which results in X = 3
calc X^2 – 4 = 11 * 7
Becomes X^2 – 4 = 77
Becomes X^2 = 81
Which results in X = 9
calc X = 20 / 4
X = 5
calc X = -5 / +2
X = -2
Your program must also check to make sure the command line argument is correct and handle the equation parts. If not your program must generate an appropriate error message and then terminate. For example:
calc X = – 3 + 4 / 6 (spaces represent splitters between numbers and operators)
Becomes X = -3 + 4 / 6
calc X = 3 + 4 / 6 + (space after+)
Becomes X = 3 + 4 / 6 + 0 (replace by 0)
Becomes X = 3 + 4 / 6
calc X = 3 + + + 4 – 6 (operation elimination)
Becomes X = 3 + 4 – 6
calc X = 3 – – – 8X – 4
Becomes X = 3 – 8X – 4
calc X + 3 + 6 + 3333333333333
Invalid Input (this is not equation and invalid as well)
calc X^2 = 2121212121 + 2020202020
Out of Integer Range
calc X = 4 % 0
calc X = 4 / 0
Division by zero
用如下的方程测试,可以通过这些就合格
X + 2 = 6
3X – 6 = 9
X = 5*X – 5 * 3
5(2) + 5x = 15
X / 5 = 6
x^2 + 7 * x + 6 * 2 = 0
(X-2) (X-3) = 0
4(4X) + 2 (X) = 72
2(X-1) + 8 = 4*X – 20
4x^2 – 11 * 2 = x^2 + 5