Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 19, Problem 14PC
Program Plan Intro
Balanced Parentheses
Program Plan:
- Include required header files
- Declare function prototype
- Inside “main ()” function,
- Declare a variable “strng”.
- Get a string from the user.
- Check if the Boolean function “is_Balanced ()” returns true.
- If the condition is true then the string has balanced parentheses.
- If the condition is not true then the string does not have balanced parentheses.
- In “is_Balanced ()” function,
- Declare a Boolean variable “status”.
- Create an object for stack.
- Use for loop to step through each character in a string.
- Use Switch…Case structure check the character has set of parentheses or not.
- If left parenthesis is detected,
- Push it into the stack using the function “push ()”.
- If right parenthesis is detected,
- Check if the stack is empty using the function “empty()”.
- If the stack is empty then assign “false”
- If the stack is not empty then assign “true”
- Check if the stack is empty using the function “empty()”.
- If left parenthesis is detected,
- Use Switch…Case structure check the character has set of parentheses or not.
- Check if the stack is empty and assign “true”. Else, assign “false”.
- Return the variable “status”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Create a c code for this pls
Use a stack to reverse the order of a string and identify whether it is a palindrome or not. It should not be case-sensitive.
Example 1:
Input string: Racecar
Reversed string: RACECAR (Note, this can also be all lowercase)
Palindrome: Yes
Note: maximum string length is 20
C++ code
Screenshot and output is must
Please answer this question fast
Chapter 19 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Ch. 19.1 - Describe what LIFO means.Ch. 19.1 - What is the difference between static and dynamic...Ch. 19.1 - What are the two primary stack operations?...Ch. 19.1 - What STL types does the STL stack container adapt?Ch. 19 - Prob. 1RQECh. 19 - Prob. 2RQECh. 19 - What is the difference between a static stack and...Ch. 19 - Prob. 4RQECh. 19 - Prob. 5RQECh. 19 - The STL stack is considered a container adapter....
Ch. 19 - What types may the STL stack be based on? By...Ch. 19 - Prob. 8RQECh. 19 - Prob. 9RQECh. 19 - Prob. 10RQECh. 19 - Prob. 11RQECh. 19 - Prob. 12RQECh. 19 - Prob. 13RQECh. 19 - Prob. 14RQECh. 19 - Prob. 15RQECh. 19 - Prob. 16RQECh. 19 - The STL stack container is an adapter for the...Ch. 19 - Prob. 18RQECh. 19 - Prob. 19RQECh. 19 - Prob. 20RQECh. 19 - Prob. 21RQECh. 19 - Prob. 22RQECh. 19 - Prob. 23RQECh. 19 - Prob. 24RQECh. 19 - Prob. 25RQECh. 19 - Prob. 26RQECh. 19 - Write two different code segments that may be used...Ch. 19 - Prob. 28RQECh. 19 - Prob. 29RQECh. 19 - Prob. 30RQECh. 19 - Prob. 31RQECh. 19 - Prob. 32RQECh. 19 - Prob. 1PCCh. 19 - Prob. 2PCCh. 19 - Prob. 3PCCh. 19 - Prob. 4PCCh. 19 - Prob. 5PCCh. 19 - Dynamic String Stack Design a class that stores...Ch. 19 - Prob. 7PCCh. 19 - Prob. 8PCCh. 19 - Prob. 9PCCh. 19 - Prob. 10PCCh. 19 - Prob. 11PCCh. 19 - Inventory Bin Stack Design an inventory class that...Ch. 19 - Prob. 13PCCh. 19 - Prob. 14PCCh. 19 - Prob. 15PC
Knowledge Booster
Similar questions
- C# language Write a program that creates a Queue or Stack (your choice) that represents a list of work orders. This program should use loop, allowing the user to push and pop items on the stack / queue. The program should also allow the user to print all the items in the stack / queue to the console.arrow_forwardStrings manipulation in C++ : Write a program to take input two strings and print the string that is smaller in length.arrow_forwardC programming language questionarrow_forward
- Python Language - Bad Luck Numbersarrow_forwarddata structure c++ write a function to empty one stack onto the top of the second one and print them Homework: Use the implemented stack to check if the string has a balanced parentheses or not. Your program should read the string from a text file. You should output the read string line and which is valid or not. The parentheses that needed to be checked are (, {, [ and “, with their closed parentheses. If the line doesn’t contain any of these parentheses the output is “empty line” Hint: each student should take the input sheets from the lab supervisor.arrow_forwardPython questions: 1) When using a stack to evaluate the balance of brackets and parentheses in an expression, what is the final step? a. at the end of the expression, if a final closing bracket is found, the brackets balance b. at the end of the expression, if the stack is empty, the brackets balance C. at the end of the expression, if the stack is full, the brackets balance d. at the end of the expression, if the stack is empty, the brackets do not balance 2)If the current state of the stack is [x, y, z, t, r] where x is the bottom of the stack and r is the top of the stack, what is the state of the stack and the value returned after two pops operation a. the state is [z, t, r]; x, y are returned b. the state is [x, y]; z, t, r are returned C. the state is [y, z]; x, t, r are returned d. the state is [x, y, z]; t, r are returned 3)What is the resulting postfix expression from the following infix expression? 12 + 5 * 2 - 3 a. 12 5 2^ * +3 - b. 12 5 +2 3^ * - C. 12 5 +2^ *…arrow_forward
- C Programming Language Note: Input and Output Must be the same Write in C Languagearrow_forward#include <stdlib.h>#include <string.h>#include <stdio.h>#include "stack.h" /* Checks whether the parenthesis in str are balanced using the stack. Returns 1, if balanced 0, if unbalanced An expression has balanced parenthesis if it satisfies the following conditions: 1. The first observed parenthesis cannot be a closing parenthesis 2. All opening parentheses should have matching closing parenthesis 3. The parentheses cannot be intertwined but can be nested*/int parenthesis_balance_check(LINKED_STACK stack, char* str); int main() { return 0;} PLEASE ONLY USE "C" LANGUAGE, DONT USE "C#" AND "C++"arrow_forward3. Use a stack to evaluate the following postfix expression. 3 5 7 + 2 1 * 1 + +arrow_forward
- Data structure/ C language / Graph / Dijkstra’s algorithm implement a solution of a very common issue: how to get from one town to another using the shortest route.* design a solution that will let you find the shortest paths between two input points in a graph, representing cities and towns, using Dijkstra’s algorithm. Your program should allow the user to enter the input file containing information of roads connecting cities/towns. The program should then construct a graph based on the information provided from the file. The user should then be able to enter pairs of cities/towns and the algorithm should compute the shortest path between the two cities/towns entered.Attached a file containing a list of cities/towns with the following data:Field 1: Vertex ID of the 1st end of the segmentField 2: Vertex ID of the 2nd of the segmentField 3: Name of the townField 4: Distance in Kilometer Please note that all roads are two-ways. Meaning, a record may represent both the roads from…arrow_forwarddata structure in c++ pls do use more // comments especially the linked list partarrow_forwardData structure/ C language / Graph / Dijkstra’s algorithm implement a solution of a very common issue: howto get from one town to another using the shortest route.* design a solution that will let you find the shortest paths betweentwo input points in a graph, representing cities and towns, using Dijkstra’salgorithm. Your program should allow the user to enter the input filecontaining information of roads connecting cities/towns. The programshould then construct a graph based on the information provided from thefile. The user should then be able to enter pairs of cities/towns and thealgorithm should compute the shortest path between the two cities/townsentered.Attached a file containing a list of cities/towns with the following data:Field 1: Vertex ID of the 1st end of the segmentField 2: Vertex ID of the 2nd of the segmentField 3: Name of the townField 4: Distance in KilometerPlease note that all roads are two-ways. Meaning, a record may representboth the roads from feild1 to field2…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning