Exercise 1 It is required to evaluate an arithmetic expression that is represent
ID: 3536210 • Letter: E
Question
Exercise 1
It is required to evaluate an arithmetic expression that is represented in infix notation. Develop a program such that the arithmetic expression in infix notation is first converted to postfix notation and then uses postfix notation to evaluate the expression.
Note: You are required to use suitable data structures that you have studied to convert to postfix notation and then evaluate it.
Example:
Infix notation: A * B + ( C – D / E)
Postfix notation: AB*CDE/-+
Assume test values A = 8, B= 6, C = 8, D= 6 and E = 2 and print the result.
Hints:
By a program
Infix
Stack
Postfix
A * B + (C - D / E)
Empty
* B + (C - D / E)
Empty
A
B + (C - D / E)
*
A
+ (C - D / E)
*
AB
(C - D / E)
+
AB*
C - D / E)
(+
AB*
- D / E)
(+
AB*C
D / E)
-(+
AB*C
/ E)
-(+
AB*CD
E)
/-(+
AB*CD
)
/-(+
AB*CDE
+
AB*CDE/-
AB*CDE/-+
Note: To simplify your task, just consider the priorities as given below.
Multiplication and division operators have equal priorities but have higher priorities than addition and subtraction operators. Addition and subtraction operators have equal priorities.
Exercise 2
You have been provided with input.txt file. It is required to list all the unique words that are present in the input.txt file and the number of occurrences of each unique word. It must also be possible to print the number of occurrences of a given unique word that is input by the user.
Develop a program using the data structure/ data structures that you feel is/are most suitable for the above mentioned requirements and test it.
Note: You can make the following assumptions
Sample Input/Output:
Input.txt:
The expression exp1 && exp2 is true if and only if exp1 == true and exp2 == true
Unique words and their occurrences:
word
Occurs
The
expression
exp1
exp2
&&
is
true
if
and
only
==
1
1
2
2
1
1
3
2
1
1
2
Input the word: true
true occurs 3 times.
Infix
Stack
Postfix
A * B + (C - D / E)
Empty
* B + (C - D / E)
Empty
A
B + (C - D / E)
*
A
+ (C - D / E)
*
AB
(C - D / E)
+
AB*
C - D / E)
(+
AB*
- D / E)
(+
AB*C
D / E)
-(+
AB*C
/ E)
-(+
AB*CD
E)
/-(+
AB*CD
)
/-(+
AB*CDE
+
AB*CDE/-
AB*CDE/-+
Explanation / Answer
here is your answer
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.