Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I could Use your help in with writing the C + + code for. The only library is the iostream library ! Here's the scenario:

I could Use your help in with writing the C++ code for. The only library is the iostream library !
Here's the scenario:
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,...,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 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 '\0'.
a) 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
-Example 2: -Input: exp='[1+{(2+3)*})", Output: False

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 Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

=+Define social listening and social monitoring

Answered: 1 week ago