program flight_control;
uses crt;
type
flighttype = record
number: string[8];
line: string;
gate: char;
runway: integer
end;
var
plane: array[1..50] of flighttype;
num,ans: integer;
ans_strg: string;
code_main: integer;
procedure departure(var count: integer);
var
flight: string[8];
airline: string;
a,b,c,d,code :integer;
check: boolean;
e,f,ans: char;
begin
count:=0;
repeat
repeat
check:= false;
write('Please enter the flight in capital letter.(With space bar between characters and numbers): ');
readln(flight);
a:= ord(flight[1]);
b:= ord(flight[2]);
c:= ord(flight[3]);
val(copy(flight,4,4),d,code);
if ((a>=65) and (a<=90)) and ((b>=65) and (b<=90)) and (c=32) and (code=0) and (length(flight)>=6) and (length(flight)<=7)
then check:= true;
if check= false
then writeln('Please enter again.')
until check= true;
write('Please enter the airline: ');
readln(airline);
count:= count+1;
with plane[count] do
begin
number:= flight;
line:= airline;
gate:=' '
end;
repeat
write('Input another flight?(Y/N): ');
readln(ans)
until ans in['y', 'Y', 'n', 'N']
until ans in ['N', 'n']
end;
procedure arrival(var counter_arr: integer);
var
time,{x,y,}t,r: integer;
z: string[8];
begin
randomize;
t:= 0;
writeln('Please wait for a moment.');
repeat
r:= random(5)+1;
t:= t+1;
counter_arr:= counter_arr+1;
time:=2;
while time>=0 do
begin
time:= time-1;
delay(1000)
end;
z:='';
{for x:= 1 to 2 do
z:= z+chr(random(26)+65);
z:= z+' ';
for y:= 1 to (random(2)+3) do
z:= z+chr(random(10)+48);}
z:=z+chr(random(26)+65)+chr(random(26)+65)+' '+chr(random(10)+48)+chr(random(10)+48)+chr(random(10)+48);
with plane[counter_arr] do
begin
number:= z;
case r of
1: line:= 'AA Pacific Company';
2: line:= 'BB Pacific Company';
3: line:= 'CC Pacific Company';
4: line:= 'DD Pacific Company';
5: line:= 'EE Pacific Company'
end
end
until t= random(3)+3
end;
procedure display(counter: integer);
var
p: integer;
begin
p:=0;
writeln;
writeln('Number ','Flight ','Airline');
writeln;
repeat
p:= p+1;
with plane[p] do
writeln(p:3,' ',number:10,' ',line)
until p= counter;
writeln
end;
procedure gate(counter,ans_gate: integer);
var
m,n,p,j: integer;
time_dep: integer;
begin
randomize;
for p:= 1 to counter do
with plane[p] do
gate:=chr(random(26)+65);
p:=0;
repeat
p:= p+1;
for j:= p+1 to counter do
if plane[p].gate = plane[j].gate
then repeat
plane[j].gate:= chr(random(26)+65)
until plane[p].gate <> plane[j].gate
until p= counter-1;
for p:= 1 to counter do
with plane[p] do
begin
time_dep:=2;
while time_dep>=0 do
begin
time_dep:= time_dep-1;
delay(1000)
end;
writeln('Gate ',gate,' is assigned for flight ',number,'.');
writeln
end;
for p:= 1 to counter do
with plane[p] do
begin
time_dep:=5;
while time_dep>=0 do
begin
time_dep:= time_dep-1;
delay(1000)
end;
if ans_gate= 1
then begin
writeln('Gate ',gate,' is now closing.');
writeln;
time_dep:= random(3)+3;
while time_dep>=0 do
begin
time_dep:= time_dep-1;
delay(1000)
end;
writeln('Flight ',number,' asks for runway.');
writeln
end
else begin
writeln('Passengers from flight ',number,' will reach Arrival Hall ',chr(random(2)+65),'.');
writeln
end
end
end;
procedure runway(var counter_dep: integer; ans_run: integer);
var
time_dep: integer;
p,q: integer;
begin
p:=0;
repeat
p:= p+1;
plane[p].runway:= random(2)+1;
time_dep:=3;
while time_dep>=0 do
begin
time_dep:= time_dep-1;
delay(1000)
end;
writeln('Runway ', plane[p].runway,' is assigned for flight ',plane[p].number,'.');
writeln;
time_dep:= 2;
while time_dep>= 0 do
begin
time_dep:= time_dep-1;
delay(1000)
end;
for q:= p+1 to counter_dep do
begin
writeln('The runways are not yet available for flight ',plane[q].number,'.');
writeln
end;
time_dep:=random(3)+3;
while time_dep>= 0 do
begin
time_dep:= time_dep-1;
delay(1000)
end;
if ans_run= 1
then with plane[p] do
begin
writeln('Flight ',number,' has taken off.');
writeln
end;
if ans_run= 2
then with plane[p] do
begin
writeln('Flight ',number,' has landed.');
writeln
end
until p= counter_dep
end;
procedure clear(var counter: integer);
var
p: integer;
begin
for p:= 1 to counter do
with plane[p] do
begin
number:='';
line:='';
gate:=' ';
runway:=0
end;
counter:= 0
end;
procedure one(num_one,ans_one: integer);
begin
departure(num_one);
display(num_one);
gate(num_one,ans_one);
runway(num_one,ans_one);
clear(num_one)
end;
procedure two(num_two,ans_two: integer);
begin
arrival(num_two);
display(num_two);
runway(num_two,ans_two);
gate(num_two,ans_two);
clear(num_two)
end;
procedure repeating;
var
ans_a: string;
ans_b: integer;
code_one: integer;
begin
repeat
write('Please enter your choice (1. Departure 2. Arrival 3. Exit): ');
readln(ans_a);
val(ans_a,ans_b,code_one)
until (ans_b= 1) or (ans_b= 2) or (ans_b= 3) and (code_one= 0);
if ans_b=1
then begin
one(num,1);
repeating
end;
if ans_b=2
then begin
two(num,2);
repeating
end
end;
begin
repeat
write('Please enter your choice (1. Departure 2. Arrival): ');
readln(ans_strg);
val(ans_strg,ans,code_main)
until (ans= 1) or (ans= 2) and (code_main= 0);
if ans= 1
then one(num,ans)
else two(num,ans);
repeating;
readln
end.