Write a C++ program to simulate the working of queues using an array

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question
Write a C++ program to simulate the working of queues using an array provide the following operation:

 

i) Insert ii) Delete iii) Display

Assume that the size of the queue is 5.


Define the following functions in the class Queue

  •     enqueue ( )  --- to add value to queue
  •     display ( )  --- Display the values in list
  •     dequeue ( ) --- to delete the value from the queue ​​​​​​


Note:

  • While inserting the element to the queue if the Queue is full then print "Queue Overflow" in the main method.
  • While deleting the element from the queue if the Queue is empty then print "Queue Underflow"  in the dequeue ( ) method.
  • While displaying the elements from the queue if the Queue is empty then print "Queue is empty" in the display( ) method.


Input and Output Format:

Refer sample input and output for formatting specifications.

[All text in bold corresponds to input and the rest corresponds to output]

Sample Input and Output 1 :

1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
1
Enter the element to be inserted :
6
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
1
Enter the element to be inserted :
8
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
1
Enter the element to be inserted :
2
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
1
Enter the element to be inserted :
6
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
1
Enter the element to be inserted :
9
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
1
Queue Overflow
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
3
Elements in the Queue :
6 8 2 6 9 
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
4

 

Sample Input and Output 2 :
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
1
Enter the element to be inserted :
4
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
1
Enter the element to be inserted :
17
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
1
Enter the element to be inserted :
18
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
3
Elements in the Queue :
4 17 18
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
2
Element deleted from queue is : 4
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
3
Elements in the Queue :
17 18
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
2
Element deleted from queue is : 17
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
3
Elements in the Queue :
18
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
2
Element deleted from queue is : 18
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
3
Queue is empty
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
2
Queue Underflow
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice :
4

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning