**
Fill This Form To Receive Instant Help**

Homework answers / question archive / CS 2124 Data Structures Lab 3 – Fall 2020 Objective : Implement a Stack ADT based Postfix Calculator Application Background: Be sure to read through Lecture decks on Stack ADT and the recommended textbook before starting this assignment

CS 2124 Data Structures Lab 3 – Fall 2020 Objective : Implement a Stack ADT based Postfix Calculator Application Background: Be sure to read through Lecture decks on Stack ADT and the recommended textbook before starting this assignment.

Part A - No Error Checking - 20 Points Initially, you do not need to do any error checking - you can assume that the input postfix expression is syntactically correct. You can use your own data sets to test your calculator. Input The input is a string that represents a postfix expression. To simplify the problem, your calculator will be restricted to operating on single-digit non-negative integers. Only the following characters are allowed in the string: • the operators '+', '-'. '*', and '/' • the digits '0' through '9' • the space character ' ' Example input: 2 4 3 * + Processing To handle spaces in the input, you will need to make one minor addition: if (ch is a blank) Ignore it Your program should ask the user to enter a text file with postfix expressions on a single line. You can either read the line one character at a time, or you can read the line into a string and then process the string one character at a time. Your program should then print the value of the expression. Your output might look like: Postfix expression: 2 3 4 + * The value of the expression is 14 Postfix expression: 7 2 / The value of the expression is 3 Important Note: Your program should perform single digit integer calculations only. Do not use floating-point (float or double) variables for your calculations. Note on writing applications This assignment is asking you to write a driver application for implementation of a Stack-based Postfix Calculator. You can use any open source stack ADT codes in C but use it at your risk, be sure to test out the C codes on UTSA Linux machines. Also please state the source. Hint: The stack used in your Calculator will need to hold integer values. You will need a way to convert the digits in the input from characters into integers. One way to convert a character that is a digit to an integer is: char token; int value; if ( token is an digit ) value = token - '0'; // note that the character in // single quotes is a zero

Part B with Error Checking (Basic - 80 pts + Bonus 10 pts) Once you have thoroughly tested your calculator, I want you to add error checking. You will need to use the provided data sets for your calculator with error checking and also for Infix2Postfx in case you want to try the bonus part. Data Set 1- Infix2Postfx 3 + 4 * 5 + ( 6 * 7 + 8 ) * 9 1 - (2 + 3 * 4)/5 (1+2)*(4-3) (4+8)*(6-5)/((3-2)*(2+2))

Data Set 2- Postfix Calculator with error checking 345*+67*8+9*+ 1234*+5/- 12+43-* 48+65-*32-22+*/ 234+* 72/ 512+4*+3- 72% 7*22+ A2/ 72// (23- Error checking Add code to check for the following errors: • Invalid character in the input expression - If this error occurs, print an error message stating that an invalid character was encountered. • Stack is empty when the algorithm needs to remove an operand - This happens when the expression has too many operators or when the operators and operands are not ordered correctly. We call this a malformed expression. If this error occurs, print an error message indicating that the expression is malformed. • When the loop in the algorithm ends, there should be exactly one value left on the stack and it is the value of input expression. If the input contained too many operands, there will be more than one value left on the stack. If you remove what should be the result of the expression the stack is not empty, then the expression was malformed and you should print an error message indicating this. In all cases, if an error occurs do not try to continue processing the input string and do not try to print the value of the expression. Just print the error message. Do not end your application - just see if the user wants to try another expression. EXTRA BONUS (10 points) For students who love challenging work - I would award extra 5 points for students who can process an infix expression from the very beginning, i.e. you will need to write a function to convert the infix expression to a postfix expression first, e.g. (6+3) * (8 + 2) -> 6 3 + 8 2 + * Please use the mandated infix input file for this bonus work. For students who love more challenging work - I would also award extra 5 points for Linked List based implementation - at the run time, have a menu allowing the user to pick up either A (ArrayStack) or L (LinkedStack) from a single driver.

Already member? Sign In