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 11. 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 2. 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 convert(const 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 (i.e., 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 1. ~ (unary negation) and ^(exponentiation)2.*(multiplication) and /(division)3.+(addition) and -(subtraction) Your function must take the infix expression (which is a C++ string that may contain unnecessary whitespace and/or 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 operators/operands 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. 3. Files You Must Submit You must submit your inpost.h and inpost.cpp files to the Grade-o-Matic for grading. You do not need to submit your mystack.cpp and mystack.h files from Assignment 11 to the Grade-oMatic. It will supply its own versions of those files (in case you never got yours to work).4. 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: 2 postfix: 2 infix: 2+a postfix: 2 a + infix: (1+a)^2 postfix: 1 a +2^ infix: ~(1+a)^2 postfix: 1 a + ~ 2^ infix: ~((1+a)^2) postfix: 1 a +2^ ~ infix: 0/0 postfix: 00/ infix: 1/0 postfix: 10/ infix: 0/1 postfix: 01/ infix: c^a postfix: c a ^ infix: ~c^a postfix: c ~ a ^ infix: c^d postfix: c d ^ infix: ~c^d postfix: c ~ d ^ infix: d+1 postfix: d 1+ infix: d +1*2 postfix: d 12*+ infix: ( d +1)*2 postfix: d 1+2* infix: a-e-a postfix: a e - a - infix: (a-e-a)/( ~d +1) postfix: a e - a - d ~ 1+/ infix: (a^2+ ~b ^2)*(5- c) postfix: a 2^ b ~ 2^+5 c -* infix: ~ 3* ~( a +1)- b / c ^2 postfix: 3 ~ a 1+ ~ * b c 2^/- infix: 246+ b /123 postfix: 246 b 123/+ infix: (246+(( b /123))) postfix: 246 b 123/+ infix: ((246+ b)/123) postfix: 246 b +123/ infix: a+b/c^d-~e*f 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 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!