DOC PREVIEW
Saddleback CS 1C - Reverse Polish Calculator using Stack Object

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Name _______________________________________Due Date ______________Reverse Polish Calculator using Stack ObjectOne very common use of a stack is found in calculators such as the Hewlett Packard calculators.Calculators that use a stack typically use reverse Polish (postfix) notation for arithmetic expressions.Reverse Polish notation allows expressions to be entered without the use of parentheses. We arecomfortable working with expressions in infix notation where a binary operator is placed between left andright operands. Parentheses are used to specify the order of operations. An infix expression is of the formLBR (left op, binary operator, right op) which corresponds to the postfix expression LRB (left op, rightop, binary operator). Consider the followingInfix Expression Postfix Expression (a + b) ab+ (x - y - z)(x - y - z)/(u + v)(a2 + b2)*(m - n)Please use ^ for exponentiationTo evaluate a postfix expression, P, you scan from left to right. When you encounter an operand, X, whilescanning P, push it on to the evaluation stack, S. When you encounter an operator, B, you pop the topmostoperand on the stack into a variable which represents the right operand, R, then pop the topmost operandon the stack into a variable which represents the left operand, L. Finally, perform the operation B on Land R getting expression LBR, and push the result back on to the evaluation stack, S. Evaluate the expression 34+2* . Draw a picture of the stack operations.Evaluate the following expression. 6 2 + 5 * 8 4 / -Rewrite the expression in infix notation to check your answer.The following algorithm can be used for unsigned single digit numbers: Enter a postfix string to evaluateFor (i=0 to the number of characters in the string, incrementing by 1)set ch to the ith character of the stringif(ch is '0' - '9')push the numeric value on to the evaluation stackelseif(ch is '+', '-', '*','/','^')pop right operandpop left operandperform appropriate arithmetic & push resultend ifend ifend foruse top to display the resultRevise this basic algorithm so your postfix expression can handle- signed numbers- multiple digit numbers- floating point numbersDelimit the items in the string with a blank space and evaluation will be in two stages as follows:Stage 1: Remove any excess blank spaces and any invalid characters from the string.Stage 2: Evaluate the postfix expression and display the answer.Sample Output:Enter a postfix expression: -3.5 (2) * 12.75 +Converted string: -3.5 2 * 12.75 +Result: 5.75Use a Stack object to implement this algorithm. TURN IN THE CORRECT ORDERCover sheetYou CodeDriverHeader file(s) Source file(s)No Output is needed for this assignment.We will demo your calculators in class so have them available. MAKE SURE YOUR PROGRAM CONFORMS TO ALL STYLE AND DOCUMENTATIONSTANDARDS OUTLINED IN CS 1A, CS 1B, CS 1C. HOMEWORK NOT IN THIS FORMAT WILL NOT BE


View Full Document
Download Reverse Polish Calculator using Stack Object
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Reverse Polish Calculator using Stack Object and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Reverse Polish Calculator using Stack Object 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?