Question: Page number 1 CS 2 1 0 - Yoo Project 1 2 0 2 4 PROJECT DESCRIPTION: Implement calculator to evaluate arithmetic equations with numbers

Page number
1
CS210- Yoo Project 12024
PROJECT DESCRIPTION:
Implement calculator to evaluate arithmetic equations with numbers (single digit integers in the range of
0 to 9) and four operators (+,-,*,/) using Python.
DUE: 11:59 P.M. on September 22(Sunday)
Your project will be divided into three parts:
- Part 1: Class/functions for Postfix Calculator
- Part 2: Class/functions to convert Infix notation to Postfix notation
- Part 3: Driver program integrating Part1 and Part2 to run several test cases
The final program should include (1) functions/class to evaluate a regular postfix expression using stack
(Part 1),(2) function/class to convert the infix expression to postfix expression (Part 2), and (3) a driver
program to run the test cases (Part 3).
Part 1: Postfix Calculator
Please create functions/class to take the postfix expression as input and evaluate it. You may review the
attached exercise to understand and practice infix and postfix notation.
There are many ways to implement Postfix Calculator. However, your program should use your own
Stack class implemented as an extendable array. Do NOT use the STL Stack. Below are some functions
to handle Stack. Feel free to add more functions such as helper functions to handle Stack:
push (x); push a new element x on the stack.
pop (); removes the top element from the stack.
size (); returns the number of elements in the stack.
isFull (); checks if the stack is full.
isEmpty (); checks for the empty stack.
top (); returns the element at the top of the stack without removing it from the stack.
Pseudocode to evaluate the postfix expression:
for each token in the expression do;
read a symbol
If its a number,
push it onto the stack
Otherwise # i.e. it is an operator
Pop the stack and store the number as the right operand
Pop the stack and store the number as the left operand
Compute the value of left operand OPERATOR right operand
Push the result onto the stack
End for
The final result will be the last value on the stack.
Pop the stack and return the result.
Check for the errors:
# If the stack has more than one element left and there are no more operators, or
# the stack has one element left and there is at least one operator then signal an error.
2
Part 2: Converting Arithmetic Expression from Infix to Postfix Notation
In part 1, you created postfix calculator which may work well but the postfix notation is not very human-
friendly. Please create functions/class to convert the infix expression as postfix notation as a solution.
When a user enters the arithmetic expression in infix notation, your function will change it into postfix
notation which will be an input to postfix calculator to generate an answer.
Please review the pseudocode below:
initialize Stack and Output arrays as empty
while there is symbol to be read in input string
read the symbol
case:
operand --> output it.
(--> push it on the stack.
)--> pop operators from the stack to the output
until a ( is popped; do not output either of the parentheses.
operator --> pop higher- or equal-precedence operators from the stack
to the output;
stop before popping a lower-precedence operator or a (.
Push the operator on the stack.
end case
end while
pop the remaining operators from the stack to the output
Follow the steps in the pseudocode for an input of A /(B + C)- D
Input: A /( B + C) D
Input Symbol Stack Content Output
A nil A
// A
(/( A
B /( A B
+/(+ A B
C /(+ A B C
)/ A B C +
-- A B C +/
D - A B C +/ D
nil A B C +/ D -
Output: A B C +/ D -
3
Part 3: Driver Program (Project1.py)
Create a driver program to integrate classes generated from part1 and part2 and run test cases. Your final
program will interact with the users to evaluate regular arithmetic expression to generate the answer as
shown below as an example:
> Enter an arithmetic expression: 1+2*3
7
> Continue? Y/N
Y
> Enter an arithmetic expression: 5*(6+3)
45
> Continue? Y/N
N
Bye
GRADING:
Your program will be graded not only on meeting the stated requirements of the project, but also on
design quality and programming style (coding standard). Program should be defect-free (no error). A late
project may be accepted with a penalty of 10% per day.
Collaboration on project or copying from Internet is not allowed and is considered as cheating. You are
required to observe the University and Departmental policies on academic honesty. Any requests for
special consideration relating to late projects must be discussed with and approved by the instructor in
advance.
SUBMISSION:
The project submission should in a zip file format including the files:
All source codes (Project1.py) including classes/functions created
Snapshot of the output after running the test expression cases below:
o 1+4*62*5
o (2+8)*(93)
o 8*(2+3)/4
Use a name convention of CS210_Project1_yourLastName

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!