using namespace std;
class ticketqueue{
private:
//Data Members
int q[5];
int front, rear, noe; //noe..to store number of elements
public:
//Member Functions
ticketqueue(){ noe = rear = front = 0;} //Constructor
void enqueue(int);
void ticketchecker();
void print();
int isempty();
void queuebuilder();
void menu();
};
void ticketqueue :: enqueue(int a)
{
q[rear] = a;
rear++;
noe++;
if (rear == 5)
rear = 0;
cout<">"><>
void ticketqueue :: ticketchecker()
{
clrscr();
int not,rt;
if ( !isempty() )
{
not = q[front];
if (not > 2)
{
rt= not - 2;
if ( rt > 0 )
{
enqueue(rt);
front++;
cout<">"><><"# tickets="" were="" demanded.="" 2="" tickets="" are="">"#><"enqueued again="" for="" next="" go="" to="" get="" remaining="">"enqueued><>
else if ( rt <= 0="">=>
front++;
noe--;
}
else if ( not <= 2="">=>
{
front++;
noe--;
cout<">"><"# tickets="" are="">"#><>
}
}
else
cout<"!!! no="" request="" in="" the="" queue="" "="">"!!!><>
getch();
clrscr();
menu();
}
void ticketqueue :: print()
{
clrscr();
int i = front;
if ( noe > 0 )
{
cout<"requests enqueued="" are="" :"="">"requests>
do
{
cout<>
if ( i == 5 )
i = 0;
}
while ( i != rear );
}
else
cout<"no request="" in="" queue...queue="" is="" empty="">"no>
getch();
clrscr();
menu();
}
//Utility Fuction
int ticketqueue :: isempty()
{
if ( noe == 0 )
return 1;
else
return 0;
}
//This Function takes input from the user and shows Queue graphically
void ticketqueue::queuebuilder(){
clrscr();
int tickets, z = 0, i = 0, x = 20, y = 10, g = 1, h = 17;
char c;
cout<"enter number="" of="" tickets="" to="" purchase...="">"enter><>
while (!(c == 'E' || c == 'e'))
{
if ( z > 4)
{
clrscr();
cout<" error!!!="" queue="" size="" violation...exiting="" now="">"><>
getch();
clrscr();
menu();
}
else
{
cout<"enter :="">"enter>
cin>>tickets;
enqueue(tickets);
z++;
gotoxy(17,10);
cout<"->";
gotoxy(20,9);
cout<>
gotoxy(x,y);
cout<>
gotoxy(20,11);
cout<>
gotoxy(g,h);
cout<"press c/c="" to="" continue="" e/e="" to="" end:="">"press>
cin>>c;
h += 6;
i++;
}
}
getch();
clrscr();
menu();
}
void ticketqueue::menu()
{
int b;
gotoxy(15,5);
cout<"press 1................enter="" no="" of="">"press>
gotoxy(15,8);
cout<"press 2................ticket="">"press>
gotoxy(15,11);
cout<"press 3................all="" ticket="">"press>
gotoxy(15,15);
cout<"press>"press>
gotoxy(15,18);
cout<"now enter="" :="">"now>
cin>>b;
if ( b == 1 )
queuebuilder();
else if ( b == 2 )
ticketchecker();
else if ( b == 3 )
print();
else if ( b == 4 )
exit(1);
}
void main()
{
clrscr();
ticketqueue t;
t.menu();
getch();
}
"->