Starting Out with C++: Early Objects (9th Edition)
Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 18, Problem 3PC
Program Plan Intro

Static Queue Template

Program Plan:

Main.cpp:

  • Include required header files.
  • Inside “main ()” function,
    • Declare a constant variable
    • Declare a template
    • Manipulate and insert elements into the queue using “enqueue ()” function.
    • Delete the queue elements using “dequeue ()” function.

Queue.h:

  • Include required header files.
  • Create template class
  • Declare a class named “Queue”. Inside the class,
    • Inside the “private” access specifier,
      • Create an object for the template
      • Declare required variables.
    • Inside “public” access specifier,
      • Declare constructor and destructor.
      • Declare the functions “enqueue ()”, “dequeue ()”, “isEmpty ()”, “isFull ()”, and “clear ()”.
  • Declare template class.
  • Give definition for the constructor.
    • Allocate memory dynamically for the template.
    • Assign the values.
  • Declare template class.
  • Give definition for the destructor.
    • Delete queue array and make it as null.
  • Declare template class.
  • Give function definition for “enqueue ()”.
    • Check whether the queue is full using “isFull ()” function.
      • If the condition is true then, print “The queue is full”.
      • If the condition is not true then,
        • Calculate the “rear” position.
        • Assign “num” to the “queue_Array [rear]”.
        • Increment the variable “numItems”.
  • Declare template class.
  • Give function definition for “dequeue ()”.
    • Check if the queue is empty using “isEmpty ()” function.
      • If the condition is true then print “The queue is empty”.
      • If the condition is not true then,
        • Calculate “front” position.
        • Assign the value of “queue_Array [front]” to the variable “num”.
        • Decrement the variable “numItems”.
  • Declare template class.
  • Give function definition for “isEmpty ()”.
    • Assign “true” to a Boolean variable
    • Check if “numItems” is true.
      • If the condition is true then assign “false” to the variable.
    • Return the Boolean variable.
  • Declare template class.
  • Give function definition for “isFull ()”.
    • Assign “true” to a Boolean variable
    • Check if “numItems” is less than “size”
      • If the condition is true then assign “false” to the variable.
    • Return the Boolean variable.
  • Declare template class.
  • Give function definition for “clear ()”.
    • Decrement queue size and assign it to “front”.
    • Decrement queue size and assign it to “rear”.
    • Assign 0 to the variable “numItems”.

Blurred answer
Students have asked these similar questions
X1222: Double Ended Queue: Deque A double ended queue, known as deque, is a queue data structure that allows adding and removing elements from both ends of the queue. Instead of enqueue and dequeue, it has insert, delete, and get for both front and last of the queue as shown below. The data stored internally is stored in a ListNodesPlus object. The basic class definition is shown below: public class Deque { private ListNodePlus elements; // code ommitted for space public void clear() {...}; public int numElements () {...}; public boolean isEmpty() {...}; ● // Implement the following four methods public void insertFront (E it) { } public E deleteFront () { } public void insertLast (E it) { } public E deleteLast() { } Write the following four methods: • insertFront (E it) takes it and adds it to the front of the queue. stored internally in elements. The front of the queue is defined as position 0 in the queue. ● deleteFront () removes the element at the front of the queue and returns it.…
Java Programming Define a class CollectionBooks. This class has a data member list of type Book using the ArrayList collection. Define method add. This method add the any object to list. Define printAll. This method display all the added object in the list. Define printAll. This method display all the added object in the list. · Define int count. This method returns the number of objects added in the list. Define Book search(Object e). This method returns the object being search if not found return null. Define void remove(int index). This method remove the object in a list Add a main method with the following menu:1 – Add 2 – Count 3 – Print4 – Search 5 – Delete 6 - Exit
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
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education