Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. [30 marks] (Stack Application Infix to Postfix Conversion) Write a program that uses the Stack class template to convert an infix arithmetic expression into

image text in transcribedimage text in transcribed

2. [30 marks] (Stack Application Infix to Postfix Conversion) Write a program that uses the Stack class template to convert an infix arithmetic expression into a postfix arithmetic expression. In infix form, the operator of an arithmetic statement is in-between every pair of operands. For example: a + b a (b c) (a b) c In postfix form, the operands of an arithmetic statement appear followed by the operator One of the virtues of postfix form is that expressions can be written without the need for parentheses. Here are some examples of arithmetic expressions written in postfix form a b + // Equivalent ta + b a b c+ // Equivalent to a *(b c) ab+*// Equivalent to (a + b) * c Please write a C++program that uses an operator stack to convert an infix arithmetic expression that the user enters into a postfix arithmetic expression. Users input the infix arithmetic expressions which only contains the operands, operators and parenthesis symbols. The character # marks the end of the expression. The operands are represented by single lowercase letters, i.e., a, b, c, d, etc, and the operators are +,-, * and /. Assuming the expressions the users enter are all validated. You may call the following functions in main function. // checks if c is an operand bool is_operand (char c) return true: else return false; // checks if c is an operator,,or / /1 checks if c is an operator,, *, or / bool is_operator (char c) return true: else return false; // return the precedence of an operator int get_operator_precedence (char op) int prec 0; prec =1; else if (op== '*' ll op-'/' ) else return preci Three files should be submitted for this program question. 1) the file Stack.h which contains the definition and implementation of Stack class template, 2) the application file a2q2.cpp containing main ) function, 3) a script file a2q2result containing result. Here are the sample runs: The infix expression: The postfix expression: ab+cdte*- The infix expression: a* (b+c)-e The postfix expression: abct e

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions