Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( 2 2 pts ) Your little sibling needs your help with checking his / her solutions of a ton of math expressions, which are

(22 pts) Your little sibling needs your help with checking his/her solutions of a ton of math expressions, which are made up of single digits (0,1,dots,9), arithmetic operators ("+","--","*","/"(integer division), and "%"(mod)), and brackets ("()'',[]", and "{}"), but you'd like to save more time to have fun. For your cute and helpless sibling's sake, please use what you learned to help him/her out!
Note: for all the questions below, you may leverage the code given in class or STL containers.
Your code should expect and produce C-style string expressions (e.g., char []) that terminate with 10'.
a)(7 pts) First, you may want to make sure that the handwritten expressions that your sibling copied from the board in class are valid (you don't want to get confused by his/her silly writing mistakes).
*** An expression is valid if:
All the brackets are balanced. That is, each left/right bracket can be paired with a right/left one in the same style. For instance, a left parenthesis "(" can be paired with a right one ")", and a right square bracket "]" can find a corresponding left one "[", and so on. There is no single bracket left alone. The appearance order of different types of brackets does not matter, that is, say, parentheses can include square brackets ("[[])") or be included by square brackets ("(:[()]''}, and so on.
Within each pair of brackets, there is only one operator for two operands (e.g.,"(3+5)"), but each operand may also be an expression in a pair of parentheses (e.g.,"[1+(2**3)]''.
Let's write a function checkValid to do that. It will return a Boolean value "True" if the expression is valid, or "False" otherwise.
Function signature:
bool checkValid(char exp[]
Example 1:
Input: exp={1+[(2+3)**(4**5)]}
Output: True
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions

Question

For a 2-curve with df = 4, determine a. 2 0.005. b. 2 0.99.

Answered: 1 week ago