Starting Out with C++ from Control Structures through Objects Brief, Student Value Edition (8th Edition)
bartleby

Concept explainers

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

Dynamic 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.

Dynqueue.h:

  • Include required header files.
  • Create template class
  • Declare a class named “Dynqueue”. Inside the class,
    • Inside the “private” access specifier,
      • Create a structure named “QueueNode”.
        • Create an object for the template
        • Create a pointer named “next”.
      • Create two pointers named “front” and “rear”.
      • Declare a variable.
    • 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.
    • Assign the values.
  • Declare template class.
  • Give definition for the destructor.
    • Call the function “clear ()”.
  • Declare template class.
  • Give function definition for “enqueue ()”.
    • Make the pointer “newNode” as null.
    • Assign “num” to newNode->value.
    • Make newNode->next as null.
    • Check whether the queue is empty using “isEmpty ()” function.
      • If the condition is true then, assign newNode to “front” and “rear”.
      • If the condition is not true then,
        • Assign newNode to rear->next
        • Assign newNode to “rear”.
      • Increment the variable “numItems”.
  • Declare template class.
  • Give function definition for “dequeue ()”.
    • Assign temp pointer as null.
    • 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,
        • Assign the value of front to the variable “num”.
        • Make front->next as “temp”.
        • Delete the front value
        • Make temp as front.
        • 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 “clear ()”.
    • Create an object for template.
      • Dequeue values from queue till the queue becomes empty using “while” condition.

Blurred answer
Students have asked these similar questions
Add the operation queueCount to the class Queue, which returns the number of elements in thequeue. Write the definition of the function template to implement this operation. Note: Code in C++
Answer the following by True or False: NOTE: When the question has been underlined, it requires two (2) answers. The ADT makes use of static array for its queue implementation. The class includes a constructor and destructor. A value must be provided when you initiate a dequeue operation.
True or False? ___________ The ADT makes use of static array for its queue implementation. ___________     ___________ The class includes a constructor and destructor. ___________ A value must be provided when you initiate a dequeue operation.

Chapter 18 Solutions

Starting Out with C++ from Control Structures through Objects Brief, Student Value Edition (8th Edition)

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