Starting Out With C++: Early Objects (10th Edition)
Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
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
C++ Question You need to write a class called LinkedList that implements the following List operations: public void add(int index, Object item); // adds an item to the list at the given index, that index may be at start, end or after or before the // specific element   2.public void remove(int index); // removes the item from the list that has the given index   3.public void remove(Object item); // finds the item from list and removes that item from the list   4.public List duplicate(); // creates a duplicate of the list // postcondition: returns a copy of the linked list   5.public List duplicateReversed(); // creates a duplicate of the list with the nodes in reverse order // postcondition: returns a copy of the linked list with the nodes in   6.public List ReverseDisplay(); //print list in reverse order   7.public Delete_Smallest(); // Delete smallest element from linked list   8.public List Delete_duplicate(); // Delete duplicate elements from a given linked list.Retain the…
C++ Question You need to write a class called LinkedList that implements the following List operations: public void add(int index, Object item); // adds an item to the list at the given index, that index may be at start, end or after or before the // specific element   2.public void remove(int index); // removes the item from the list that has the given index   3.public void remove(Object item); // finds the item from list and removes that item from the list   4.public List duplicate(); // creates a duplicate of the list // postcondition: returns a copy of the linked list   5.public List duplicateReversed(); // creates a duplicate of the list with the nodes in reverse order // postcondition: returns a copy of the linked list with the nodes in   6.public List ReverseDisplay(); //print list in reverse order   7.public Delete_Smallest(); // Delete smallest element from linked list   8.public List Delete_duplicate(); // Delete duplicate elements from a given linked list.Retain the…
Briefly describe the stack parameter.
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