A string may use more than one type of delimiter to bracket information into blocks.  For example, a string may use braces { }, parentheses ( ), and brackets [ ] as delimiters.  A string is properly delimited if each right delimiter is matched with a preceding left delimiter of the same type in such a way that either the resulting blocks of information are disjoint, or one of them is completely nested within the other.  Write a program that uses a single stack to check whether a string containing braces, parentheses, and brackets is properly delimited. Use input file string.txt as input to test your program. Each line in the input file is a string.  If the string is properly delimited, display a message stating so.  If it is not properly delimited, display a message stating so. For example, if the input file contains the following 3 lines of strings: if (a[i] > b[i]) while (c[index] < 0) { a++; b--; c[index++];} for ({int i = 0; num[i }]; would display the following output: Processing input file... String: 1.  is properly delimited 2.  is properly delimited 3.  is not properly delimited End of file.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question


A string may use more than one type of delimiter to bracket information into blocks.  For example, a string may use braces { }, parentheses ( ), and brackets [ ] as delimiters. 

A string is properly delimited if each right delimiter is matched with a preceding left delimiter of the same type in such a way that either the resulting blocks of information are disjoint, or one of them is completely nested within the other. 

Write a program that uses a single stack to check whether a string containing braces, parentheses, and brackets is properly delimited.

Use input file string.txt as input to test your program.

Each line in the input file is a string.  If the string is properly delimited, display a message stating so.  If it is not properly delimited, display a message stating so.

For example, if the input file contains the following 3 lines of strings:

if (a[i] > b[i])
while (c[index] < 0) { a++; b--; c[index++];}
for ({int i = 0; num[i }];

would display the following output:

Processing input file...

String:
1.  is properly delimited
2.  is properly delimited
3.  is not properly delimited

End of file.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Knowledge Booster
Problems on Dynamic Programming
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning