Question: You will create a program using the concept of Circular queue where the items stored are characters. The maximum size of the circular queue is
You will create a program using the concept of Circular queue where the items stored are characters. The maximum size of the circular queue is 5. (QUEUE_CAPACITY = 5))
Program will have a menu with three options: (Display of Menu: 1 points)
-----------Menu-------------
1. Enter Character
2. Display all items
3. Exit
| Option 1: Enter Character | This option is used to enter a character. If the character is a consonant then insert (enqueue) that character in the circular queue. If the character is a vowel then delete (dequeue) the front item of the queue. |
| Option 2: Display all items | This option will display all the items in the circular queue. |
| Option 3: Exit | This option exits the application |
Tip:
If the character is consonant, then insert it in the queue; otherwise, delete the front item of the queue.
if ((item == 'A') || (item == 'E') || (item == 'I') || (item == 'O') || (item == 'U'))
{ item = q.dequeue();
cout << "Item deleted ---> " << item << endl;
}
else
q.enqueue(item);
Given is the list of characters to be processed from left to right.
Sample numbers: R, C, G, C, A, E, C, N, J
(Explanation: when the characters are R, C, G, C; you insert each of these characters in queue. When the character is A (consonant) then dont insert that in the queue rather you delete the front item R and this process continues)
Basic operations to be used. (Use of these functions: 3 points)
1. queue - Queue constructor. An empty queue object is constructed.
2. enqueue - Add an item at the back of the queue
3. dequeue - Remove the item from the front of the queue
4. display - Display items in the queue
5. empty - Checks if the queue is empty
Use the following object definition: (Use of this object definition: 2 points)
#include
#ifndef QUEUE
#define QUEUE
const int QUEUE_CAPACITY = 5;
typedef char QueueElement;
//-----Queue class
class queue
{
//---Data members
private:
int myFront, myBack;
QueueElement myArray[QUEUE_CAPACITY];
//---Function members
public:
queue(); //----Constructor
void enqueue(QueueElement); //----Add item
QueueElement dequeue(); //----Remove item
bool empty() const; //----check for empty
void display();
}; // End of class declaration
#endif }; // End of class declaration
DISPLAY: (Display of output: 4 points)
When a character (consonant) is inserted, it will display the character and the message "Inserted".
(Ex: R ---- Inserted)
When a character is deleted from the front of the queue, it will display the character and the message "Deleted".
(Ex: R ---- Deleted)
If a character could not be inserted due to queue is full, it will display the message
"Circular Queue is Full".
If a situation arises that tries to delete an empty queue, it will display the message "Queue is Empty - No deletion possible".
Finally, you will display the front item of the queue, back item in the queue and the items in the queue.
Sample Output:
Sample items entered R, C, G, C, A, E, C, N, and J
R ---- Inserted
C ---- Inserted
G ---- Inserted
C ---- Inserted
R ---- Deleted
C ---- Deleted
N ---- Inserted
Could not be inserted - queue is full
All items: G C C N
Front item in queue: G
Back item in queue: N
Sample Test Run
-----------Menu-------------
1. Insertion
2. Display all items
3. Exit
Enter Your choice <1..3> ?2
No items in the queue
Enter Your choice <1..3> ?1
Enter item: R
Item inserted ---> R
Enter Your choice <1..3> ?1
Enter item: C
Item inserted ---> C
Enter Your choice <1..3> ?2
All items: R C
Front item in queue: R
Back item in queue: C
Enter Your choice <1..3> ?1
Enter item: G
Item inserted ---> G
Enter Your choice <1..3> ?1
Enter item: C
Item inserted ---> C
Enter Your choice <1..3> ?2
All items: R C G C
Front item in queue: R
Back item in queue: C
Enter Your choice <1..3> ?1
Enter item: A
Item deleted ---> R
Enter Your choice <1..3> ?2
All items: C G C
Front item in queue: C
Back item in queue: C
Enter Your choice <1..3> ?1
Enter item: E
Item deleted ---> C
Enter Your choice <1..3> ?2
All items: G C
Front item in queue: G
Back item in queue: C
Enter Your choice <1..3> ?1
Enter item: C
Item inserted ---> C
Enter Your choice <1..3> ?1
Enter item: N
Item inserted ---> N
Enter Your choice <1..3> ?2
All items: G C C N
Front item in queue: G
Back item in queue: N
Enter Your choice <1..3> ?1
Enter item: J
Circular Queue is Full
Enter Your choice <1..3> ? 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
