Question: you will receive a makefile and a driver program called main.cpp that will test your conversion function by passing it a series of infix expression
you will receive a makefile and a driver program called main.cpp that will
test your conversion function by passing it a series of infix expression strings. In order to build and
run tyou will receive a makefile and a driver program called main.cpp that will test your conversion function by passing it a series of infix expression strings. In order to build and run this assignment on your own local machine, you will also need the mystack.h and mystack.cpp files from Assignment The makefile can be used to build the program for this part of the assignment by typing: make inpost To run the program, type: inpost Files You Must Write For this assignment, you will write the following files: inpost.cpp contains your convert function. inpost.h contains the function prototype for convert so that the main can call it The file inpost.cpp is described in more detail below. The header file should contain header guards to prevent it from being included multiple times in the same source file. inpost.cpp This file should contain a definition for the following function: std::string convertconst std::string& infix; This function converts the infix expression passed to it as a C string into an equivalent postfix expression stored in a string object. You may assume that infix is a valid expression, that only and will be used ie no or will appear in the expression that all variables will be single characters always in lower case, and that all numeric literals will be integers. The operators used, in order of precedence from highest to lowest, are ~ unary negation and exponentiationmultiplication and divisionaddition and subtraction Your function must take the infix expression which is a C string that may contain unnecessary whitespace andor parentheses and convert it to a postfix expression stored in a string object. It is very important that the postfix expression does not contain any leading whitespace and that the operatorsoperands are separated by exactly one space. Infix to postfix conversion algorithm Here is a description of the logic for the infix to postfix conversion using a stack. Let opstack be a stack used to hold operators during conversion. Let infix be a string containing the infix input expression tokens. Let postfix be a string where a postfix output expression will be constructed. To convert the infix expression to a postfix expression: Scan the infix string from left to right, extracting and processing one token at a time, skipping over whitespace: If the token is a variable from a to z append it to the postfix string. If the token is a numeric literal, append all of its digits to the postfix string without spaces between the digits If the token is a left parenthesis push it on the opstack. If the token is a right parenthesis pop the opstack until the corresponding left parenthesis is removed. Append each operator popped to the end of the postfix string and discard the and parenthesis tokens. If the token is an operator then, first, pop all operators from opstack and append them to the postfix string until either a opstack is empty or b the operator on opstack has a lower precedence than the new operator token. Then push the new operator token into opstack. When the end of the infix string is encountered, pop and append all remaining operators from opstack and append them to the postfix string. Files You Must Submit You must submit your inpost.h and inpost.cpp files to the GradeoMatic for grading. You do not need to submit your mystack.cpp and mystack.h files from Assignment to the GradeoMatic. It will supply its own versions of those files in case you never got yours to work Output The only output from this program is generated by the main routine supplied for you in main.cpp A conversion function that works correctly will result in the following output: infix: postfix: infix: a postfix: a infix: a postfix: a infix: ~a postfix: a ~ infix: ~a postfix: a ~ infix: postfix: infix: postfix: infix: postfix: infix: ca postfix: c a infix: ~ca postfix: c ~ a infix: cd postfix: c d infix: ~cd postfix: c ~ d infix: d postfix: d infix: d postfix: d infix: d postfix: d infix: aea postfix: a e a infix: aea ~d postfix: a e a d ~ infix: a ~b c postfix: a b ~ c infix: ~ ~ a b c postfix: ~ a ~ b c infix: b postfix: b infix: b postfix: b infix: b postfix: b infix: abcd~ef postfix: a b c d e ~ f
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
