Develop an expression manager that can do a balanced symbol check.
Your program will read three different mathematical expressions from the user that are the followings:
As you notice the expressions contain the following symbols: { , }, ( , ), [ , ].
Write a program PEX5.cpp that after it reads the above expressions will check and report whether the expression is balanced or not.
Remember that { , }, ( , ), [ , ] are the only symbols that will be checked. All other characters will be ignored.
Remember to use the stack STL as you process each expression. Call the method that processes the expression as follows:
bool isItBalanced(string inputExpr)
If there is a mismatch in the expression make sure you report the symbol of the mismatch and its actual position in the expression.
Expected output:
Enter your expression: {(0+1)*(2+3)}
Your code compiles fine in GCC, is that a warning or an error? Ambiguity is typically the result of poorly named variables, maybe try renaming your data variable to something else?
Also note that here: cout << "\nMismatch found :" << data << " at " << position << "\n";
you are treating data as a nul-terminated string and it is not, resulting in undefined behavior.
I'm at a loss as to why you're using an array to hold a single character.