Plane Simulation Code in c c ++ with Time


Advertisement



Plane  Simulation  implementation Code in  C c ++  programming language with Time

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
#include<stdlib.h>
#include<dos.h>

struct st
{
int id;
st * ptr;
};

class simulation
{
private:
st * rear_AQ,*front_AQ;
st * rear_TQ,*front_TQ;
int sim_Time;
float avg_AQ,avg_TQ;

public:

simulation()
{
rear_AQ=NULL;
front_AQ=NULL;
rear_TQ=NULL;
front_TQ=NULL;
cout<<"Enter the simulation Time"<<endl;
cin>>sim_Time;
cout<<"Enter the average waiting Time for Arrival planes"<<endl;
cin>>avg_AQ;
cout<<"Enter the average waiting Time for TakeOff planes"<<endl;
cin>>avg_TQ;



}


void insert ( )
{

      int arrival,take,j=1,k=1;
      st * newnode;
st * p,*q;
int flag=0;

      for (int i=0;i<sim_Time;i++)
      {
arrival=random(10);
take=random(10);


if(arrival<=avg_AQ)
{

cout<<"New Arrival Plane Enters in a Queue "<<endl;
newnode=new st;
newnode->id=k;
newnode->ptr=NULL;
k++ ;

     if(rear_AQ==NULL)
{
rear_AQ=newnode;
front_AQ=newnode;
}//case 1
else
{
rear_AQ->ptr=newnode;
rear_AQ=newnode;
}

}//arrivalqueue
if(take<=avg_TQ)
{

    cout<<"New Take Off Plane Enters in a Queue "<<endl;
     newnode=new st;
     newnode->id=j;
 newnode->ptr=NULL;
     j++;

     if(rear_TQ==NULL)
{
rear_TQ=newnode;
front_TQ=newnode;
}//case 1
else
{
rear_TQ->ptr=newnode;
rear_TQ=newnode;
}

}//takequeue

delay(500);

if(front_AQ!=NULL)
{
p=front_AQ;
cout<<"Plane #"<<front_AQ->id<< "arrival has been occured"<<endl;
front_AQ=front_AQ->ptr;
delete p;
if(front_AQ==NULL)
rear_AQ=NULL;

}
   else
{
if((front_TQ!=NULL)&&(front_AQ==NULL))
{
cout<<"Run Way is empty Now"<<endl;
p=front_TQ;
cout<<"Plane #"<<front_TQ->id<< "Take off has been occured"<<endl;
front_TQ=front_TQ->ptr;
delete p;
if(front_TQ==NULL)
rear_TQ=NULL;
}
}//for take off
delay(500);

  }//for loop

while(front_AQ!=NULL)
{  
p=front_AQ;
cout<<"Plane #"<<front_AQ->id<< "arrival has been occured"<<endl;
front_AQ=front_AQ->ptr;
delete p;
   delay(1000);
}
      if(front_AQ==NULL)
{
rear_AQ=NULL;
cout<<"Run way is Empty "<<endl;
while(front_TQ!=NULL)
{      
p=front_TQ;
cout<<"Plane #"<<front_TQ->id<< "Take off has been occured"<<endl;
front_TQ=front_TQ->ptr;
delete p;
delay(1000);
}
rear_TQ=NULL;

} //end of if


}
};
void main()
{
 ` clrscr();
simulation l;
l.insert();
getche();
}

Advertisement






0

Post a Comment

Author :
Maria Ali
Lectures
Educations
Questions

ShareThis

 

Recent Posts

RESULT

Result

Return to top of page Copyright © 2010 | Flash News Converted into Blogger Template by HackTutors