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
Concept explainers
Question
Chapter 18, Problem 11PC
Program Plan Intro
Balanced Multiple Delimiters
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 delimiters.
- If the condition is not true then the string does not have balanced delimiters.
- Inside “is_Balanced ()” function,
- Declare a Boolean variable “status”.
- Declare a character variable “expected”
- Create an object for stack.
- Loop each character.
- Switch to the character.
- If left parenthesis is detected,
- Push it into the stack using the function “push ()”.
- If left braces is detected,
- Push it into the stack using the function “push ()”.
- If left bracket is detected,
- Push it into the stack using the function “push ()”.
- If right parenthesis or right bracket or right braces is detected,
- Get the top element from the stack and store it in a variable “expected”
- Check if the expected character is not equal to “str[k]”.
- Assign “false” if the condition is true.
- Else, pop the element
- If left parenthesis is detected,
- Switch to the character.
- 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
WAP c# program creates a string, s1, which deliberately leaves space for a name, much like you’d do with a letter you plan to run through a mail merge. We add two to the position where we find the comma to make sure there is a space between the comma and the name.
Edef reverse_sentence (s: str) -> str:
Given a sentence , we define a word within to be a continuous
sequence of characters in that starts with a capital letter and
ends before the next capital letter in the string or at the end of
the string, whichever comes first. A word can include a mixture of
punctuation and spaces.
This means that in the string 'ATest string!', there are in fact only two
words: 'A' and 'Test string!'. Again, keep in mind that words start with a
capital letter and continue until the next capital letter or the end of the
string, which is why we consider 'Test string!' as one word.
This function will reverse each word found in the string, and return a new
string with the reversed words, as illustrated in the doctest below.
>>> reverse_sentence('ATest string!')
'A!gnirts tseT'
return
T/F
Suffix array can be created in O(nlogn) time.
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
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- A "generic" data structure cannot use a primitive type as its generic type. O True Falsearrow_forwardIn C programming language Question (Strings) Write a function find_Substring() that finds a substring into a string. Pass array s1 and s2 to this function and prints if the substring is present or not. Expected Output 1: Enter string This is a javascript Enter substring script The substring is present Expected Output 2: Enter string This is a javascript Enter substring Jscript The substring is not presentarrow_forwardDiscrete mathematicsarrow_forward
- Data structures find_color(colors:set, values:list) -> list The function will have two parameters. The first parameter is a set of strings known as Colors. A second parameter is a list of tuple-2 known as Values. Colors will contain a set of randomly selected colors. Values will contain a list of tuples of size 2. Each tuple will contain color (str) and a number (int). The function should look at each tuple in Values. For each tuple, add the number (the second value in the tuple) to a list of numbers if the color in the tuple (the first value in the tuple) is in Colors. In other words, find all tuples that have a color in the Colors and add the tuples numbers to a list. Finally, the function should return the list of numbers collected in the order they are found in the values list. Example: Colors: {'black', 'pink', 'yellow'} values: [('green', 100), ('yellow', 13), ('red', 6)] Expected: [13] Colors: {'yellow'} values: [('black', 54), ('pink', 5)] Expected: [] Colors: {'black',…arrow_forwardTo store a string in C language, we use character array terminated with: \n null @arrow_forwarddef swap_text(text): Backstory: Luffy wants to organize a surprise party for his friend Zoro and he wants to send a message to his friends, but he wants to encrypt the message so that Zoro cannot easily read it. The message is encrypted by exchanging pairs of characters. Description: This function gets a text (string) and creates a new text by swapping each pair of characters, and returns a string with the modified text. For example, suppose the text has 6 characters, then it swaps the first with the second, the third with the fourth and the fifth with the sixth character. Parameters: text is a string (its length could be 0)Return value: A string that is generated by swapping pairs of characters. Note that if the Examples: swap_text ("hello") swap_text ("Party for Zoro!") swap_text ("") def which_day(numbers): → 'ehllo'→ 'aPtr yof roZor!' → '' length of the text is odd, the last character remains in the same position.arrow_forward
- What input or parameter value impacts the number of times the recursive function will be called. • Give three specific examples of input/parameter values and, for each, state the number of times the recursive function will be called. • Devise a formula with respect to n that describes the number of times the recursive function will be called, where n is either the value passed or some property of the value passed (e.g. n might be the length of a string of the size of an array).arrow_forwardPython Language - Bad Luck Numbersarrow_forwardC++arrow_forward
- Static Length, Limited Dynamic Length, and Dynamic Length String implementations have what advantages and disadvantages?arrow_forward* A = [2-31; 20 -1; 1 4 5], then det(A) is 49 39 27 33 Other:arrow_forward#ifndef lab5ExF_h #define lab5ExF_h typedef struct point { char label[10]; double x ; // x coordinate for point in a Cartesian coordinate system double y; // y coordinate for point in a Cartesian coordinate system double z; // z coordinate for point in a Cartesian coordinate system }Point; void reverse (Point *a, int n); /* REQUIRES: Elements a[0] ... a[n-2], a[n-1] exists. * PROMISES: places the existing Point objects in array a, in reverse order. * The new a[0] value is the old a[n-1] value, the new a[1] is the * old a[n-2], etc. */ int search(const Point* struct_array, const char* target, int n); /* REQUIRES: Elements struct-array[0] ... struct_array[n-2], struct_array[n-1] * exists. target points to string to be searched for. * PROMISES: returns the index of the element in the array that contains an * instance of point with a matching label. Otherwise, if there is * no point in the array that its label matches the target-label, * it should return -1. * If there are more than…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage