answer.
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
svetoff [14.1K]
2 years ago
3

Write a function that takes a string parameter and determines whether the string contains matching grouping symbols. Grouping sy

mbols are parenthesis ( ) , brackets [] and curly braces { }. For example, the string {a(b+ac)d[xy]g} and kab*cd contain matching grouping symbols. However, the strings ac)cd(e(k, xy{za(dx)k, and {a(b+ac}d) do not contain matching grouping symbols. (Note: open and closed grouping symbols have to match both in number and in the order they occur in the string). Your function must use a stack data structure to determine whether the string parameter satisfies the condition described above. You may define your own stack class or use the STL stack class. Write a driver program (i.e. a function main()) to test your function.
Deliverables:

1. a copy of your function and the test driver program source codes in a text file

2. screen shots of your test driver program runs showing it meets the problem's specifications. This is what I've done so far: I've copied the material from the book as well as from some sources on the internet. Could you edit my code and write it in C++. Some of my code is in Java.

Computers and Technology
1 answer:
Alex73 [517]2 years ago
5 0

Answer:

See attachment below

Program to check for matching symbols

// Program is written in C++

// Comments are used for explanatory purposes

// Program Starts here

#include<bits/stdc++.h>

using namespace std;

bool CheckParenthesis(string word)

{

int pos = 0;

char singlechar;

stack<char> stackchar;

for (pos=0; pos<word.length(); pos++)

{

//Check for opening paranthesis

if (word[pos]=='('||word[pos]=='['||word[pos]=='{')

{

stackchar.push(word[pos]);

continue;

}

if (stackchar.empty())

return false;

switch (word[pos])

{

//Check for closing paranthesis

case ')':

singlechar = stackchar.top();

stackchar.pop();

if (singlechar=='{' || singlechar=='[') {

return false; }

break;

case ']':

singlechar = stackchar.top();

stackchar.pop();

if (singlechar =='(' || singlechar == '{') {

return false; }

break;

}

case '}':

singlechar = stackchar.top();

stackchar.pop();

if (singlechar=='(' || singlechar=='[') {

return false; }

break;

}

return (stackchar.empty());

}

// Main Program Starts Here

int main()

{

//Declare String

string word;

cout<<"Enter some string texts:";

cin>>word;

//Check for matching symbols

if (CheckParenthesis(word))

cout << "Matching Symbols";

else

cout << "No Matching Symbols";

return 0;

}

You might be interested in
Which of the following is not a characteristic of a good value log entry
Stolb23 [73]
What are we supposed to find? Help us
6 0
1 year ago
Describe the output when the following code executes in 64-bit mode: .data dividend_hi QWORD 00000108h dividend_lo QWORD 3330002
iragen [17]

Answer:

RAX = 333000h (16 bits with preceding zeros removed)

RDX = 20h (also 16 bits with preceding zeros removed)

Explanation:

The "div" opcode in the assembly language source code is used to divide operands. It accepts a divisor ( the denominator) and divides the content of the AX register. The result is saved in the AX register while the remainder (if any) is saved in the DX register. If the DX register holds any data, the data is replaced with the divisor remnant.

The code above divides the content of the RAX register with the divisor variable and saves the result and remainder in the RAX and RDX respectively.

7 0
2 years ago
There is a function we are providing in for you in this problem called square. It takes one integer and returns the square of th
anastassius [24]

Answer:

xyz = 25  

result = square(xyz)

print(result)

The above code assigns the value 25 to variable xyz as 5*5=25. Then next statement is a function call to square() function passing xyz to this function in order to compute the square of 25. The output is:

625

Explanation:

The above code can also be written as:

xyz = 5*5

result = square(xyz)

print(result)

The difference is that xyz is assiged 5*5 which is equal to 25 so the output produced will be the same i.e.  625.

The result variable is used to store the value of square of 25 after the square() method computes and returns the square of 25. So print(result) prints the resultant value stored in the result variable i.e. 625

3 0
2 years ago
What is the Gain (dB) of a transmission if the Maximum Data Rate is 1 Gbps and the Bandwidth =7000 MHz? Group of answer choices
denpristay [2]

Answer:

15.420 dB

Explanation:

the Gain (dB) of a transmission if the Maximum Data Rate is 1 Gbps and the Bandwidth =7000 MHz is 15.420 dB.

3 0
2 years ago
Anna bought a box of blueberries for £7. She used 700 grams for a cheesecake and she has 450 grams left. How much did the bluebe
xxTIMURxx [149]

0.61 (rounded up)

Explanation:

You add both 700 and 450 which will give you 1150g

You then divide 1150 by 100 which gives you 11.5

Then divide 7 by 11.5 which will give you 0.61 as cost of every 100 grams

8 0
2 years ago
Other questions:
  • What are the two most important network-layer functions in a datagram network? what are the three most important network-layer f
    7·1 answer
  • Write a method named quarterstodollars. the method should accept an int argument that is a number of quarters, and return the eq
    13·2 answers
  • As an information user you should be skeptical of
    7·1 answer
  • 14. If B3=10 and D5=8, what would the following function return? IF(B3&gt;D5, "Closed", D5-B3) *
    9·1 answer
  • PowerPoint is a visual aid for many speakers. Discuss some points to remember when adding text to a PowerPoint presentation. How
    13·1 answer
  • Assignment 1 is to write a program that will write the lyrics to "X number of beers on the wall". Use only the main method. Prom
    11·1 answer
  • A program is divided into 3 blocks that are being compiled on 3 parallel computers. Each block takes an Exponential amount of ti
    6·1 answer
  • Why is it important for element IDs to have meaningful names?
    11·1 answer
  • A Consider the following method definition. The method printAllCharacters is intended to print out every character in str, start
    11·1 answer
  • A data analyst is using the Color tool in Tableau to apply a color scheme to a data visualization. They want the visualization t
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!