Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a) Design and submit the pseudo-code for both the versions of arithmetic calculator. b) Implement a Java program for the first version . In your

a) Design and submit the pseudo-code for both the versions of arithmetic calculator.

b) Implement a Java program for the first version. In your program, you will implement and use your own array-based stack (and not the built-in Java stack) of variable size based on the doubling strategy discussed in class (refer to the code segments provided on your slides and the textbook).

image text in transcribed

Q4. In this programming assignment, you will first design using pseudo code two versions of arithmetic calculators. The first version will be based on the pseudo code discussed in class that uses two different stacks. The second version must be completely based on recursion and must not use any stack (however, we know by now that recursion will implicitly use JVM's own stack as in regular function calls). You will implement the first version in Java. Your arithmetic calculators must read lines of text from a text file, where each line contains a syntactically correct arithmetic expression. Your output file must repeat the input line and print the computed result on the next line COMP 352 Winter 2018 Assignment 2-page 1 of 2 Your calculators must support the following operators on integers and observe the standard operator precedence as shown in the following (1 to 8: is highest and 8 is lowest. Same precedence operators are evaluated from left to right) 1. Parentheses (possibly nested ones): (,) Unar ators 2. factorial:! 3. minus:- Bi rators 4. power function: xy 5. operators: *,/ 6. operators: +, - 7. operators:>,2. S, 8. operators algorithm shown in class is Two stacks opStk holds operators Algorithm EvalExD0 Input: a stream of tokens representing an arithmetic expression (with numbers) Output: the value of the expression o Use $ to hold a special "end of input token with lowest precedence Algorithm doOp0 while there's another token z x valstk.popo; y valstk.popo; op opStk.pop(); valStk.push( y op x) if isNumber(z) then valStk.push(z) else Algorithm repeatOpsrefOp while ( valStk.size)> A repeatQps(z); opStk.push(z) prec(refOp)s prec(opStk.top0) repeatOps(S); return valStk.top doOp0 Q4. In this programming assignment, you will first design using pseudo code two versions of arithmetic calculators. The first version will be based on the pseudo code discussed in class that uses two different stacks. The second version must be completely based on recursion and must not use any stack (however, we know by now that recursion will implicitly use JVM's own stack as in regular function calls). You will implement the first version in Java. Your arithmetic calculators must read lines of text from a text file, where each line contains a syntactically correct arithmetic expression. Your output file must repeat the input line and print the computed result on the next line COMP 352 Winter 2018 Assignment 2-page 1 of 2 Your calculators must support the following operators on integers and observe the standard operator precedence as shown in the following (1 to 8: is highest and 8 is lowest. Same precedence operators are evaluated from left to right) 1. Parentheses (possibly nested ones): (,) Unar ators 2. factorial:! 3. minus:- Bi rators 4. power function: xy 5. operators: *,/ 6. operators: +, - 7. operators:>,2. S, 8. operators algorithm shown in class is Two stacks opStk holds operators Algorithm EvalExD0 Input: a stream of tokens representing an arithmetic expression (with numbers) Output: the value of the expression o Use $ to hold a special "end of input token with lowest precedence Algorithm doOp0 while there's another token z x valstk.popo; y valstk.popo; op opStk.pop(); valStk.push( y op x) if isNumber(z) then valStk.push(z) else Algorithm repeatOpsrefOp while ( valStk.size)> A repeatQps(z); opStk.push(z) prec(refOp)s prec(opStk.top0) repeatOps(S); return valStk.top doOp0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions