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
What is inputted into a computer system?
Anna [14]

Answer:

Hey mate.....

Explanation:

This is ur answer.....

<em>Input refers to any information, or data, that is sent to a computer for processing. Input is often sent to the computer from a device such as a keyboard, mouse, or other input device. Putting it simple, input is the act of entering data into a computer.</em>

<em />

Hope it helps!

Mark me brainliest....

FOLLOW ME!!!! :)

4 0
2 years ago
The dns server translates the URL into the IP address 8.8.8.8. What is the next step in the process?
geniusboy [140]

Answer:

The web browser sends an HTTP request to the IP address, the IP address then sends the content that are displayed by the browser

Explanation:

The process of converting the typed in URL to a displayed page is as follows;

1) The typed in URL is sent to a DNS recursor by the browser

2) The recursor gets the DNS record for the domain from the cache if the record is cached or when the DNS record for the domain is not cached, the recursor makes a requests to the DNS root from which the name of the TLD nameserver is received

3) The TLD nameserver is contacted by the resolver to obtain the authoritative nameserver's IP address

4) With the information, the resolver contacts the authoritative nameserver and obtains the domain's IP address for the domain the resolver contacts

5) The obtained IP address for the URL's domain is then sent to the browser by the resolver

6) An HTTP request is sent by the browser to the IP address and the data received by the browser from that IP address is rendered and seen as the page content.

6 0
2 years ago
PLEASE HELP I WILL REWARD YOU
xxMikexx [17]
What what what what what what
5 0
3 years ago
PLZ HELP !!!!! <br> plzzzz
kozerog [31]

Answer:

Producers

Explanation:

Producers manufacture and provide goods and services to consumers.

7 0
2 years ago
Where is permanent data in the computer stored? Whenever Jim starts his laptop, he sees some commands and numbers appearing on h
Wittaler [7]

the operating system ithink

4 0
3 years ago
Other questions:
  • Is instant messaging a form of synchronous communication
    10·1 answer
  • ____ steganography places data from the secret file into the host file without displaying the secret data when you view the host
    9·1 answer
  • Plz tell the answer I I'll mark u as the brainliest
    14·1 answer
  • Hi there! I just started my beginner computer science class and I was wondering if anyone wants to help with an assignment i'm h
    15·1 answer
  • Jon wants to assign a value to the favorite food variable: favoriteFood! = "Pizza" but gets an error message. What does he need
    9·2 answers
  • Even though jdoe and jrock have the same password (i.e., hacker), their password hashes in the /etc/shadow file are different. W
    15·1 answer
  • The higher the ____________________, the faster the ____________________.
    5·1 answer
  • Why do we need operating systems?
    7·1 answer
  • How do we prevent electrical problems as prescribe by the course?​
    11·1 answer
  • Susan wants to play the games that come with Windows on her computer, but they are not on the Start menu. What should she do in
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!