Starting Out with C++: Early Objects
Starting Out with C++: Early Objects
8th Edition
ISBN: 9780133360929
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: Addison-Wesley
Question
Book Icon
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 and assign “true”. Else, assign “false”.
    • Return the variable “status”.

Blurred answer
Students have asked these similar questions
Stack using C++ programmijng language please  Write a program to input an arithmetic expression, then 1. Match nested brackets found the expression, if they are matched correctly proceed to step 2.2. Evaluate the expression. Please not that the operands of the expression may contain more than one digit. the cin of the arithmetic expression is :: ((5+(6/2*3)-2)+1)= you can use this function also :::  struct node { int data; node *next; node(int d,node *n=0) { data=d; next=n; } }; class stack { node *topp; public: stack(); void push(int el); bool pop(); int top(); bool top(int &el); //~stack(); //void operator=(stack &o); //stack(stack &o); }; stack::stack() { topp=0; } void stack::push(int el) { topp=new node(el,topp); } bool stack::pop() { if(topp==0) return false; node *t=topp; topp=topp->next; delete t; return true; } int stack::top() { if(topp!=0) return topp->data; } bool stack::top(int &el) { if(topp==0) return false; el=topp->data; return true; }
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
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.
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