Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
Question
Book Icon
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 and assign “true”. Else, assign “false”.
    • Return the variable “status”.

Blurred answer
Students have asked these similar questions
Create a  C code that will allow the user to input a word and check whether it is a palindrome or not. 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 exampl 2: Input string:caRrot Reversed string: TORRAC(Note, this can also be all lowercase) Palindrome: No   Note: maximum string length is 20
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.
Stacks 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.

Chapter 19 Solutions

Starting Out with C++ from Control Structures to Objects (9th Edition)

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning