Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
9th Edition
ISBN: 9780134379319
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
Question
Book Icon
Chapter 18, 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)?
3.Write a generic class called GenericStack<T> that represents a stack structure. A stack structure follow the strategy last-in-first-out, which means that the last element added to the stack, is the first to be taken out. The GenericStack class has the following attributes and methods: --An attribute ArrayList<T> elements which represents the elements of the stack.(All of you refer collection framework for ArrayList. or you can use an array to hold the elements of Stack.)[Refer the following links to have intro on ArrayList: https://www.w3schools.com/java/java_arraylist.asp, https://www.geeksforgeeks.org/arraylist-in-java/] --A constructor that creates the ArrayList or an Array --A method push(T e) which adds the element to the ArrayList<T> or array. --A method pop() which removes the last element of the ArrayList<T> (last element added), if the list is not already empty and returns it. --A method print() which prints the elements of the stack starting from the…
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