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
Uh i g08ujunuyv kjmn
svlad2 [7]

;-;

So uhm-

I'ma just take the free 5 points?

:[

6 0
3 years ago
Read 2 more answers
Which one of the following oscilloscope controls is used to move the trace up and down the screen vertically
kakasveta [241]
B. is the answer to this question
3 0
3 years ago
Ive already tried "word" and "star"
ale4655 [162]

Could use a hint or search  for four letter words

Hope it helped

6 0
3 years ago
How do the companies gather data to determine common passwords?
dsp73
What companies<span> are referring to? was under the impression that when people generate list of </span>common passwords<span> it's based on the results of people cracking leaked encrypted password lists (or using dictionaries created from previously cracked lists). I </span>could<span> be wrong, but that's what I always assumed.</span>
4 0
4 years ago
If you'd like to queue multiple exports and keep working on a different project in Premiere Pro, what method should you use?
pogonyaev

Answer:

Export to Adobe Media Encoder CC only

Explanation:

5 0
3 years ago
Other questions:
  • Which one of the following is an example of hacktivism according to you and why?
    11·1 answer
  • A range of cells can be converted into an Excel ________ so that the data can be analyzed
    7·1 answer
  • Who has access to the source code of proprietary software?
    15·2 answers
  • TRUE OR FALSE!!!!!
    6·2 answers
  • The ________ is the heart of the operating system and controls its most critical processes.
    9·1 answer
  • Which Step did Mario forget ​
    11·1 answer
  • Pick the simplest line of code to test if the word "BASIC" is stored in the variable text1.
    12·1 answer
  • How can using Prezi software for a presentation allow the presenter to better respond to audience needs?
    10·1 answer
  • What is the default return type of a method in Java language?
    9·2 answers
  • #Question 4: #Use a variable to represent the name of a food. You are then going to print this variable four times. Before you d
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!