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 15PC
Program Plan Intro
Stack Based evaluation of prefix expression
Program Plan:
- Declare a structure to create a stack element.
- Include all the required header files.
- Declare a function to input prefix statements.
- Declare a Function int evaluate that evaluates the prefix 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 function bool prefix_reducible that returns true if there are at least three elements on the stack and top two elements are values and the third from the top is an operator.
- Declare the main function.
- Prompt the user to enter a prefix expression.
- Evaluate the prefix expression by calling the int evaluate function and print the result.
- Prompt the user to enter a prefix expression.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Python Language - Bad Luck Numbers
C Programming Language
Note:
Input and Output Must be the same
Write in C Language
C++ code
Screenshot and output is must
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
- C 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_forwardJava - Contains the Characterarrow_forwardPlease answer this question fastarrow_forward
- Modular Programming: Your program should be modular and consists of the following functions: a) read(): - Ask the user for a valid atomic number (Z) b) compute_binding_energy(Z, table): - Build the table (a list of lists) of binding energy where the columns are: the mass number (A), the binding energy (Eb) and the binding energy per nucleon (BEN), while the rows range from A = Z to A = 4Z c) most_stable(table) : - Find and return the row that contains the highest binding energy per nucleon, which corresponds to the most stable configuration. d) print_table(table): - Print the table in a neat tabular format as shown in the sample run in figure 2. e) write_to_file(table, file_name): - Save the table in a text file output.txt as shown in figure 3. 4 f) main(): - The main function is set up to make the calls to the functions as specified in points a) to e)arrow_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_forwardC programming language questionarrow_forward
- C++arrow_forwardC Programarrow_forwardC++ Code Please Using Queue We can use a queue to simulate the flow of customers through a check-out line in a store. In this simulation we will have the following details: one check-out line the expected service time for each customer is one minute (However, they may have to wait in line before being serviced) between zero and two customers join the line every minute We can simulate the flow of customers through the line during a time period n minutes long using the following algorithm: Initialize the queue to empty. for ( minute = 0 ; minute < n ; ++minute ) { if the queue is not empty, then remove the customer at the front of the queue. Compute a random number k between 0 and 3. If k is 1, then add one customer to the line. If k is 2, then add two customers to the line. Otherwise (if k is 0 or 3), do not add any customers to the line. } In addition, the algorithm will keep track of the following: the total number of customers served the…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 Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning