Question: (17.1)all in c++ please: Write a program that takes as input an arithmetic expression. The program outputs whether the expression contains matching grouping symbols. For

(17.1)all in c++ please:

Write a program that takes as input an arithmetic expression. The program outputs whether the expression contains matching grouping symbols. For example, the arithmetic expressions {25 + (3 6) * 8} and 7 + 8 * 2 contain matching grouping symbols. However, the expression 5 + {(13 + 7) / 8 - 2 * 9 does not contain matching grouping symbols.

Algorithm:

While (more characters) 
Get a character 
Evaluate character 

open group character

push onto stack

close group character

pop stack

check for match

if !match

ouput "Does not match"

any other character

discard

If stack is empty 
output "Match" 
else 

output "Does not match"

Test Data:

{25 + (3 - 6) * 8} ---> Match 
7 + 8 * 2 ---> Match 
5+ { (13 + 7) /8 - 2 * 9 ---> Does not match 
5 + { (13 + 7} / 8) - 2 * 9 ---> Does not match 

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 Databases Questions!