Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 18, Problem 14PC
Program Plan Intro
Stack Based Evaluation of Postfix Expression
Program Plan:
- Declare a function skipWhiteSpace that Skips whitespace in an input stream while evaluating a postfix expression.
- Declare a Function postFixEval that evaluates the postfix expression by considering if the next token in the input stream is an integer, read the integer and push it onto the stack using the push() operation of the stack .
- But if the input stream is an operator, pop the last two values from the stack using the pop operation and apply the operator, and push the result onto the stack and the lone value is the result.
- Declare the main function.
- Prompt the user to enter a postfix expression.
- Evaluate the postfix expression by calling the postFixEval function and print the result.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Programming Language :- C
Python Language - Bad Luck Numbers
A sequence of instructions may be used to see the function's return address. Any modifications to the stack must be made with the return of the method to its caller in mind.
Chapter 18 Solutions
Starting Out with C++: Early Objects (9th 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. 9PCCh. 18 - Prob. 10PCCh. 18 - Prob. 11PCCh. 18 - Prob. 12PCCh. 18 - Prob. 13PCCh. 18 - Prob. 14PCCh. 18 - Prob. 15PC
Knowledge Booster
Similar questions
- (Numerical) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters to 0, and then generate a large number of pseudorandom integers between 0 and 9. Each time a 0 occurs, increment the variable you have designated as the zero counter; when a 1 occurs, increment the counter variable that’s keeping count of the 1s that occur; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of the time they occurred.arrow_forwardJava - Contains the Characterarrow_forward7. 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_forward
- slecetion sort (python) Selection sort is a sorting algorithm, like Bubble sort which you saw in the previous module. Selection sort works as follows: Selection sort divides the input list into two parts: a sublist of sorted items (left part) and a sublist of still unsorted items (right part). Initially, the sorted sublist is empty and the whole input consists of the unsorted sublist. To fill the sorted sublist, the algorithm computes the (index of) the minimum of the unsorted sublist and swaps the first unsorted element and the minimum element (if the minimum is already the first element, nothing happens). Afterward, the sorted sublist is one bigger. This continues until the unsorted sublist is empty and the entire input is sorted. Example: Sorted sublist Unsorted sublist Least element in unsorted list () (11, 25, 12, 22, 64) 11 (11) (25, 12, 22, 64) 12 (11, 12) (25, 22, 64) 22 (11, 12, 22) (25, 64) 25 (11, 12, 22, 25) (64) 64 (11, 12, 22, 25, 64) () Implement this…arrow_forwarddata structure in c++ pls do use more // comments especially the linked list partarrow_forwardA set of instructions may be used to show the return address of a function. Remember that any changes to the stack must not prevent the procedure's return to its caller.arrow_forward
- Program 3 - List Practice Write a program that either: 1. Reads 10 integers from the user, or 2. Generates 10 integers between -10 and 10 randomly And then 1. Prints out the maximum integer 2. Print out the sum of the integers Without using built in functions such as max() or sum()arrow_forwardInstructor: Muhammad Haris Due Date: December 3 Question 1: Take a character string from user as input and check if the word is a palindrome. For example: Deed, madam etc. Hint: Use Stackarrow_forwardCodeWorkout Gym Course Search exercises... Q Search kola shreya@colum X459: Review- Fibonacci In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, characterized by the fact that every number after the first two is the sum of the two preceding ones: e, 1, 1, 2, 3, 5, 8, 13, Write a recursive function that the returns the nth fibonacci number. Examples: fibonacci(0) -> 0 fibonacci(1) -> 1 fibonacci(7) -> 13 Your Answer: 1 public int fibonacci(int n) { 2 3} 4 CodeWorkout © Virginia Tech About License Privacy Contactarrow_forward
- Data structure/ C language / Graph / Dijkstra’s algorithm implement a solution of a very common issue: how to get from one town to another using the shortest route.* design a solution that will let you find the shortest paths between two input points in a graph, representing cities and towns, using Dijkstra’s algorithm. Your program should allow the user to enter the input file containing information of roads connecting cities/towns. The program should then construct a graph based on the information provided from the file. The user should then be able to enter pairs of cities/towns and the algorithm should compute the shortest path between the two cities/towns entered.Attached a file containing a list of cities/towns with the following data:Field 1: Vertex ID of the 1st end of the segmentField 2: Vertex ID of the 2nd of the segmentField 3: Name of the townField 4: Distance in Kilometer Please note that all roads are two-ways. Meaning, a record may represent both the roads from…arrow_forwarddjkvnuisdvsuykb jkxcnjlvnocvarrow_forwardC Programming Language Task: Deviation Write a program that prompts the user to enter N numbers and calculates which of the numbers has the largest deviation from the average of all numbers. You program should first prompt the user to enter how many numbers that will specify. The program should then scan for each number, separated by a newline. You should calculate the average value and return the number from the list which is furthest away from this average (to 2dp). Try using dynamic memory functions to store the incoming array of numbers on the heap. Code to build from: + 1 #include 2 #include 3 4 int main(void) { 5 6} 7 Output Example: deviation.c How many numbers? 5 Enter them: 1.0 2.0 6.0 3.0 4.0 Average: 3.20 Largest deviation from average: 6.00arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning