STARTING OUT WITH C++ REVEL >IA<
STARTING OUT WITH C++ REVEL >IA<
9th Edition
ISBN: 9780135853115
Author: GADDIS
Publisher: PEARSON
Question
Book Icon
Chapter 19, Problem 1PC
Program Plan Intro

Static Stack Template

Program Plan:

Main.cpp:

  • Include required header files.
  • Inside the “main ()” function,
    • Create an object named “stck” for stack.
    • Declare a variable named “popElem”.
    • Push 5 elements inside the stack using the function “push_Elem ()”.
    • Pop 5 elements from the stack using the function “pop_Elem ()”.

Stack.h:

  • Include required header files.
  • Create a template.
  • Declare a class named “Stack”. Inside the class
    • Inside the “private” access specifier,
      • Create an object for the template
      • Declare the variables “stackSize” and “top_Elem”.
    • Inside the “public” access specifier,
      • Give a declaration for an overloaded constructor.
      • Give function declaration for “push_Elem ()”, “pop_Elem ()”, “is_Full ()”, and “is_Empty ()”.
  • Give function definition for the overloaded constructor.
    • Create stack size
    • Assign the value to the “stackSize”.
    • Assign -1 to the variable “top_Elem”
  • Give function definition for “push_Elem ()”.
    • Check if the stack is full using the function “is_Full ()”
      • If the condition is true then print “The stack is full”.
      • If the condition is not true then,
        • Increment the variable “top_Elem”.
        • Assign the element to the top position.
  • Give function definition for “pop_Elem ()”.
    • Check if the stack is empty using the function “is_Empty ()”
      • If the condition is true then print “The stack is empty”.
      • If the condition is not true then,
        • Assign the element to the variable “num”.
        • Decrement the variable “top_Elem”.
  • Give function definition for “is_Full ()”.
    • Assign Boolean value to the variable
    • Check if the top and the stack size is same
      • Assign true to “status”.
    • Return the status
  • Give function definition for “is_Empty ()”.
    • Assign Boolean value to the variable
    • Check if the top is equal to -1.
      • Assign true to “status”.
    • Return the status

Blurred answer
Students have asked these similar questions
static binding,a) Allocate stack memoryb) allocate static memoryWhat is the advantage of a) compared to b)?
Apply the Stack Applications algorithms in c++. You have to implement the stack using the static array or the linked list. You have to create a project for each algorithm. Add a screenshot of the output for each project.
1. Assume the existence of a class Stack whose implementation is unknown (array versus nodes), withoperationspushandpop. Write a Stack methodvoid reverseStack()that reverses the order of theelements contained in the Stack. You can assume the existence of any other ADT data structures andtheir operations.
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