/* 8. Write a C++ program to create a template class QUEUE, with add and delete member functions. Using it, implement a queue of integers and doubles. Demonstrate the implementation by displaying the status and content of the queue after every operation. */


#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
const int max=5;
template <class T>
class QUEUE 
{
    T a[max];
    int front,rear;

    public:
        QUEUE()
        {
            front = -1;
            rear = -1;
        }
        void Qinsert();
        void Qdelete();
        void Qdisplay();
};
template <class T>
void QUEUE<T>::Qinsert()
{
    if (rear >= (max-1))
        cout<<"\n\nError : Overflow";
    else
    {
        T item;
        cout<<"\nEnter the item to be inserted : ";
        cin>>item;
        a[++rear] = item;
    }
}
template <class T>
void QUEUE<T>::Qdelete()
{
    if (front >= rear)
        cout<<"\nError : Underflow";
    else
    {
        cout<<"\nDeleted item is "<<a[++front];
        if (front == rear)
            front = rear = -1;
    }
}
template <class T>
void QUEUE<T>::Qdisplay()
{
    if (front == rear)
        cout<<"\nError : Q empty";
    else
    {
        cout<<"\nQueue contents is as follows :\n";
        for (int i=front+1; i<=rear; i++)
            cout<<a[i]<<'\t';
    }
}
void main()
{
    int ch;
    QUEUE<double> q1;
    clrscr();
    while(1)
    {
        cout<<"\nMENU\n1. Insert\n2. Delete\n3. Display\n4. Exit\nYour Choice = ? ";
        cin>>ch;
        switch(ch)
        {
            case 1:
                q1.Qinsert();
                break;

            case 2:
                q1.Qdelete();
                break;

            case 3:
                q1.Qdisplay();
                break;

            case 4:
                exit(0);

            default:
                cout<<"\nInvalid Entry. Please Try Again";
        }
    }
    getch();
}