/* Implement circular queue using array and perform following operations on it.
i) Add a record ii) Delete a record iii) Checking Empty
 iv) Checking Underflow v) Checking Overflow */

#include<stdlib.h>
#include<iostream>
#include<string.h>
#define MAX 30
using namespace std;

class student
{
  public:
char Name[20];
int roll_no;
};

class queue
{

student Q[MAX];
int front,rear;
 public:
queue()
{
front=0;
rear=-1;
}
int is_full();
int is_empty();
void insert(student);
student remove();
};

int queue::is_empty()
{
if(rear==-1)
return 1;
return 0;
}

int queue::is_full()
{
if(rear!=-1 && front==(rear+1)%MAX)
return 1;
return 0;
}

void queue::insert(student data)
{
rear=(rear+1)%MAX;
Q[rear]=data;
}

student queue::remove()
{
student val;
val=Q[front];
front=(front+1)%MAX;
if(front==(rear+1)%MAX)
{
front=0;
rear=-1;
}
return val;
}

int main()
{
int ch;
student Q1;
queue q;
do
{
cout<<"\nEnter \n1)Insert Record \n2)Remove Record \n3)Check Underflow \n4)Check Overflow, \n5)Exit:";
cin>>ch;
switch(ch)
{
case 1:
if(!q.is_full())
{
cout<<"\nEnter Name of Student:";
cin>>Q1.Name;
cout<<"\nEnter its Roll No:";
cin>>Q1.roll_no;
q.insert(Q1);
}
else
cout<<"\nCannot insert.Queue is Full.";
break;
case 2:
if(!q.is_empty())
{
Q1=q.remove();
cout<<"\nName of Student : "<<Q1.Name;
cout<<"\nIts Roll No is : "<<Q1.roll_no;
}
else
cout<<"\nCannot remove.Queue is Empty.";
break;
case 3:
if(q.is_empty())
cout<<"\nQueue is Empty.";
else
cout<<"\nQueue is not Empty.";
break;
case 4:
if(q.is_full())
cout<<"\nQueue is Full.";
else
cout<<"\nQueue is not Full.";
break;
case 5:
break;
   default:
cout<<"\nWrong entry.Please try again.";
}
}while(ch!=5);
return 0;
}

//END OF PROGRAM