Am unable to solve this assignment plz helppppp write a c++ program that reads f
ID: 3615858 • Letter: A
Question
Am unable to solve this assignment plz helpppppwrite a c++ program that reads from the user a mathematicalexpression like:
(3+(4-9) * (3/4) * (3+2))
1. your program should check if the expression is correct
1.1 An expression is correct if:
the parantheses are correctly added and arebalanced
examples of not correct expressions can be:
)9+8(
(((8-1)
etc
Assume that the numbers are only one digit ( you can extend yourprogram to read more than one digit numbers as a bonus)
2. If the expression is correct, your program should evaluate theexpression and display the result.
Hint : use stacks to solve the problem
Explanation / Answer
I've done a similar project in java and one in C, but a littledifferent. If you only need to check the parenthesis are correct, read thestring from left to right and every time you encounter a '(' youpush it on the stack, every time you get a ')', peek on the stack,if it is a '(' pop it off the stack, if it isn't a '(' thensomething is wrong. Every parenthesis will have a matchingcounterpart in that order. Then just solve it the equation. I did a project where youconverted the infix to postfix then had to solve the postfixequation in C using pointers, but you should be able to use anarray. Have you tried writing code yet? I'm not going to do your code foryou, but if you need help with a certain part I can try to helpyou. Contact me if you think I can help you further.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.