This is the code.
I'm having problem in comparing the Now and arrival time(atime) of plane.
To get the result the number of plane on the air.
urgent.this code have to pass up on tuesday.
thanks!
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main()
{
int A[2]={1,2};
int A_Status[1];
int G[3]={60,90,120};
int G_Status[2];
int L[4]={45,60,75,90};
int L_Status[3];
int *airplanes = NULL;
int size;
string flight_no[12];
string dest[20];
int atime[10];
int ltime,Atime,Dtime;
int a,i;
int air;
int ground;
int choose;
int min;
int Now;
do
{
cout<<endl<<endl<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"| WELCOME TO OUR PROGRAM |"<<endl;
cout<<"| Airport Menu Options |"<<endl;
cout<<"| 1 = Enter Flight Information |" <<endl;
cout<<"| 2 = Display Flight initial Information |"<<endl;
cout<<"| 3 = Display Runway and Information |"<<endl;
cout<<"| 0 = quit |" <<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<endl;
cout<<"Please key in your choose"<<endl;
cin>>choose;
cout<<endl;
system("pause");
cout<<endl<<endl<<endl;
if(choose==1)
{
cout<<"__________________________________________________________________________________"<<endl;
cout<<endl<<" ^^Condition^^"<<endl;
cout<<endl<<" ~~ Please key in the plane order by accending of their time ~~"<<endl;
cout<<endl<<" ~~ Please insert more than one plane ~~"<<endl;
cout<<"__________________________________________________________________________________"<<endl;
cout<<endl<<endl;
do{
cout <<endl<<"How many Flight Information you would like to key in : "<<endl;
cin >> size;
}while (size<2);
airplanes = new int[size];
for(a = 0; a < size; a++)
{
cout <<endl<<"Enter Flight information for plane No." << a+1 <<"= "<<endl;
cout <<endl;
cout <<"Flight Number ";
cin >>flight_no[a];
cout <<"Destination ";
cin >>dest[a];
do
{
cout <<"Arrival Time(in 24 Hours Mode) ~~example(0000=12am)~~ =";
cin >>atime[a];
}while(atime[a]<0000 || atime[a] >2400);
}
}
if(choose==2)
{
cout <<" " <<left;
cout<<"** Now display information data you key in **"<<endl<<endl;
cout << setw(15) <<" Flight Number | "<<setw(13) <<"Destination | " <<setw(16) <<"Arrival Time" <<endl;
cout <<endl;
for(int b = 0; b < size; b++)
{
cout <<left;
cout <<" "<<setw(13) <<flight_no[b] <<" " <<setw(16) <<dest[b]<<atime[b];
cout <<endl;
}
cout<<endl;
}
if(choose==3)
{
cout<<" **Display Runway and Information...**"<<endl;
cout<<"Total plane you key in := "<<size<<endl<<endl;
min=atime[0];
int runway=0;
cout<<"_________________________________________________________________________"<<endl;
cout<<endl<<" Information Arrive:-"<<endl;
cout<<" Runway := "<<runway<<endl;
cout<<" Plane "<<flight_no[0]<<endl;
cout<<" Now = "<<min<<endl;
cout<<"_________________________________________________________________________"<<endl;
runway=+1;
for(i=1; i<size; i++)
{
if ((atime[i]==min)&&runway==1)
{
cout<<"_________________________________________________________________________"<<endl;
cout<<endl<<" Information for another plane....."<<endl;
cout<<" Plane "<<flight_no[i]<<endl;
cout<<" Run way full already......!"<<endl;
cout<<" Please wait for plane"<<flight_no[i-1]<<"landed.....!"<<endl;
cout<<" Status Ranway := "<<runway<<endl;
cout<<" Now = "<<atime[i]<<endl;
cout<<"_________________________________________________________________________"<<endl;
}
else{
cout<<"_________________________________________________________________________"<<endl;
cout<<" No others Plane Now"<<endl;
cout<<"_________________________________________________________________________"<<endl;
}
}
Now=min;
for(i=0;i<size;i++)
{
if(atime[i]==Now)
air=1+i++;
}
ground=0;
cout<<endl;
cout<<"Total Number plane on the air is := "<<air<<endl;
cout<<"Total Number plane on the ground is := "<<ground<<endl<<endl;;
int pos=(rand()%2)/60;
A_Status[i]=A[pos];
int A=A_Status[i];
Atime=min+A;
int Now = min;
cout<<"_________________________________________________________________________"<<endl;
cout<<endl<<" Information Arrive in airport:-"<<endl;
cout<<" Plane "<<flight_no[0]<<endl;
cout<<" Now= "<<Atime<<endl;
cout<<"_________________________________________________________________________"<<endl<<endl;
for(i=0;i<size;i++)
{
if(atime[i]==Now)
air=1+i++;
}
cout<<"Total Number plane in the air is := "<<air<<endl;
cout<<"Total Number plane in the ground is := "<<ground<<endl<<endl;
int pos1=(rand()%4)/60;
L_Status[i]=L[pos1];
int L=L_Status[i];
ltime=Atime+L;
Now=ltime;
cout<<"_________________________________________________________________________"<<endl;
cout<<endl<<" Information landing in airport:-"<<endl;
cout<<" Plane "<<flight_no[0]<<endl;
cout<<" Now= "<<ltime<<endl;
cout<<" Status Runway := "<<runway<<endl;
cout<<"_________________________________________________________________________"<<endl<<endl;
for(i=0;i<size;i++)
{
if(atime[i]==Now)
air=1+i++;
}
air=air-1;
ground=1;
cout<<"Total plane on the air:= "<<air<<endl;
cout<<"Total plane on the ground:= "<<ground<<endl<<endl;
int pos2=(rand()%3)/60;
G_Status[i]=G[pos2];
int G=G_Status[i];
Dtime=ltime+G;
Now=Dtime;
cout<<"_________________________________________________________________________"<<endl;
cout<<endl<<" Information depart in airport:-"<<endl;
cout<<" Plane "<<flight_no[0]<<endl;
cout<<" Now= "<<Dtime<<endl;
cout<<" Status Runway := "<<runway<<endl;
cout<<"_________________________________________________________________________"<<endl<<endl;
for(i=1;i<size;i++)
{
if(atime[i]==Now)
{
air=i+1;
}
else{
air=i;
}
}
ground=0;
cout<<"Total plane on the air:= "<<air<<endl;
cout<<"Total plane on the ground =: "<<ground<<endl;
runway=0;
for(i=1; i<size; i++)
{
if ((atime[i]<=Now)&&runway==0)
{
Now=Dtime;
cout<<"_________________________________________________________________________"<<endl<<endl;
cout<<endl<<" Information prepare landing in airport:-"<<endl;
cout<<" Plane "<<flight_no[i]<<endl;
cout<<" Now= "<<Now<<endl;
cout<<"_________________________________________________________________________"<<endl<<endl;
for(i=1;i<size;i++)
{
if(atime[i]==Now)
{
air=i+1;
}
else{
air=i;
}
}
cout<<"Total plane in the air:= "<<air<<endl;
cout<<"Total plane in the ground: "<<ground<<endl;
ltime=Now+L;
Now=ltime;
runway=1;
cout<<"_________________________________________________________________________"<<endl<<endl;
cout<<endl<<" Information landing in airport:-"<<endl;
cout<<" Plane "<<flight_no[i]<<endl;
cout<<" Now= "<<Now<<endl;
cout<<" Status Runway := "<<runway<<endl;
cout<<"_________________________________________________________________________"<<endl<<endl;
ground=1;
air=air-1;
for(i=1;i<size;i++)
{
if(atime[i]==Now)
{
air=i+1;
}
else{
air=i;
}
}
cout<<"Total plane on the air:= "<<air<<endl;
cout<<"Total plane on the ground:= "<<ground<<endl;
Dtime=ltime+G;
Now=Dtime;
runway=0;
cout<<"_________________________________________________________________________"<<endl<<endl;
cout<<endl<<" Information depart in airport:-"<<endl;
cout<<" Plane "<<flight_no[i]<<endl;
cout<<" Now= "<<Now<<endl;
cout<<" Status Runway := "<<runway<<endl;
cout<<"_________________________________________________________________________"<<endl<<endl;
}
for(i=1;i<size;i++)
{
if(atime[i]==Now)
{
air=i+1;
}
else{
air=i;
}
}
ground=0;
cout<<"Total plane on the air:= "<<air<<endl;
cout<<"Total plane on the ground:= "<<ground<<endl;
runway=0;
if ((atime[i]>=Now)&&runway==0)
{
Now=atime[i];
cout<<"_________________________________________________________________________"<<endl<<endl;
cout<<endl<<" Information prepare landing in airport:-"<<endl;
cout<<" Plane "<<flight_no[i]<<endl;
cout<<" Now= "<<Now<<endl;
cout<<"_________________________________________________________________________"<<endl<<endl;
for(i=1;i<size;i++)
{
if(atime[i]==Now)
{
air=i+1;
}
else{
air=i;
}
}
cout<<"Total plane in the air:= "<<air<<endl;
cout<<"Total plane in the ground: "<<ground<<endl;
ltime=Now+L;
Now=ltime;
runway=+1;
cout<<"_________________________________________________________________________"<<endl<<endl;
cout<<endl<<" Information landing in airport:-"<<endl;
cout<<" Plane "<<flight_no[i]<<endl;
cout<<" Now= "<<Now<<endl;
cout<<" Status Runway := "<<runway<<endl;
cout<<"_________________________________________________________________________"<<endl<<endl;
for(i=1;i<size;i++)
{
if(atime[i]==Now)
{
air=i+1;
}
else{
air=i;
}
}
ground=1;
air=air-1;
cout<<"Total plane in the air:= "<<air<<endl;
cout<<"Total plane in the ground: "<<ground<<endl;
Dtime=ltime+G;
Now=Dtime;
runway=0;
cout<<"_________________________________________________________________________"<<endl<<endl;
cout<<endl<<" Information depart in airport:-"<<endl;
cout<<" Plane "<<flight_no[i]<<endl;
cout<<" Now= "<<Now<<endl;
cout<<" Status Runway := "<<runway<<endl;
cout<<"_________________________________________________________________________"<<endl<<endl;
for(i=1;i<size;i++)
{
if(atime[i]==Now)
{
air=i+1;
}
else{
air=i;
}
}
ground=0;
cout<<"Total plane in the air:= "<<air<<endl;
cout<<"Total plane in the ground: "<<ground<<endl;
runway=0;
}
}
int Total=Dtime-atime[0];
cout<<endl;
cout<<"Total time for simulation for "<<size<<" is = "<<Total<<endl;
}
system("pause");
}while (choose!=0);
delete []airplanes;
return 0;
}