Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134521176
Author: SAVITCH
Publisher: PEARSON
Question
Book Icon
Chapter 13, Problem 10PP
Program Plan Intro

Creation of program to display result of computation of Reverse polish Notation

Program Plan:

  • Define a file “Stack.h” to declare operation and methods in stack.
    • Define a structure “StckNde” that contains data and link to next node as members.
    • Define a class “Stack” to define methods and prototypes.
      • Define function prototypes for methods in program.
  • Define a file “Stack.cpp” to define operations and methods in stack.
    • Define a constructor “Stack()” to create an empty stack.
    • Define a destructor “~Stack()” to destroy a stack.
    • Define a method “empty()” to check whether stack is empty.
    • Define a method “pop()” to remove top element of stack.
    • Define a method “datatyeCon()” to display error if stack is empty.
    • Define a method “operator=()” to define operation for “=” operator.
    • Define a method “operator==()” to define operation for “==” operator.
  • Define a file “Main.cpp” to call methods in stack and perform all computations.
    • Declare variables required for the program.
    • Get expression from user.
    • Check for operators and operands.
    • Define a switch case to perform different computations in expression.
    • Display result of operation.

Blurred answer
Students have asked these similar questions
A SpecialStackTM is a stack modified to support the following two operations: PUSHCLEAR(v) successively pops consecutive items from the top of the stack that are less than u, then pushes v onto the stack. POP() deletes the item at the top of the stack. Assume these operations are implemented using a singly-linked list. PUSHCLEAR(v) iter- ates through the linked list to pop the applicable items and then adds v to the beginning. POP() deletes the first item. (a) Describe the ordering of values on the stack. (b) Explain how a single call to PUSHCLEAR(V) could take (n) time. (c) If we assume that every operation takes linear time, we get a naive bound of O(n²) on the total runtime. But this doesn't consider the fact that these expensive operations happen infrequently so let's analyze it more closely. Show that any sequence of n operations takes O(n) time. -
Given a stack, switch_pairs function takes a stack as a parameter and thatswitches successive pairs of numbers starting at the bottom of the stack.For example, if the stack initially stores these values:bottom [3, 8, 17, 9, 1, 10] topYour function should switch the first pair (3, 8),the second pair (17, 9), ...:bottom [8, 3, 9, 17, 10, 1] topif there are an odd number of values in the stack, the value at the top of thestack is not moved: For example:bottom [3, 8, 17, 9, 1] topIt would again switch pairs of values, but the value at thetop of the stack (1)would not be movedbottom [8, 3, 9, 17, 1] topNote: There are 2 solutions:first_switch_pairs: it uses a single stack as auxiliary storagesecond_switch_pairs: it uses a single queue as auxiliary storage""".
Write a program for Stack (Array-based or linked list-based) in Python. Test the scenario below with the implementation and with the reasoning of the answer. Make comments with a short description of what is implemented. Include source codes and screen-captured outputs. Stack: A letter means doing a push operation and an asterisk means doing a pop operation in the below sequence. Give the sequence of letters that are returned by the pop operations when this sequence of operations is performed on an initially empty stack. A*BCE**F*GH***I*
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning