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
(a) List 5 keys we can type with our left hand fingers
ehidna [41]

Answer:

A) <em><u>a,s,d,f, and either g or caps lock</u></em>

B) <u><em>l,k,j,h, and, ;</em></u>

Explanation:

3 0
3 years ago
What are some of the benefits of project
galina1969 [7]

Answer:

The project is more likely to be finished on  time.

Tasks can be done more efficiently.

Explanation:

Project management refers to the process involved in the management and accomplishment of the project. It includes the process, techniques, and guidance to carry on to complete a project. Project management helps in achieving the desired outcomes of the project. The efficient use of the resources and the proper management of the skills are ensured in project management. Better communication and an increase in satisfaction help in improving productivity.

4 0
3 years ago
4.3 mini programs AP computer science
allochka39001 [22]

1.

name = input("Enter your name: ")

num1 = int(input("Hello "+name+ ", enter an integer: "))

num2 = int(input(name+", enter another integer: "))

try:

   if num1 % num2 == 0:

       print("The first number is divisible by the second number")

   else:

       print("The first number is not divisible by the second number")

except ZeroDivisionError:

   print("The first number is not divisible by the second number")

try:

   if num2 % num1 == 0:

       print("The second number is divisible by the first number")

   else:

       print("The second number is not divisible by the first number")

except ZeroDivisionError:

   print("The second number is not divisible by the first number")

2.

import random, math

num1 = float(input("Enter a small decimal number: "))

num2 = float(input("Enter a large decimal number: "))

r = round(random.uniform(num1, num2), 2)

print("The volume of a sphere with radius " + str(r) + " is " + str(round(((4 / 3) * math.pi * (r ** 3)), 2)))

I hope this helps!

8 0
3 years ago
Caroline has been asked to find a standard to guide her company’s choices in implementing information security management system
koban [17]

Answer:

ISO 27002

Explanation:

The acronym ISO stand for The International Organization for Standardization. its a non governmental body that is responsible for setting standards guide internationally.

while NIST stand for National Institute of Standards and technology and it is also a body that is responsible for setting up standard guide in the US..

ISO 27002  is a standard code for implementing information security management systems. while  ISO 27017 is for cloud security.  NIST 800-12 is a general security and NIST 800-14 is for policy development. thus option A is correct.

Note :

All code preceded by ISO is from The International Organization for Standardization and are international standard. while those preceded by NIST is from National Institute of Standards and technology  and are not international standard.

7 0
3 years ago
Hi, Everybody i have a question it is almost my B-day i want this lego set
salantis [7]

Answer:

You can look at different websites of look on an app for people selling it, or something :p

Explanation:

3 0
3 years ago
Other questions:
  • Which certification can help enhance your job prospects in the role of a computer programmer?
    6·2 answers
  • If the Account Number field in a record always should display the three characters in the account number in uppercase, then the
    14·1 answer
  • Pleaseeee help me w this!
    10·1 answer
  • What advantage does a circuit-switched network have over a packet-switched network? What advantages does TDM have over FDM in a
    6·1 answer
  • Suppose that a computer can read or write a memory word in 5 nsec. Also suppose that when an interrupt occurs, all 32 CPU regist
    10·2 answers
  • A(n) _________ is a computer system which is part of a larger system which performs a dedicated function.
    8·1 answer
  • What factor(s) should be considered when determining whether a business is too far based on the query and the user location? Sel
    10·1 answer
  • 2. The internet offers a great source of information; however, how are
    9·1 answer
  • Why do designers of smartphones hide computer processing details from
    14·2 answers
  • PlanthelogicforLungi’sapplicationusingpseudocode.Thelogicneedstosatisfythefollowingneeds:TheapplicationwillneedtoallowLungitoen
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!