Sale!

CSC 3100 Assignment 1 solution

Original price was: $35.00.Current price is: $30.00. $25.50

Category:

Description

5/5 - (5 votes)

CSC3100 Assignment 1
Functional Requirement:
1. The program evaluatesthe value of math expressions, and outputs an integer value or “invalid”.
2. In test A, each math expression includes (see the example below):
2.1 positive integers;
2.2 (no more than five) operators of “+” (addition), “-“ (subtraction), “*” (multiplication) and
“/” (division).
3. In test A, all expressions are valid. The output is an integer value after rounding.
An example of input file for test A Expected output file:
1+2
3+4/3+7
1*2*3*4+5
2*3+4*5+6/7
1/2-1*3/3
1/2-1*4/3

3
11
29
27
0
-1

4. In test B, each math expression includes (see the example below):
4.1 numbers (integers and doubles);
4.2 (no more than ten) operators of “+” (addition), “-“ (subtraction), “*” (multiplication) and
“/” (division);
4.3 (no more than three) functionsincluding “sin” (sine function), “cos” (cosine function), “tan”
(tangent function) and “sqrt” (square root function).
4.4 “(“ and “)” (brackets);
4.5 possibly blank space.
5. In test B, the expression may not be valid. Correspondingly, the output is either the integer
value after rounding if the expression is valid, or “invalid” if the expression is not valid.
An example of input file for test B Expected output file:
1+2.0*sin(37+(25*3))
(2+ 3.50)*4*sqrt(sin(1.5))
-3+4/ (2.5+3.7)
(-3+4)/2.5+3.9
1.2-3.5*5.2-13.2
1.2-3.5*5.2-13.7
2.3*5*7 – 12*9/8
-sin(3.5-sqrt(4)) + cos(tan(2.5))
sqrt(-1)
2.5 4.0

-1
22
-2
4
-30
-31
67
0
invalid
invalid

Program Template:
Each submission is expected to strictly follow the template to implement the required function.
The main function is in TestMathExpr.java. In line 11 of TestMathExpr.java, an expression string is
evaluated, which returns the value of the expression. Each submission is required to:
1. Modify the MathExpr.java and implement the parse() function;
2. If needed, new classes and functions can be added;
3. No modification of TestMathExpr.java is allowed.
The command used to run the program is: java TestMathExpr input.txt output.txt, where input.txt
is the input file of expressions, and output.txt is the output file of values.
Appendix
1. TestMathExpr.java
2. MathExpr.java
3. inputA.txt
4. outputA.txt
5. inputB.txt
6. outputB.txt
CSC 3100