//Datastructure

//Airport Simulation

 

#include<iostream.h>

#include<stdlib.h>

 

const QMAX=10;

struct Queue{

            int item[10];

            int front,rear,counter;

};

            void enqueue(Queue &portqueue,int id){

                        portqueue.item[portqueue.rear]=id;

                        portqueue.rear++;

                        portqueue.counter++;}

 

            char dequeue(Queue &portqueue){

                        int item;

                        portqueue.counter--;

                        item=portqueue.item[portqueue.front];

                        portqueue.front++;

                        return item;}

 

            bool isempty(Queue portqueue){

                        if(portqueue.counter==0) return 1;

                        else return 0;}

 

            bool isfull(Queue portqueue){

                        if(portqueue.counter==QMAX) return 1;

                        else return 0;}

 

            void main(){

                        Queue arrqueue,depqueue;

                        int option;

                        int item,x;

 

                        arrqueue.front=arrqueue.rear=arrqueue.counter=0;

                        depqueue.front=depqueue.rear=depqueue.counter=0;

 

                        cout<<"RUNNING THE AIRPORT SIMULATION"<<endl<<endl;

 

                        while(1){

 

                                    option=1+rand()%4;

 

                                    switch(option){

 

                                    case 1: if(!isfull(arrqueue)){cout<<"ENTER ARRIVING FLIGHT TO QUEUE: ";

                                                                                                                                    cin>>item; enqueue(arrqueue,item);}//IF

                                                else cout<<"ARRIVAL QUEUE IS FULL"<<endl;

                                                break;

 

                                    case 2: if(!isempty(arrqueue)){x=dequeue(arrqueue);

                                                cout<<"ARRIVING FLIGHT IS: "<<x<<endl;}//IF

                                                else cout<<"ARRIVAL QUEUE IS EMPTY "<<endl;

                                                break;

 

                                    case 3:if(!isfull(depqueue)){cout<<"ENTER DEPARTING FLIGHT TO QUEUE: ";

                                                cin>>item;enqueue(depqueue,item);}//IF

                                                else cout<<"DEPARTING QUEUE IS FULL"<<endl;

                                                break;

 

                                    case 4:if(!isempty(depqueue)){x=dequeue(depqueue);

                                                cout<<"DEPARTING FLIGHT IS:"<<x<<endl;}//IF

                                                else cout<<"DEPARTING QUEUE IS EMPTY"<<endl;

                                                break; }

 

                                    if((arrqueue.counter==QMAX)&&(depqueue.counter==QMAX)){

                                                            cout<<"TERMINATING SIMULATION"<<endl;

                                                            break;}

                        }

            }

 

 

RUNNING THE AIRPORT SIMULATION

 

ARRIVAL QUEUE IS EMPTY

DEPARTING QUEUE IS EMPTY

ENTER DEPARTING FLIGHT TO QUEUE: 7

ENTER ARRIVING FLIGHT TO QUEUE: 8

ARRIVING FLIGHT IS: 8

ENTER ARRIVING FLIGHT TO QUEUE: 9

ENTER DEPARTING FLIGHT TO QUEUE: 1

ENTER DEPARTING FLIGHT TO QUEUE: 2

ENTER DEPARTING FLIGHT TO QUEUE: 3

ENTER ARRIVING FLIGHT TO QUEUE: 4

ARRIVING FLIGHT IS: 9

ARRIVING FLIGHT IS: 4

ARRIVAL QUEUE IS EMPTY

DEPARTING FLIGHT IS:7

ARRIVAL QUEUE IS EMPTY

DEPARTING FLIGHT IS:1

DEPARTING FLIGHT IS:2

ENTER DEPARTING FLIGHT TO QUEUE:

1