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]
2 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]2 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
The keyboard,mouse, display,and system units are:​
Ymorist [56]

Answer:

input devices?

Explanation:

Keyboard: It is used to give input through typing of the keys in keyboard. Mouse: It is used to give input through clicking mouse or selecting the options. System unit: It collectively defines the motherboard and CPU of the computer.

7 0
3 years ago
Read 2 more answers
JAVA
avanturin [10]

Answer:

   public ArrayList onlyBlue(String[] clothes){

       ArrayList<String> blueCloths = new ArrayList<>();

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

           if(clothes[i].equalsIgnoreCase("blue")){

               blueCloths.add(clothes[i]);

           }

       }

       return blueCloths;

   }

Explanation:

  • Create the method to accept an Array object of type String representing colors with a return type of an ArrayList
  • Within the method body, create and initialize an Arraylist
  • Use a for loop to iterate the Array of cloths.
  • Use an if statement within the for loop to check if item equals blue and add to the Arraylist.
  • Finally return the arrayList to the caller
3 0
2 years ago
A(n) ____ algorithm is a set of specific, sequential steps that describe in natural language exactly what a computer program mus
Paul [167]
<span>The answer is algorithm, because computer programmers need a programming language that's more similar to their native language. They then write specific steps a computer must take to complete the task at hand. Machine code is not easily memorized and is foreign to most people.</span>
8 0
3 years ago
A _________ is a set of instructions (program) in Scratch.<br> code
bulgar [2K]
Program or software program, also you could use an html or css program
6 0
3 years ago
What can we learn from the example of the wi-fi alliance with regard to the necessity of networking standards?
Vera_Pavlovna [14]
The Wi-Fi alliance is an alliance that promotes the wireless technologies and the interoperability between them. It defines the the security of the wireless technologies and the application protocols. From this example we can learn that is crucial to have one platform that defines the main characteristic of a type of network in order to have strictly defined standards and protocols, and by doing so, have interoperable networks. 
7 0
3 years ago
Other questions:
  • Knowing the meaning of the acronym WYSIWYG can be most helpful to you when you
    14·1 answer
  • A hard disk has four surfaces (that's top and bottom of two platters). Each track has 2,048 sectors and there are 131,072 (217)
    11·1 answer
  • Write the sql command to show which tutor needs to be reminded to turn in reports.
    13·1 answer
  • Which of the following is not a technology that can be used to conserve resources?
    8·2 answers
  • This is a program that calculates information about orders of shirts and pants. All orders have a quantity and a color. Write a
    7·1 answer
  • What are the 5 characteristics of flowchart<br>​
    14·1 answer
  • Most significant effect the rotary press had on printing
    9·1 answer
  • The system where the unit of measurement is centimeter
    15·1 answer
  • Molly needs to access a setting in microsoft windows group policy to change the type of a network to which a computer is attache
    15·1 answer
  • An entity is said to be _____-dependent if it can exist in the database only when it is associated with another related entity o
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!