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
Alona [7]
3 years ago
9

Write a program that prompts for a file name and then reads the file to check for balanced curly braces, {; parentheses, (); and

square brackets, []. Use a stack to store the most recent unmatched left symbol. The program should ignore any character that is not a parenthesis, curly brace, or square bracket. Note that proper nesting is required. For instance, [a(b]c) is invalid.
Computers and Technology
1 answer:
Phoenix [80]3 years ago
5 0

Answer:

Explanation:

The program is written in C++

/*

 C++ Program to check for balanced parentheses in an expression using stack.

 Given an expression as string comprising of opening and closing characters

 of parentheses - (), curly braces - {} and square brackets - [], we need to  

 check whether symbols are balanced or not.  

*/

#include<iostream>

#include<stack>

#include<string>

using namespace std;

// Function to check whether two characters are opening  

// and closing of same type.  

bool ArePair(char opening,char closing)

{

if(opening == '(' && closing == ')') return true;

else if(opening == '{' && closing == '}') return true;

else if(opening == '[' && closing == ']') return true;

return false;

}

bool AreParanthesesBalanced(string exp)

{

stack<char>  S;

for(int i =0;i<exp.length();i++)

{

 if(exp[i] == '(' || exp[i] == '{' || exp[i] == '[')

  S.push(exp[i]);

 else if(exp[i] == ')' || exp[i] == '}' || exp[i] == ']')

 {

  if(S.empty() || !ArePair(S.top(),exp[i]))

   return false;

  else

   S.pop();

 }

}

return S.empty() ? true:false;

}

int main()

{

/*Code to test the function AreParanthesesBalanced*/

string expression;

cout<<"Enter an expression:  "; // input expression from STDIN/Console

cin>>expression;

if(AreParanthesesBalanced(expression))

 cout<<"Balanced\n";

else

 cout<<"Not Balanced\n";

}

You might be interested in
As a member of the accounting group,
Anastasy [175]

Answer:

rtg

Explanation:

rth

3 0
3 years ago
How do you write 124.59 in expanded form?
scZoUnD [109]
124.59 in expanded form is:

100 + 20 + 4 + 0.5 + 0.09
8 0
2 years ago
Read 2 more answers
Suppose you define a java class as follows: public class test { } in order to compile this program, the source code should be st
likoan [24]
Test.java

The classname and the filename need to match (case sensitive).
5 0
3 years ago
4. What is the package name in which the Scanner class resides?
Ahat [919]
Related Articles. Scanner is a class in java. util package used for obtaining the input of the primitive types like int, double, etc. and strings.
7 0
2 years ago
ICT4AD was meant to modernize the civil service through E-governance implementation.
astra-53 [7]

ICT4AD work through E-governance implementation fail as a result of:

  • Lack of Infrastructure.
  • High cost of running its affairs as it needs  huge public expenditure.
  • Issues with Privacy and Security and others.

<h3>What is the aim of e-governance?</h3>

The objectives of e-Governance is created so as to lower the level of corruption in the government and to make sure of  fast administration of services and information.

Conclusively, It is known to fail due to the reasons given above and if they are worked on, the service would have prospered.

Learn more about civil service from

brainly.com/question/605499

7 0
2 years ago
Other questions:
  • Imagine your friend wants to apply
    5·1 answer
  • Which one is not the future of wireless technology?
    8·1 answer
  • Can Word Processing (WP) programs be used for DTP? Explain your answer
    7·1 answer
  • Given a variable temps that refers to a list, all of whose elements refer to values of type float, representing temperature data
    10·2 answers
  • 4. UPS stands for Uninterrupted Power Supply . (Yes /no
    11·1 answer
  • Now the y0utube home screen is gone
    13·2 answers
  • Discuss the impact printer and its types in detail?
    7·1 answer
  • in Java programming Design a program that will ask the user to enter the number of regular working hours, the regular hourly pay
    11·1 answer
  • Jamie Lee is beside herself knowing that the thieves had unauthorized use of her debit/ATM card. What is Jamie's financial respo
    11·1 answer
  • A server is handling thousands of simultaneous connections, and proxying requests to another service. Which concurrency model is
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!