1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Elan Coil [88]
2 years ago
5

Matching parentheses. An math expression may have a number of parentheses like (, ), [, ], { and }. Each openning parenthesis (,

or [, or { must be macthed by a corresponding closing parenthsis ), or ] or }. For example, 12 { 34 / [ 6 * ( 55 - 10 ) / ( 100 20 ) ] } has matched pairs of parentheses, while 12 { 34 / ( 6 * ) ] } does not. Write a function to check whether an input math expression has matched parentheses. The header of the function is given as follows:
bool match( const char exp [ ], const int s);
The input math express is store in the char array exp, and the size of exp is s. It returns true if all parentheses are matched or false otherwise.
Computers and Technology
1 answer:
Solnce55 [7]2 years ago
3 0
C++ Code

#include
using namespace std;

bool match(const char exp[],const int s)
{
// declare a character array to perform stack operations
char stack[s];

// declare top and initialize to -1 and flag to 0
int top=-1,i,flag=0;

// visit all characters in the expression string
for(i=0;i {
// if the character is [ or ( or { then push it into stack
if(exp[i]=='[' || exp[i]=='(' || exp[i]=='{')
{
top++;
stack[top]=exp[i];
}
// if the character is ] or ) or } then check conditions
else if(exp[i]==']' || exp[i]==')' || exp[i]=='}')
{
// check stack is empty or not
if(top!=-1)
{
// check all possible failure conditions
if(exp[i]==')' && (stack[top] == '{' || stack[top]=='['))
{
flag = 1;
break;
}
else if(exp[i]==']' && (stack[top] == '{' || stack[top]=='('))
{
flag = 1;
break;
}
else if(exp[i]=='}' && (stack[top] == '(' || stack[top]=='['))
{
flag = 1;
break;
}
top--;
}
else
{
flag=1;
break;
}
}
}
// after visiting all characters of expression string check if stack is not empty and flag is 1. if any one of the condition is true return false. otherwise return true

if(top>=0 || flag==1)
return false;
else
return true;
}

int main()
{

// declare character array to store expression
char exp[10000];
cout<<"Enter an Expression"<
// read expression from user
cin.getline(exp, 10000);
int s=0;

// find the length of the expression string
for(int i=0;exp[i]!='\0';i++)
{
s++;
}

// call the match function
bool status = match(exp,s);

// print the result based on value returned by match() function
if(status == 1)
cout<<"true"< else
cout<<"false"<
}


Sample Input/Output is attached

You might be interested in
Which tab is used to configure editing restrictions in Word 2016? Review References Security Developer
Ipatiy [6.2K]

Answer:

Review Tab is the correct answer to the given question .

Explanation:

Giving the permission to file in word 2016

  • Click on the Review tab and select the restrict tab .
  • Chose the option allow this type of editing .
  • After that choose the option No changes .
  • Pick the section of the document they want to authorize the adjustments.
  • After that there are multiple option are seen select accordingly  as user need and press ok button .
  • Click on the start permission there is option is seen Start enforcement and press the button option start Enforcing Protection.
  • After that feeding the password if the user need the password is in encrypt form then press encrypt option and click ok .

If the user need to read the file

  • Click on the Review tab and select the restrict tab .
  • After that choose the option "Stop Protection" .
  • Giving the password you are feeding in the permission of file  .
  • Finally the user will edit the document

4 0
3 years ago
Read 2 more answers
Which access object cannot be used to enter or edit data
kap26 [50]

Answer:

Should be B. table !

6 0
2 years ago
Read 2 more answers
Write a program to input elements of 4*3matrix and prints its elements properly using array ​
Harlamova29_29 [7]

Answer:

Step by step explanation:

7 0
2 years ago
What is word processors​
otez555 [7]

A word processor is a computer program or device that provides for input, editing, formatting and output of text, often with additional features.

8 0
2 years ago
1:A presentation program which is developed by Microsoft
LekaFEV [45]
Option 3: PowerPoint.
4 0
2 years ago
Read 2 more answers
Other questions:
  • Which of the following is a correct definition of the term rectification? A. Rectification is the opposition to current flow in
    14·2 answers
  • Answer the following questions which are based on the study "Patients' Engagement with Sweet Talk." Submit your answers to the e
    9·1 answer
  • Plane eyes I don't know
    9·1 answer
  • In an AND truth table.
    7·1 answer
  • Which of the following does every font that you choose communicate, either on a conscious or subconscious level?
    10·2 answers
  • Which two statements are true about the Data Sync functionality? (Choose two.)
    15·1 answer
  • Which term describes a visual object such as a picture a table or text box
    15·2 answers
  • You can find synonyms and disciplinary jargon in the ______, _______, and ______ in your search results. You can then use these
    13·1 answer
  • A non-profit organization decides to use an accounting software solution designed for non-profits. The solution is hosted on a c
    11·1 answer
  • after teaching a group of students about measuring systems and drug calculations, the instructor determines that the teaching wa
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!