Starting Out with C++: Early Objects
Starting Out with C++: Early Objects
8th Edition
ISBN: 9780133360929
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: Addison-Wesley
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…
C++ ProgrammingActivity: Queue Linked List Explain the flow of the code not necessarily every line, as long as you explain what the important parts of the code do. The code is already correct, just explain the flow.   #include "queue.h" #include "linkedlist.h" class SLLQueue : public Queue {     LinkedList* list;      public:     SLLQueue() {             list = new LinkedList();     }     void enqueue(int e) {         list->addTail(e);         return;     }     int dequeue() {         int elem;         elem = list->removeHead();         return elem;     }     int first() {         int elem;         elem = list->get(1);         return elem;;     }     int size() {         return list->size();     }     bool isEmpty() {         return list->isEmpty();     }     int collect(int max) {         int sum = 0;         while(first() != 0) {             if(sum + first() <= max) {                 sum += first();                 dequeue();             } else {…
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