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
Think of an example in your life where a number could be described as data, information, and knowledge
zhannawk [14.2K]

Answer:

how many event you have been too in the last month (well non during this time but as an example)

Explanation:

4 0
2 years ago
Which of the following statements are true about mobile app development? Select 3 options.
mestny [16]

Answer:

Option 1,4 and 5 are correct.

7 0
2 years ago
Read 2 more answers
Namespaces cannot have namespaces as members.<br><br> True<br><br> False
Anna71 [15]

Answer:

False

Explanation:

namespaces can be nested. That is we can have a hierarchy of namespaces.

For examples suppose we have a namespace top. Within this we have another namespace first. At the next level we have a namespace called second. Then we have a class MyClass as a member of this namespace second. Then the complete description of the class will be as follows:

top::first::second::MyClass

5 0
3 years ago
What will be the output of the following code?
saveliy_v [14]

Answer:

The correct answer to this question is given below in the explanation section.

Explanation:

The correct answer to this question is : 4.

When you run this program in Java. The output produce by this program is 4

The given code is:

import java.util.ArrayList;

public class arrayList7

{

public static void main(String[] args) {

ArrayList one = new ArrayList ();

Integer count=3;

count=count+1;

one.add(2);

one.add(count);

System.out.println(one.get(1));

}

}

This code store the value in ArrayList one variable. It first adds 2 at zero indexes and 4 at first index.  When you print the value at index one, you will get the output 4. because the count variable contains 4. If you want to print 2, then you specify the print statement that prints the value at index zero. eg.

System.out.println(one.get(0));

5 0
3 years ago
Suppose Client A initiates a Telnet session with Server S. At about the same time, Client B also initiates a Telnet session with
poizon [28]

Answer:

An answer to this question is given below in explanation section.

Explanation:

The given question is incomplete. First, we write the complete question that is:

Suppose Client A initiates a Telnet session with Server S. At about the same time, Client B also initiates a Telnet session with Server S. Run telnet in a terminal and capture the traffic on Wireshark. For example, open a telnet session using this command: "telnet cs537.cs.csusm.edu". What are the source and destination port numbers for the following items?

  1. the segment sent from A to S.
  2. the segment sent from B to S.
  3. the segment sent from S to A.
  4. the segment sent from S to B.
  5. if A and B are different hosts, is it possible that the source port number in the segments from A to S is the same as that from B to S?
  6. how about if they are the same host?

Answers

                           Source Port Numbers               Destination Port Number

  1. A -> S                      1467                                               23
  2. B -> S                       1513                                               23
  3. S->A                         23                                                  1467
  4. S->B                         23                                                  1513
  5. Yes, it is that the source port number in the segement from A to S is the same as that from B to S. In short, there is no relationship between port numbers on different hosts
  6. no, a port number identify UNIVOCALLY a process.

5 0
2 years ago
Other questions:
  • The system administrator in your office quits unexpectedly in the middle of the day. It's quickly apparent that he changed the s
    10·1 answer
  • The true or false questions.
    5·1 answer
  • You are configuring two switches of different vendors such that they connect to each other via a single link that will carry mul
    13·1 answer
  • _____________ refers to know-what and know-why of technology.
    12·1 answer
  • If you press the key corresponding to letter A on the keyboard, what process is carried out inside the CPU to display the letter
    10·1 answer
  • Write a paragraph on the following topic.
    14·1 answer
  • I need help plzzzzzzzz
    10·2 answers
  • Write a program that asks for the names of three runners and the time, in minutes (no seconds, etc.), it took each of them to fi
    7·1 answer
  • 1. True or false: The more pixels per inch in an image, the higher the resolution is. (1 point)
    8·1 answer
  • In C, how could I use a command line input to remove certain characters from an existing string? For example, if I have string '
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!