program air_traffic_control;
uses Dos,Crt;
type
airport_platform=record
airplane_no:string[30];
airplane_predicted_time_left:integer;
end;
airtraffic_condition=record
airplane_no:string[30];
airplane_landing_time_left:integer;
end;
var
hour,min,sec,msec:word;
num,target,count,count2,counter,z,a,q:integer;
platformfile,airtrafficfile:text;
platform:array[1..30] of airport_platform;
airtraffic:array[1..20] of airtraffic_condition;
ch:char;
procedure user_display;
type DayType=(Sun,Mon,Tue,Wed,Thu,Fri,Sat);
var
YY,MM,DD,DayOfWeek,hour,min,sec,msec:word;
today:DayType;
password:string[20];
begin
textbackground(black);
ClrScr;
Getdate(YY,MM,DD,DayOfWeek);
GetTime(hour,min,sec,msec);
Today:=DayType(DayOfWeek);
textcolor(yellow);
writeln('Welcome to execute air traffic control');
repeat
textcolor(yellow);
write('Password:');
readln(password);
if password<>'aed7689'
then writeln('Wrong password,enter again');
until password='aed7689';
ClrScr;
writeln('Day of Today:',DD,'/',MM,'/',YY,',',Today);
writeln('Current time: ',hour,':',min,':',sec);
writeln('Now start the system of air traffic control management');
repeat
textcolor(yellow);
write('Enter password again to continue:');
readln(password);
if password<>'aed7689'
then writeln('Wrong password,enter again');
until password='aed7689';
ClrScr;
end;
procedure input_airtraffic(var count2:integer);
var count,x:integer;
begin
for x:=1 to 30 do
airtraffic[x].airplane_no:='';
count2:=0;
assign(airtrafficfile,'C:/airtrafficcontrol/airtraffic.txt');
reset(airtrafficfile);
while not eof(airtrafficfile) do
begin
count2:=count2+1;
with airtraffic[count2] do
begin
readln(airtrafficfile,airplane_no);
readln(airtrafficfile,airplane_landing_time_left);
end;
end;
close(airtrafficfile);
end;
procedure input_platform_condition(var num:integer);
var x,counter:integer;
begin
num:=0;
for x:=1 to 30 do
platform[x].airplane_no:='';
assign(platformfile,'C:/airtrafficcontrol/airport_condition.txt');
reset(platformfile);
counter:=0;
while counter<30 do
begin
counter:=counter+1;
with platform[num] do
begin
readln(platformfile,airplane_no);
readln(platformfile,airplane_predicted_time_left);
if airplane_no<>'$$$'
then num:=num+1;
end;
end;
close(platformfile);
end;
procedure take_off(var num,target:integer);
var choice:char;
password:string[30];
begin
with platform[target] do
begin
repeat
write('plane ',airplane_no,'is ready to take off,asking for permission(Y/N)?');
readln(choice);
if not(choice in ['Y','y','N','n'])
then write('Wrong input choice,please input choice again(Y/N):');
ClrScr;
until (choice='y') or (choice='Y') or (choice='N') or (choice='n');
if (choice='N') or (choice='n')
then airplane_predicted_time_left:=5
else begin
repeat
write('Enter password to execute this order:');
readln(password);
ClrScr;
until password='aed7689';
writeln('please wait for the processing of taking off.......');
delay(20000);
writeln('plane ',airplane_no,'has been taken off');
readln;
num:=num-1;
airplane_no:='$$$';
airplane_predicted_time_left:=999;
end;
end;
end;
procedure update_platform_time_left(var num,target,count:integer);
begin
target:=0;
if count<=30
then
begin
count:=count+1;
with platform[count] do
begin
airplane_predicted_time_left:=airplane_predicted_time_left-1;
if (airplane_predicted_time_left<=0) and (airplane_no<>'')
then begin
target:=count;
if platform[target].airplane_no<>'$$$'
then take_off(num,target);
if count<31
then update_platform_time_left(num,target,count);
end
else if count<30 then
update_platform_time_left(num,target,count);
end;
end;
end;
procedure update_air_traffic(count:integer;var num,count2:integer);
var choice1:char;
target,count1,x,y,n:integer;
password:string[10];
begin
n:=1;
target:=0;
count1:=0;
count:=count+1;
if count<=count2
then begin
with airtraffic[count] do
begin
airplane_landing_time_left:=airplane_landing_time_left-1;
if (airplane_landing_time_left<=0) and (airplane_no<>'')
then begin
repeat
write('airplane ',airplane_no,' is asking for the permission of landing(Y/N):');
readln(choice1);
until (choice1='y') or (choice1='Y') or (choice1='n') or (choice1='N');
repeat
write('Please input password to continue:');
readln(password);
ClrScr;
until password='aed7689';
case choice1 of
'y','Y':begin
while target=0 do
begin
count1:=count1+1;
if count1>30
then exit;
if platform[count1].airplane_no='$$$'
then target:=count1;
end;
if count1>30
then begin
writeln('No platform remain, please stay on the air');
airplane_landing_time_left:=5;
end
else begin
write('airplane ',airplane_no, ' landing to platform ',target);
readln;
platform[target].airplane_no:=airplane_no;
platform[target].airplane_predicted_time_left:=400;
airplane_no:='';
num:=num+1;
for n:=1 to (count2-1) do
begin
if airtraffic[n].airplane_no<>''
then begin
airtraffic[n].airplane_landing_time_left:=airtraffic[n].airplane_landing_time_left;
end;
end;
end;
count2:=count2-1;
end;
'n','N':airplane_landing_time_left:=5
end
end
else if count<31
then begin
update_air_traffic(count,num,count2);
end;
end;
end;
end;
procedure generate_airplane_no(var count2:integer);
var x:array[1..3] of char;
y:array[1..7] of char;
z:string[30];
count,abc:integer;
begin
if count2<30
then begin
count2:=count2+1;
for count:=1 to 3 do
x[count]:=' ';
for count:=1 to 7 do
y[count]:=' ';
if count2<21
then begin
randomize;
abc:=random(9);
for count:=1 to 3 do
x[count]:=chr(random(26)+65);
for count:=1 to 7 do
y[count]:=chr(random(10)+48);
for count:=1 to 2 do
z:=concat(z,x[count]);
for count:=1 to 7 do
z:=concat(z,y[count]);
with airtraffic[count2] do
begin
airplane_no:=z;
airplane_landing_time_left:=random(20)+1;
readln;
end;
end;
end;
end;
procedure update_platformfile;
var n:integer;
begin
rewrite(platformfile);
for n:=1 to 30 do
begin
with platform[n] do
begin
writeln(platformfile,airplane_no);
writeln(platformfile,airplane_predicted_time_left);
end;
end;
close(platformfile);
end;
procedure update_airtrafficfile(var count2:integer);
var n:integer;
begin
rewrite(airtrafficfile);
for n:=1 to count2 do
begin
with airtraffic[n] do
begin
writeln(airtrafficfile,airplane_no);
writeln(airtrafficfile,airplane_landing_time_left);
end;
end;
close(airtrafficfile);
end;
begin
count2:=0;
user_display;
input_airtraffic(count2);
input_platform_condition(num);
while num>=0 do
begin
ClrScr;
GetTime(hour,min,sec,msec);
writeln('Current time: ',hour,':',min,':',sec);
z:=0;
writeln('There are total ',num,' planes in the airport now');
writeln('There are total ',count2,' planes are waiting for landing');
count:=0;
repeat
writeln('Press Enter to continue/Press ESC to exit');
ch:=ReadKey;
ClrScr;
until (ch=#27) or (ch=#13);
case ch of
#13:begin
if (num=0) and (count2=0)
then begin
writeln('No plane information found, please wait until plane land/take off....');
writeln('press ENTER to continue!!');
repeat
ch:=ReadKey;
until (ch=#13);
ClrScr;
end;
if (num<>0) and (count2<>0)
then begin
generate_airplane_no(count2);
ClrScr;
writeln('Waiting for the system instruction.....');
delay(10000);
ClrScr;
update_air_traffic(count,num,count2);
update_platform_time_left(num,target,count);
update_platformfile;
update_airtrafficfile(count2);
end;
end;
#27:exit;
end;
end;
end.
$$$
999
ays5598745
4
afj7895542
11
asw7865456
17
afu7641313
22
hfi7646411
29
dai5641321
40
ash7646132
49
ash4564653
58
kjs8463133
63
kja7645413
69
ahf4613133
74
sad8976463
81
qwr2131852
88
hdf1341679
93
djd7641232
98
qwr7841321
101
dsa7643125
110
fdd4632154
116
thr5412312
121
vxj7643135
125
jhd6734535
131
rjn8764354
138
fds8645643
141
her7634351
150
hbg5643515
153
ery4123156
160
few3131548
166
$$$
999
$$$
999
afj7895542
4
asw7865456
10
afu7641313
15
hfi7646411
22
dai5641321
33
ash7646132
42
ash4564653
51
kjs8463133
56
kja7645413
62
ahf4613133
67
sad8976463
74
qwr2131852
81
hdf1341679
86
djd7641232
91
qwr7841321
94
dsa7643125
103
fdd4632154
109
thr5412312
114
vxj7643135
118
jhd6734535
124
rjn8764354
131
fds8645643
134
her7634351
143
hbg5643515
146
ery4123156
153
few3131548
159
HK6206933
393
-7
-7
-7
Unfortunately the program crashes for me on startup when attempting to read the files.
actually i think the program crashes for you is because the file name as i put the textfile in C drive(if i do not misunderstand your word).I was smart enough to change that. Still i do not have those files and your code is not taking that situation into account.
Did i make anything wrong or did i misunderstand sth?Yes :D. your code wrongfully assumes the files always exist while in my case they don't.
actually i think the program crashes for you is because the file name as i put the textfile in C drive(if i do not misunderstand your word).I was smart enough to change that. Still i do not have those files and your code is not taking that situation into account.
Please try yourself by renaming your existing files that your porgram uses and witness the crash yourself.
The first crash occurs inside routine input_airtraffic() when you do the reset.
Hence why i pointed towards the documentation on that subject :)QuoteDid i make anything wrong or did i misunderstand sth?Yes :D. your code wrongfully assumes the files always exist while in my case they don't.
what i want is:
blah
however after updated i got
blah
Life is pretty simple :D
You wrote:Quotewhat i want is:
blah
however after updated i got
blah
It is not possible for someone else to verify this situation as the files that your program uses are not part of your post.
So, whenever someone else starts your program they will run your program for the very first time.
For that situation there are no files present yet, and so your program crashes.
It is impossible for someone else (besides yourself) to generate the result as you have shown in your post. I'm not in the mood to invent files and their data for your program as i have not the faintest idea what i must put inside such files.
okay,so what i should do for this to correct this?If you want others to be able to produce the exact same output as you do, then provide us with the missing file(s).
okay,so what i should do for this to correct this?If you want others to be able to produce the exact same output as you do, then provide us with the missing file(s).
In case you can't share the files you are currently using, then make/provide us some (unimportant) version of the file for us to work with and that you can use yourself for comparison. In that case make sure the error that you experience is still present (it can depend on the actual data that is stored inside your file).
Better would be to let your program generate the files automatically but, i can imagine that you removed those parts from your initial post in order to keep your example as small as possible. :)
Either way, your code does need to take care of the situation were it is unable to reset the file and act accordingly (for example printing a human readable error instead of runtime error 2 (http://www.freepascal.org/docs-html/user/userap4.html))
The example code for the fileexists function that i pointed to earlier (link (http://www.freepascal.org/docs-html/rtl/system/reset.html)) would be a good start for you to be able to determine if the required file actually exists or not. As of yet i have no clue what your program should do in case it is unable to find the file other then telling the user that the program was unable to find the file.
Perhaps you have an idea about that yourself ?
i see what you mean.Then we have a problem :D
But the problems are that i cannot have a correct data in my textfile even the files exist.
Current time: 10:57:13
There are total 30 planes in the airport now
There are total 0 planes are waiting for landing
Press Enter to continue/Press ESC to exit
i see what you mean.Then we have a problem :D
But the problems are that i cannot have a correct data in my textfile even the files exist.
If i create those files and leave them empty, all i get is:QuoteCurrent time: 10:57:13
There are total 30 planes in the airport now
There are total 0 planes are waiting for landing
Press Enter to continue/Press ESC to exit
So, i am unable to reproduce the error that you got :'(
What must i do do reproduce the exact error that you got ?
.....
assign(airtrafficfile,'C:/airtrafficcontrol/airtraffic.txt');
........
the textfile is like that:fes2135487
3
qwe7634153
7
jfd1325748
11
program air_traffic_control;
uses Dos,Crt;
type
airport_platform=record
airplane_no:string[30];
airplane_predicted_time_left:integer;
end;
airtraffic_condition=record
airplane_no:string[30];
airplane_landing_time_left:integer;
end;
var
hour,min,sec,msec:word;
num,target,count,count2,counter,z,a,q:integer;
platformfile,airtrafficfile:text;
platform:array[1..30] of airport_platform;
airtraffic:array[1..20] of airtraffic_condition;
ch:char;
procedure user_display;
type DayType=(Sun,Mon,Tue,Wed,Thu,Fri,Sat);
var
YY,MM,DD,DayOfWeek,hour,min,sec,msec:word;
today:DayType;
password:string[20];
begin
textbackground(black);
ClrScr;
Getdate(YY,MM,DD,DayOfWeek);
GetTime(hour,min,sec,msec);
Today:=DayType(DayOfWeek);
textcolor(yellow);
writeln('Welcome to execute air traffic control');
repeat
textcolor(yellow);
write('Password:');
readln(password);
if password<>'aed7689'
then writeln('Wrong password,enter again');
until password='aed7689';
ClrScr;
writeln('Day of Today:',DD,'/',MM,'/',YY,',',Today);
writeln('Current time: ',hour,':',min,':',sec);
writeln('Now start the system of air traffic control management');
repeat
textcolor(yellow);
write('Enter password again to continue:');
readln(password);
if password<>'aed7689'
then writeln('Wrong password,enter again');
until password='aed7689';
ClrScr;
end;
procedure input_airtraffic(var count2:integer);
var count,x:integer;
begin
for x:=1 to 30 do
airtraffic[x].airplane_no:='';
count2:=0;
assign(airtrafficfile,'C:/airtrafficcontrol/airtraffic.txt');
reset(airtrafficfile);
while not eof(airtrafficfile) do
begin
count2:=count2+1;
with airtraffic[count2] do
begin
readln(airtrafficfile,airplane_no);
readln(airtrafficfile,airplane_landing_time_left);
end;
end;
close(airtrafficfile);
end;
procedure input_platform_condition(var num:integer);
var x,counter:integer;
begin
num:=0;
for x:=1 to 30 do
platform[x].airplane_no:='';
assign(platformfile,'C:/airtrafficcontrol/airport_condition.txt');
reset(platformfile);
counter:=0;
while counter<30 do
begin
counter:=counter+1;
with platform[num] do
begin
readln(platformfile,airplane_no);
readln(platformfile,airplane_predicted_time_left);
if airplane_no<>'$$$'
then num:=num+1;
end;
end;
close(platformfile);
end;
procedure take_off(var num,target:integer);
var choice:char;
password:string[30];
begin
with platform[target] do
begin
repeat
write('plane ',airplane_no,'is ready to take off,asking for permission(Y/N)?');
readln(choice);
if not(choice in ['Y','y','N','n'])
then write('Wrong input choice,please input choice again(Y/N):');
ClrScr;
until (choice='y') or (choice='Y') or (choice='N') or (choice='n');
if (choice='N') or (choice='n')
then airplane_predicted_time_left:=5
else begin
repeat
write('Enter password to execute this order:');
readln(password);
ClrScr;
until password='aed7689';
writeln('please wait for the processing of taking off.......');
delay(5000);
writeln('plane ',airplane_no,'has been taken off');
readln;
num:=num-1;
airplane_no:='$$$';
airplane_predicted_time_left:=999;
end;
end;
end;
procedure update_platform_time_left(var num,target,count:integer);
begin
target:=0;
if count<=30
then
begin
count:=count+1;
with platform[count] do
begin
airplane_predicted_time_left:=airplane_predicted_time_left-1;
if (airplane_predicted_time_left<=0) and (airplane_no<>'')
then begin
target:=count;
if platform[target].airplane_no<>'$$$'
then take_off(num,target);
if count<31
then update_platform_time_left(num,target,count);
end
else if count<30 then
update_platform_time_left(num,target,count);
end;
end;
end;
procedure update_air_traffic(count:integer;var num,count2:integer);
var choice1:char;
target,count1,x,y,n:integer;
password:string[10];
begin
n:=1;
target:=0;
count1:=0;
count:=count+1;
if count<=count2
then begin
with airtraffic[count] do
begin
airplane_landing_time_left:=airplane_landing_time_left-1;
if (airplane_landing_time_left<=0) and (airplane_no<>'')
then begin
repeat
write('airplane ',airplane_no,' is asking for the permission of landing(Y/N):');
readln(choice1);
until (choice1='y') or (choice1='Y') or (choice1='n') or (choice1='N');
repeat
write('Please input password to continue:');
readln(password);
ClrScr;
until password='aed7689';
case choice1 of
'y','Y':begin
while target=0 do
begin
count1:=count1+1;
if count1>30
then exit;
if platform[count1].airplane_no='$$$'
then target:=count1;
end;
if count1>30
then begin
writeln('No platform remain, please stay on the air');
airplane_landing_time_left:=5;
end
else begin
write('airplane ',airplane_no, ' landing to platform ',target);
readln;
platform[target].airplane_no:=airplane_no;
platform[target].airplane_predicted_time_left:=400;
airplane_no:='';
num:=num+1;
for n:=1 to (count2-1) do
begin
if airtraffic[n].airplane_no<>''
then begin
airtraffic[n].airplane_landing_time_left:=airtraffic[n].airplane_landing_time_left;
end;
end;
end;
count2:=count2-1;
end;
'n','N':airplane_landing_time_left:=5
end
end
else if count<31
then begin
update_air_traffic(count,num,count2);
end;
end;
end;
end;
procedure generate_airplane_no(var count2:integer);
var x:array[1..3] of char;
y:array[1..7] of char;
z:string[30];
count,abc:integer;
begin
if count2<30
then begin
count2:=count2+1;
for count:=1 to 3 do
x[count]:=' ';
for count:=1 to 7 do
y[count]:=' ';
if count2<21
then begin
randomize;
abc:=random(9);
for count:=1 to 3 do
x[count]:=chr(random(26)+65);
for count:=1 to 7 do
y[count]:=chr(random(10)+48);
for count:=1 to 2 do
z:=concat(z,x[count]);
for count:=1 to 7 do
z:=concat(z,y[count]);
with airtraffic[count2] do
begin
airplane_no:=z;
airplane_landing_time_left:=random(20)+1;
readln;
end;
end;
end;
end;
procedure update_platformfile;
var n:integer;
begin
rewrite(platformfile);
for n:=1 to 30 do
begin
with platform[n] do
begin
writeln(platformfile,airplane_no);
writeln(platformfile,airplane_predicted_time_left);
end;
end;
close(platformfile);
end;
procedure update_airtrafficfile(var count2:integer);
var n:integer;
begin
rewrite(airtrafficfile);
for n:=1 to count2 do
begin
with airtraffic[n] do
begin
writeln(airtrafficfile,airplane_no);
writeln(airtrafficfile,airplane_landing_time_left);
end;
end;
close(airtrafficfile);
end;
begin
count2:=0;
user_display;
input_airtraffic(count2);
input_platform_condition(num);
while num>=0 do
begin
ClrScr;
GetTime(hour,min,sec,msec);
writeln('Current time: ',hour,':',min,':',sec);
z:=0;
writeln('There are total ',num,' planes in the airport now');
writeln('There are total ',count2,' planes are waiting for landing');
count:=0;
repeat
writeln('Press Enter to continue/Press ESC to exit');
ch:=ReadKey;
ClrScr;
until (ch=#27) or (ch=#13);
case ch of
#13:begin
if (num=0) and (count2=0)
then begin
writeln('No plane information found, please wait until plane land/take off....');
writeln('press ENTER to continue!!');
repeat
ch:=ReadKey;
until (ch=#13);
ClrScr;
end;
if (num<>0) and (count2<>0)
then begin
generate_airplane_no(count2);
ClrScr;
writeln('Waiting for the system instruction.....');
delay(10000);
ClrScr;
update_air_traffic(count,num,count2);
update_platform_time_left(num,target,count);
update_platformfile;
update_airtrafficfile(count2);
for q:=1 to 30 do
begin
with platform[q] do
begin
writeln(airplane_no);
writeln(airplane_predicted_time_left);
end;
readln;
end;
end;
end;
#27:exit;
end;
end;
end.
If ( (airplane_no<>'$$$') and (airplane_no <> '') )
Then num := num+1;
As i assume it is allowed to have no planes at all at the airport (and only have planes in the air, waiting for landing).I haven't found the culprit yet but i did run into something else.
What happens if the file airport_condition.txt is empty ?
Procedure input_platform_condition(Var num:integer); Var x,counter: integer; Begin num := 0; For x:=1 To 30 Do platform[x].airplane_no := ''; assign(platformfile,'airport_condition.txt'); reset(platformfile); counter := 0; While counter<30 Do Begin counter := counter+1; With platform[num] Do Begin readln(platformfile,airplane_no); readln(platformfile,airplane_predicted_time_left); If (airplane_no<>'$$$') Then num := num+1; End; End; close(platformfile); End;
The code simply assumes that when the plane is not $$$ that it is a plane, which is wrong in case the statement readln(platformfile,airplane_no); produced an empty airplane_no.
Fix that by:Code: [Select]If ( (airplane_no<>'$$$') and (airplane_no <> '') )
As i assume it is allowed to have no planes at all at the airport (and only have planes in the air, waiting for landing).
Then num := num+1;
And that leads to another problem, namely that you start-loop is stuck when this condition happens :(
Because if there are no planes at the airport, the routine input_platform_condition returns the num variable (which is then zero).
Take a look at your loop:
While num>=0 Do Begin // blah Case ch Of #13: Begin If (num=0) And (count2=0) Then begin // blah end; If (num<>0) And (count2<>0) Then Begin // blah End; End; End;
Num is the number of planes at the airport (which is zero), and count2 is the number of planes in the air (three given your example file).
None of these conditions is met and, the loop will go on forever without actually doing anything.
procedure input_platform_condition(var num:integer);
var x,counter,num1:integer;
begin
num:=0;
num1:=1;
for x:=1 to 30 do
platform[x].airplane_no:='';
assign(platformfile,'C:/airtrafficcontrol/airport_condition.txt');
reset(platformfile);
while not eof(platformfile) do
begin
with platform[num1] do
begin
readln(platformfile,airplane_no);
readln(platformfile,airplane_predicted_time_left);
num1:=num1+1;
if airplane_no<>'empty'
then num:=num+1;
end;
end;
close(platformfile);
end;
Is that all right (i change the $$$ to empty)?Well, the $$$ sign can stay if you want to :)
while (target=0) and (count1>31) do
begin
count1:=count1+1;
if platform[count1].airplane_no='empty'
then target:=count1;
end;
Is that better?Except for the fact that entries inside file airport_condition are still being written with empty airplane_no's.
Is that better?Except for the fact that entries inside file airport_condition are still being written with empty airplane_no's.
Other then that, somewhere around entry 20 things go wrong inside file airtraffic.txt as well (empty lines for both airplane_no and the left time). Somewhere in at the end i even got entries reading -78117079 and 2088 for airplane_no and an empty line for time_left %)
Can't seem to get my head around why the empty entries inside file airport_condition are being created.
PS: oops, no. Unfortunately that is not going to work 7vinbaby. If you do that then when it happens to be the first plane directly wanting to land the count1 variable will be zero and, you assign that as platfom. You arrays starts counting from one.
Sure, but your code doesn't act on it. If an entry is empty your current code happily assumes it is a valid plane number. It does not distinguish between them.Can't seem to get my head around why the empty entries inside file airport_condition are being created.You mean the empty entries should not be created?
But i need to know which entrie is empty in order to give to the landing airplane.
Talking about array index here:PS: oops, no. Unfortunately that is not going to work 7vinbaby. If you do that then when it happens to be the first plane directly wanting to land the count1 variable will be zero and, you assign that as platfom. You arrays starts counting from one.i am sorry that where are the position you are talking about?
chosen to allow landing, searching for a free platformAnd that is a big no-no for your arays.
The target platform is 0
The count1 is0
airplane qwe7634153 landing to platform 0
chosen to allow landing, searching for a free platform
The target platform is 0
The count1 is0
airplane qwe7634153 landing to platform 0
program air_traffic_control;
uses Dos,Crt;
type
airport_platform=record
airplane_no:string[30];
airplane_predicted_time_left:integer;
end;
airtraffic_condition=record
airplane_no:string[30];
airplane_landing_time_left:integer;
end;
var
hour,min,sec,msec:word;
num,target,count,count2,counter,z,a,q:integer;
platformfile,airtrafficfile:text;
platform:array[1..30] of airport_platform;
airtraffic:array[1..20] of airtraffic_condition;
ch:char;
procedure user_display;
type DayType=(Sun,Mon,Tue,Wed,Thu,Fri,Sat);
var
YY,MM,DD,DayOfWeek,hour,min,sec,msec:word;
today:DayType;
password:string[20];
begin
textbackground(black);
ClrScr;
Getdate(YY,MM,DD,DayOfWeek);
GetTime(hour,min,sec,msec);
Today:=DayType(DayOfWeek);
textcolor(yellow);
writeln('Welcome to execute air traffic control');
repeat
textcolor(yellow);
write('Password:');
readln(password);
if password<>'aed7689'
then writeln('Wrong password,enter again');
until password='aed7689';
ClrScr;
writeln('Day of Today:',DD,'/',MM,'/',YY,',',Today);
writeln('Current time: ',hour,':',min,':',sec);
writeln('Now start the system of air traffic control management');
repeat
textcolor(yellow);
write('Enter password again to continue:');
readln(password);
if password<>'aed7689'
then writeln('Wrong password,enter again');
until password='aed7689';
ClrScr;
end;
procedure input_airtraffic(var count2:integer);
var count,x:integer;
begin
for x:=1 to 30 do
airtraffic[x].airplane_no:='';
count2:=0;
assign(airtrafficfile,'C:/airtrafficcontrol/airtraffic.txt');
reset(airtrafficfile);
while not eof(airtrafficfile) do
begin
count2:=count2+1;
with airtraffic[count2] do
begin
readln(airtrafficfile,airplane_no);
readln(airtrafficfile,airplane_landing_time_left);
end;
end;
close(airtrafficfile);
end;
procedure input_platform_condition(var num:integer);
var x,counter,num1:integer;
begin
num:=0;
num1:=1;
for x:=1 to 30 do
platform[x].airplane_no:='';
assign(platformfile,'C:/airtrafficcontrol/airport_condition.txt');
reset(platformfile);
while not eof(platformfile) do
begin
with platform[num1] do
begin
readln(platformfile,airplane_no);
readln(platformfile,airplane_predicted_time_left);
num1:=num1+1;
if airplane_no<>'empty'
then num:=num+1;
end;
end;
close(platformfile);
end;
procedure take_off(var num,target:integer);
var choice:char;
password:string[30];
begin
with platform[target] do
begin
repeat
write('plane ',airplane_no,'is ready to take off,asking for permission(Y/N)?');
readln(choice);
if not(choice in ['Y','y','N','n'])
then write('Wrong input choice,please input choice again(Y/N):');
ClrScr;
until (choice='y') or (choice='Y') or (choice='N') or (choice='n');
if (choice='N') or (choice='n')
then airplane_predicted_time_left:=5
else begin
repeat
write('Enter password to execute this order:');
readln(password);
ClrScr;
until password='aed7689';
writeln('please wait for the processing of taking off.......');
delay(5000);
writeln('plane ',airplane_no,'has been taken off');
readln;
num:=num-1;
airplane_no:='empty';
airplane_predicted_time_left:=999;
end;
end;
end;
procedure update_platform_time_left(var num,target,count:integer);
begin
target:=0;
if count<=30
then
begin
count:=count+1;
with platform[count] do
begin
airplane_predicted_time_left:=airplane_predicted_time_left-1;
if (airplane_predicted_time_left<=0) and (airplane_no<>'')
then begin
target:=count;
if platform[target].airplane_no<>'empty'
then take_off(num,target);
if count<31
then update_platform_time_left(num,target,count);
end
else if count<30 then
update_platform_time_left(num,target,count);
end;
end;
end;
procedure update_air_traffic(count:integer;var num,count2:integer);
var choice1:char;
target,count1,x,y,n:integer;
password:string[10];
begin
n:=1;
target:=0;
count1:=0;
count:=count+1;
if count<=count2
then begin
with airtraffic[count] do
begin
airplane_landing_time_left:=airplane_landing_time_left-1;
if (airplane_landing_time_left<=0) and (airplane_no<>'')
then begin
repeat
write('airplane ',airplane_no,' is asking for the permission of landing(Y/N):');
readln(choice1);
until (choice1='y') or (choice1='Y') or (choice1='n') or (choice1='N');
repeat
write('Please input password to continue:');
readln(password);
ClrScr;
until password='aed7689';
case choice1 of
'y','Y':begin
while target=0 do
begin
count1:=count1+1;
if count1>30
then exit;
if platform[count1].airplane_no='empty'
then target:=count1;
end;
if count1>30
then begin
writeln('No platform remain, please stay on the air');
airplane_landing_time_left:=5;
end
else begin
write('airplane ',airplane_no, ' landing to platform ',target);
readln;
platform[target].airplane_no:=airplane_no;
platform[target].airplane_predicted_time_left:=400;
airplane_no:='';
num:=num+1;
for n:=1 to (count2-1) do
begin
if airtraffic[n].airplane_no<>''
then begin
airtraffic[n].airplane_landing_time_left:=airtraffic[n].airplane_landing_time_left;
end;
end;
end;
count2:=count2-1;
end;
'n','N':airplane_landing_time_left:=5
end
end
else if count<31
then begin
update_air_traffic(count,num,count2);
end;
end;
end;
end;
procedure generate_airplane_no(var count2:integer);
var x:array[1..3] of char;
y:array[1..7] of char;
z:string[30];
count,abc:integer;
begin
if count2<30
then begin
count2:=count2+1;
for count:=1 to 3 do
x[count]:=' ';
for count:=1 to 7 do
y[count]:=' ';
if count2<21
then begin
randomize;
abc:=random(9);
for count:=1 to 3 do
x[count]:=chr(random(26)+65);
for count:=1 to 7 do
y[count]:=chr(random(10)+48);
for count:=1 to 2 do
z:=concat(z,x[count]);
for count:=1 to 7 do
z:=concat(z,y[count]);
with airtraffic[count2] do
begin
airplane_no:=z;
airplane_landing_time_left:=random(20)+1;
readln;
end;
end;
end;
end;
procedure update_platformfile;
var n:integer;
begin
rewrite(platformfile);
for n:=1 to 30 do
begin
with platform[n] do
begin
writeln(platformfile,airplane_no);
writeln(platformfile,airplane_predicted_time_left);
end;
end;
close(platformfile);
end;
procedure update_airtrafficfile(var count2:integer);
var n:integer;
begin
rewrite(airtrafficfile);
for n:=1 to count2 do
begin
with airtraffic[n] do
begin
writeln(airtrafficfile,airplane_no);
writeln(airtrafficfile,airplane_landing_time_left);
end;
end;
close(airtrafficfile);
end;
procedure output_all;
begin
window(1,50,80,25);
readln;
clrscr;
end;
procedure signal_light;
begin
end;
begin
count2:=0;
user_display;
input_airtraffic(count2);
input_platform_condition(num);
while num>=0 do
begin
ClrScr;
GetTime(hour,min,sec,msec);
writeln('Current time: ',hour,':',min,':',sec);
z:=0;
writeln('There are total ',num,' planes in the airport now');
writeln('There are total ',count2,' planes are waiting for landing');
output_all;
count:=0;
repeat
writeln('Press Enter to continue/Press ESC to exit');
ch:=ReadKey;
ClrScr;
until (ch=#27) or (ch=#13);
case ch of
#13:begin
if (num=0) and (count2=0)
then begin
writeln('No plane information found, please wait until plane land/take off....');
writeln('press ENTER to continue!!');
repeat
ch:=ReadKey;
until (ch=#13);
ClrScr;
end;
if (num<>0) and (count2<>0)
then begin
generate_airplane_no(count2);
ClrScr;
writeln('Waiting for the system instruction.....');
delay(10000);
ClrScr;
update_air_traffic(count,num,count2);
update_platform_time_left(num,target,count);
update_platformfile;
update_airtrafficfile(count2);
signal_light;
end;
end;
#27:exit;
end;
end;
end.
'y','Y':begin
while target=0 do
begin
count1:=count1+1;
if count1>30
then exit;
if platform[count1].airplane_no='empty'
then target:=count1;
end;
Look back procedure update_air_trafficCode: [Select]while (target=0) and (count1>31) do
begin
count1:=count1+1;
if platform[count1].airplane_no='empty'
then target:=count1;
end;
...
for x:=1 to 30 do
airtraffic[x].airplane_no:='';
var
airtraffic:array[1..20] of airtraffic_condition;
...
until (choice='y') or (choice='Y') or (choice='N') or (choice='n');
if (choice='N') or (choice='n')
...
choice := UpCase(choice);
until (choice in ['Y','N']);
if (choice = 'N')
C:\Users\Bart\LazarusProjecten\ConsoleProjecten\bugs\Forum\airtraffic>hd airtraffic.txt
Offset Hex ASCII
00000010: 66 65 73 32 31 33 35 34 38 37 0D 0A 33 0D 0A 71 fes2135487 3 q
00000020: 77 65 37 36 33 34 31 35 33 0D 0A 33 0D 0A 6A 66 we7634153 3 jf
00000030: 64 31 33 32 35 37 34 38 0D 0A 37 0D 0A 00 00 00 d1325748 7
00000040: 00 00 06 00 54 FF 41 01 4C DC 40 00 A4 F3 40 00 T A L @ @
00000050: C4 F7 40 00 50 00 4F 52 35 33 34 0D 0A 35 0D 0A @ P OR534 5
00000060: 00 00 00 00 00 06 00 54 FF 41 01 4C DC 40 00 A4 T A L @
00000070: F3 40 00 C4 F7 40 00 50 00 56 52 37 32 39 0D 0A @ @ P VR729
00000080: 39 0D 0A 00 00 00 00 00 06 00 54 FF 41 01 4C DB 9 T A L
00000090: 40 00 A4 F3 40 00 C4 F7 40 00 50 00 4C 52 37 34 @ @ @ P LR74
000000A0: 31 0D 0A 34 0D 0A 00 00 00 00 00 06 00 54 FF 41 1 4 T A
000000B0: 01 4C DB 40 00 A4 F3 40 00 C4 F7 40 00 50 00 47 L @ @ @ P G
000000C0: 46 35 30 36 0D 0A 37 0D 0A 00 00 00 00 00 06 00 F506 7
000000D0: 54 FF 41 01 4C DB 40 00 A4 F3 40 00 C4 F7 40 00 T A L @ @ @
000000DC: 50 00 46 54 34 35 34 0D 0A 32 30 0D P FT454 20
z := '';
for count := 1 to 2 do z := z + chr(random(26)+65);
for count := 1 to 7 do z := z + chr(random(10)+48);