Asgn 2
Asgn 2
Question (50 Marks) A lack of a certain symbol (such as a missing brace or bracket or parenthesis) will cause
the compiler to spill out a hundred lines of diagnostics without identifying the real error. The solution is to
check whether every bracket, braces or parentheses is balanced. Every right brace, bracket, parenthesis and
etc must correspond to its left counter part. Develop a stack using C++ which is given a set of string statement
as follows:
The code should read each character in the string. If the character is a variable name or an operator (like +,
-, * or /), then it should do nothing. If the character read is an opening symbol like ( or { or [, then it should
push it on stack. If the character read is a closing symbol like ] or } or ), then it should pop from stack. In the
end if the stack is not empty, display a message that the statement is not balanced in terms of symbols.
For more explanation: see slides 16, 17, 18, 19 and 20 of Week 5. Ppt
Page 1 out of 3