Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony 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
Data Structure & Algorithum java program Do the following: 1) Add a constructor to the class "LList" that creates a list from a given array of objects.2) Add a method "addAll" to the "LList" class that adds an array of items to the end of the list. The header of the method is as follows, where "T" is the generic type of the objects in the list. 3) Write a Test/Driver program that thoroughly tests all the methods in the class "LList".
Explain the process of Linking with Static Libraries ?
c++ data structures ADT Unsorted List The specifications for the Unsorted List ADT states that the item to be deleted is in the list.   Rewrite the specifications for DeleteItem so that the list is unchanged if the item to be deleted is not in the list. Rewrite the specifications for DeleteItem so that all copies of the item to be deleted are removed if they exist

Chapter 19 Solutions

Starting Out with C++ from Control Structures to Objects (9th Edition)

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning