Recent

Author Topic: I am the new of pascal .please give me some HELP!  (Read 16297 times)

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
I am the new of pascal .please give me some HELP!
« on: October 10, 2016, 09:23:16 am »
I am the new in pascal and i get some problems on my programme.Please read my programme and help to solve it,thanks.
Code: [Select]
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.

here is my code and after executing many procedures , i try to save my record and update my textfile.However i stuck on my saving of update_platformfile. the data saved is out of my expectation.

what i want is:
Code: [Select]
$$$
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

however after updated i got
Code: [Select]
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

i am sorry that it costs a lot of time of teaching a novice but
Could you help to figure out what i get wrong on my programme or on my logic,please?
7vinbaby

molly

  • Hero Member
  • *****
  • Posts: 2345
Re: I am the new of pascal .please give me some HELP!
« Reply #1 on: October 10, 2016, 10:40:38 am »
Hi 7vinbaby,

Unfortunately the program crashes for me on startup when attempting to read the files.

Reason for that is when you do not have the files present you still attempt to open them.

Would you like to address that first ? And are you able to manage that on your own ?

As a hint, please have a look at the reset command

Do you notice how the {$I-} and {$I+} switches being used in the example shown at the bottom ?

That is so that you are able to 'catch' the IOResult variable in order to be able check if the file opened correctly or not.


PS: And please do me/us/yourself a favour and declare a global constant with the password for testing purposes so that one is able to change that with one single change of that password. It is highly annoying to get prompted for the password over and over again. If you declare it globally one could change it into nothing and simply press enter.
« Last Edit: October 10, 2016, 10:50:49 am by molly »

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
Re: I am the new of pascal .please give me some HELP!
« Reply #2 on: October 10, 2016, 10:52:45 am »

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).
Also i think it is not the problems of opening the file but the problems of saving record.
Because in the textfile,if there is empty ,i use $$$ to represent .
But after saving i cannot find any $$$ but becomes -7.

Did i make anything wrong or did i misunderstand sth?
7vinbaby

molly

  • Hero Member
  • *****
  • Posts: 2345
Re: I am the new of pascal .please give me some HELP!
« Reply #3 on: October 10, 2016, 10:56:26 am »
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  :)

Quote
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.

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
Re: I am the new of pascal .please give me some HELP!
« Reply #4 on: October 10, 2016, 11:05:36 am »
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  :)

Quote
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.

i get loss on what you pointed out.

Btw the update_platformfile and update_airtrafficfile should have something wrong on saving the record into the textfile
        Because in the textfile,if it is empty record ,i use $$$ to represent .
        But after saving i cannot find any $$$ but becomes -7 in the textfile.
7vinbaby

molly

  • Hero Member
  • *****
  • Posts: 2345
Re: I am the new of pascal .please give me some HELP!
« Reply #5 on: October 10, 2016, 11:15:35 am »
Life is pretty simple  :D

You wrote:
Quote
what 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.


7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
Re: I am the new of pascal .please give me some HELP!
« Reply #6 on: October 10, 2016, 11:23:35 am »
Life is pretty simple  :D

You wrote:
Quote
what 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?
7vinbaby

molly

  • Hero Member
  • *****
  • Posts: 2345
Re: I am the new of pascal .please give me some HELP!
« Reply #7 on: October 10, 2016, 11:46:16 am »
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)

The example code for the fileexists function that i pointed to earlier (link) 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 ?

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
Re: I am the new of pascal .please give me some HELP!
« Reply #8 on: October 10, 2016, 11:56:48 am »
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)

The example code for the fileexists function that i pointed to earlier (link) 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.
But the problems are that i cannot have a correct data in my textfile even the files exist.
7vinbaby

molly

  • Hero Member
  • *****
  • Posts: 2345
Re: I am the new of pascal .please give me some HELP!
« Reply #9 on: October 10, 2016, 12:02:59 pm »
i see what you mean.
But the problems are that i cannot have a correct data in my textfile even the files exist.
Then we have a problem  :D

If i create those files and leave them empty, all i get is:
Quote
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

So, i am unable to reproduce the error that you got  :'(

What must i do do reproduce the exact error that you got ?

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
Re: I am the new of pascal .please give me some HELP!
« Reply #10 on: October 10, 2016, 12:06:40 pm »
i see what you mean.
But the problems are that i cannot have a correct data in my textfile even the files exist.
Then we have a problem  :D

If i create those files and leave them empty, all i get is:
Quote
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

So, i am unable to reproduce the error that you got  :'(

What must i do do reproduce the exact error that you got ?

actually there are also a textfile for airtrafficfile.
Code: [Select]
.....
 assign(airtrafficfile,'C:/airtrafficcontrol/airtraffic.txt');
........
the textfile is like that:
Code: [Select]
fes2135487
3
qwe7634153
7
jfd1325748
11

sorry for taking you long time!
7vinbaby

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
Re: I am the new of pascal .please give me some HELP!
« Reply #11 on: October 10, 2016, 12:09:52 pm »
Also the problems occur after i add procedure update_platformfile & update_airtrafficfile since i want to save the record even the users leave the programme but not restart.
Before this ,the programme is all right ( i think).
7vinbaby

molly

  • Hero Member
  • *****
  • Posts: 2345
Re: I am the new of pascal .please give me some HELP!
« Reply #12 on: October 10, 2016, 12:30:09 pm »
Ok, thank you. That 3 flight entries example helped start up the program  :)

Without actually looking at the code, i think i spotted some things that go wrong:
1) when i press escape to stop the process the file airport_condition.txt is filled with a crlf + number. That does not seem to make any sense to me.
2) no matter what i choose when a plane asks if it is allowed to land: it always adds up the number of planes that are waiting for landing (i would expect that number to decrease when i actually give permission for the plane to land).
3) after the message Press enter to continue/Press ESC key, and when pressing enter the screen is cleared and a cursor stands at top left corner without any message. It took me a while to figure out i had to press the return key (i was expecting a delay of about 20 seconds as i peeked in your code  :D )

This will require a bit more time to debug but, at the same time i am not sure what is the intention of the program.

In case my writing tells you that something is wrong, then please state how the program is suppose to behave. Right now my experience is that the program behaves  how the code was written. If that is correct or not is another story  :)

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
Re: I am the new of pascal .please give me some HELP!
« Reply #13 on: October 10, 2016, 12:47:12 pm »
Code: [Select]
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.

you can try the above code which output the stored data in record of platformfile
i add some codes which output the record of platform
and you will find the record from $$$ to -1 &-2&-3 which i expect if the record is empty ,it is $$$.
That's all the reasons that go wrong including no plane to take off.
Also the no of plane to land will not decrease since it is the waiting list of landing plane and generate automatically.
7vinbaby

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
Re: I am the new of pascal .please give me some HELP!
« Reply #14 on: October 10, 2016, 12:58:33 pm »
My programme procedure is :(modify the programme timing)

read the data in textfile .
wait for 60s (5s)
find any plane on air or in airport 's time is 0 ,means it is ready to take off or landing.
then, if time is 0
         take off/landing procedure. Then goto save record and loop repeatly
otherwise goto save record and loop repeatly
finally save record in textfile ..
« Last Edit: October 10, 2016, 02:00:17 pm by 7vinbaby »
7vinbaby

 

TinyPortal © 2005-2018