STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
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
C++ code
Screenshot and output is must
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…
Strings manipulation in C++ :
Write a program to take input two strings and print the string that is smaller in length.
Chapter 18 Solutions
STARTING OUT WITH C++ MPL
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. 9PCCh. 18 - Prob. 10PCCh. 18 - Prob. 11PCCh. 18 - Prob. 12PCCh. 18 - Prob. 13PCCh. 18 - Prob. 14PCCh. 18 - 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_forwardExercise Objectives Problem Description Write a program that reads a string and mirrors it around the middle character. Examples: abcd becomes cdab. abcde becomes deCab AhmadAlami becomes AlamiAhmad Page 1 of 2 Your program must: • Implement function void reflect (char* str) which receives a string (array of characters) and mirrors it. This function does not print anything. • Read from the user (in main()) a string and then print the string after calling function reflect(). • Use pointers and pointer arithmetic only. The use of array notation and/or functions from the string.h library is not allowed.arrow_forwardC++arrow_forward
- Python Language - Bad Luck Numbersarrow_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_forwardAlert - don't use AIarrow_forward
- Expression Conversion Design a program which can tansfer an infix expression into a postfix expression and compute its result. Suppose the infix expression only includes’ *’, ‘/’, ‘+’, ‘-‘, ‘(‘, ‘)’ and the numbers are all integers. [Basic Requirements] 1) You are required to use stack. 2) The infix expression is inputted from keyboard as a string. If the input is legal, please convert the infix expression into postfix expression, calculate the result, and finally output the postfix expression and its value. 3) If the infix expression entered is illegal, the program can prompt the user to input incorrectly and prompt the user to re-enter. Please do the program according to the requirements above and it should be in C language...also after the code i want a report that the algorithm explanations of the code plesse don't just copy other student program and give me back please please pleasearrow_forwardExpression Conversion Design a program which can tansfer an infix expression into a postfix expression and compute its result. Suppose the infix expression only includes’ *’, ‘/’, ‘+’, ‘-‘, ‘(‘, ‘)’ and the numbers are all integers. [Basic Requirements] 1) You are required to use stack. 2) The infix expression is inputted from keyboard as a string. If the input is legal, please convert the infix expression into postfix expression, calculate the result, and finally output the postfix expression and its value. 3) If the infix expression entered is illegal, the program can prompt the user to input incorrectly and prompt the user to re-enter. I want the program to be written in C language and want explanation for the algorithm of this programarrow_forwardC Programming Language Note: Input and Output Must be the same Write in C Languagearrow_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