Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 18, Problem 10PC
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
A set of instructions may be used to show a function's return address. Remember that any modifications you make to the stack cannot prevent the procedure from returning to its caller.
Chapter 18 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 18.3 - Describe what LIFO means.Ch. 18.3 - What is the difference between static and dynamic...Ch. 18.3 - What are the two primary stack operations?...Ch. 18.3 - What STL types does the STL stack container adapt?Ch. 18 - Prob. 1RQECh. 18 - Prob. 2RQECh. 18 - What is the difference between a static stack and...Ch. 18 - Prob. 4RQECh. 18 - The STL stack is considered a container adapter....Ch. 18 - What types may the STL stack be based on? By...
Ch. 18 - Prob. 7RQECh. 18 - Prob. 8RQECh. 18 - Prob. 9RQECh. 18 - Prob. 10RQECh. 18 - Prob. 11RQECh. 18 - Prob. 12RQECh. 18 - Prob. 13RQECh. 18 - Prob. 14RQECh. 18 - Prob. 15RQECh. 18 - Prob. 16RQECh. 18 - Prob. 17RQECh. 18 - Prob. 18RQECh. 18 - Prob. 1PCCh. 18 - Prob. 2PCCh. 18 - Prob. 3PCCh. 18 - Prob. 4PCCh. 18 - Prob. 5PCCh. 18 - Prob. 6PCCh. 18 - Prob. 7PCCh. 18 - Prob. 8PCCh. 18 - Prob. 14PCCh. 18 - Prob. 9PCCh. 18 - Prob. 10PCCh. 18 - Prob. 11PCCh. 18 - Prob. 12PCCh. 18 - Prob. 13PCCh. 18 - Prob. 15PC
Knowledge Booster
Similar questions
- 7. The following function converts a postfix expression to an infix expression assuming the expression can only contain unsigned integer numbers and +' and -' operators. 1. public static String convert (String postfix) { 2. String operand1, operand2, infix; 3. Stack s = new AStack; 4. int i = 0; 5. while (i < postfix.length) { char nextc = postfix.charAt (i); if ((nextc 6. 7. '+')|| (nextc == '-') { == operand2 = s.pop (); operandl = s.pop () ; infix = '(' + operandl + nextc + operand2 + ')'; s.push (infix); i++; 8. 9. 10. 11. } 12. else if (Character.isDigit (nextc)){ int start = i; while (Character.isDigit (postfix.charAt (i)) i++; infix = postfix.substring (start, i); s.push (infix); 13. 14. 15. 16. 17. } else i++; 18. 19. } 20 return s.pop () ; 21. } (a) Rewrite only the lines of code that need to be changed so that the above function converts a postfix expression to a prefix expression. (b) Describe in words what changes are needed on the above given convert () function so that it…arrow_forwardC++arrow_forwardStrings manipulation in C++ : Write a program to take input two strings and print the string that is smaller in length.arrow_forward
- C programming languagearrow_forwardPlease answer this question fastarrow_forwardStacks 1- Write a Python function that takes a user input of a word and returns True if it is a Palindrome and returns False otherwise (Your function should use a Stack data structure). A palindrome is a word that can be read the same backward as forward. Some examples of palindromic words are noon, civic, radar, level, rotor, kayak, reviver, racecar, redder, madam, and refer. 2- Write a Python function that takes a stack of integer numbers and returns the maximum value of the numbers in the stack. The stack should have the same numbers before and after calling the function. 3- Write a main function that tests the functions you wrote in 1 and 2 above and make sure that your code is well documented.arrow_forward
- C programming language questionarrow_forward* This function evaluates the provided postfix expression. When an operand is encountered, it is added to the stack. When an operator is encountered, two operands are popped, the operation is evaluated, and the result is pushed to the stack.* @param expr string postfix expression representation * @return value of the supplied expressionarrow_forwardC# 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_forward
- 1. Read input 5 integer values from the user and print them in the reverse order of their input using a stack data structure. Programming languages allowed: C++/JAVA/Pythonarrow_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_forwardC++ Coding: Branching Write one line of code to print a random value between -10 and 22 inclusive.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