home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug003.arc
/
PASCAL.008
< prev
next >
Wrap
Text File
|
1979-12-31
|
8KB
|
190 lines
PASCAL FOR BASIC PROGRAMMERS
Dixon Kenney
PART VIII
Iεá thi≤á article¼á wσá arσá goinτ t∩ adΣ ß ne≈á procedurσá t∩á ou≥ ì
Inventor∙ program«á Thi≤ prograφ wil∞ lis⌠ al∞ thσ item≤ oµ ou≥á database« ì
Iε orde≥ t∩ usσ thσ databasσ later¼á wσ arσ als∩ goinτ t∩ adΣ anothe≥ fielΣ ì
t∩ thσ record¼ s∩ tha⌠ i⌠ wil∞ no≈ looδ likσ thi≤ -
áááááááááááááá PartReπ ╜ Record
áááááááááááááá PartNuφ ║ 100░ .« 9999;
áááááááááááááá Descriptioε ║ St20;
áááááááááááááá Cos⌠ ║ Real;
áááááááááááááá Retai∞ ║ Real;
áááááááááááááá MinO╚ ║ Integer;
áááááááááááááá MaxReorde≥ ║ Integer;
áááááááááááááá CurrentO╚ ║ Integer;
áááááááááááááá DeleteΣ ║ Boolean;
áááááááááááááá End;
Thσá ne≈ fielΣ i≤ thσ las⌠ one¼á whicΦ wil∞ bσ useΣ t∩ marδ ß recorΣ iµá wσ ì
wan⌠á t∩á deletσ i⌠ froφ thσ database«á A⌠ datß entry¼á i⌠ wil∞ bσ se⌠á t∩ ì
false« T∩ d∩ this¼ alte≥ thσ listinτ oµ "NEWITEM.PROó t∩ looδ likσ thi≤ -
GoToXY(32,11); Read(MaxReorder);
GoTOXY(32,13); Read(CurrentOH);
Deleted := False;
Write(PartFile, Part)
End;
The addition is the line which sets the field "Deleted" to False.
Herσá i≤á thσ listinτ fo≥ thσ procedurσ whicΦ list≤ al∞ thσá item≤á oµ ì
stocδ oε thσ screeε :
áááááProcedurσ Listem;
áááááConst
ááááá Heade≥ ╜ º ¬ LISTIN╟ O╞ AL╠ ITEM╙ O╞ STOC╦ ¬ ';
ááááá ScreenLine≤ ╜ 15;
áááááVar
ááááá YesN∩ ║ Char;
ááááá Ro≈ ║ Integer;
áááááBegin
ááááá Assign(PartFile,FileName);
ááááá Reset(PartFile);
ááááá ClrScr;
ááááá Writeln(º ':20¼ Header);
ááááá Write('Iteφ #':6,º Description':22,º Cost':10);
ááááá Writeln(º Retail':10,'Minimum':8,'Maximum':8,'Oε Hand':8);
ááááá Writeln;
ááááá Ro≈ :╜ 0;èááááá Whilσ no⌠ EOF(PartFile⌐ do
ááááá Begin
ááááá Read(PartFile,Part);
ááááá WitΦ Par⌠ do
ááááá Begin
ááááá Write(PartNum:6,Description:22,Cost:10:2,Retail:10:2);
ááááá Writeln(MinOH:8,MaxReorder:8,CurrentOH:8);
ááááá Ro≈ :╜ Succ(Row);
ááááá Iµ Ro≈ ╜ ScreenLine≤ then
ááááá Begin
ááááá Writeln;
ááááá Write('Pres≤ <RETURN> t∩ continue');
ááááá Readln(YesNo);
ááááá Ro≈ :╜ 0
ááááá EnΣ √ oµ Iµ Ro≈ }
ááááá EnΣ √ oµ WitΦ Par⌠ D∩ }
ááááá End╗ √ oµ Whilσ No⌠ EO╞ }
ááááá Close(PartFile);
ááááá Writeln;
ááááá Write('Typσá <RETURN╛á ke∙á wheε yo⌡ havσá finisheΣá witΦá thi≤ ì
ááááádispla∙ ');
ááááá Readln(YesNo);
áááááEnd╗ √ oµ Procedurσ Listeφ }
The skeleton of this procedure looks like this -
1 Open the File, and put the record pointer to zero.
2 Clear the Screen, and write the column headers on it.
3 a Get a record from the disk
b Write it to the screen
c If the screen is full ( by calculation a fixed number
of records, called ScreenLines ), pause until the
user presses a key.
4 When the file is fully listed, wait until the user types
a key, and then return to the Main Menu.
Comments on this procedure -
While Not EOF(Partfile) do
Thi≤ forma⌠ create≤ ß loop«á Thi≤ i≤ onσ oµ thσ │ type≤ oµ loopinτ ì
o≥ repetitivσ statement≤ availablσ iε Pascal«á Wσ havσ seeε thσ othe≥á tw∩ ì
alread∙ - thσ 'FO╥ ° :╜ bottoφ t∩ to≡ doº type¼á anΣ thσ 'REPEA╘ .«á UNTILº ì
type« Thi≤ presen⌠ typσ ha≤ thσ format
While < condition > do [ Begin .... End ]
Thσá conditioεá i≤ evaluateΣ a⌠ thσ beginninτ oµá thσá loop«á Thi≤ ì
mean≤á tha⌠á thσ loo≡ ma∙ no⌠ bσ executeΣ a⌠ all¼á sincσ thσ conditioεá ma∙ ì
turε ou⌠ t∩ bσ falsσ beforσ thσ loo≡ i≤ entered« Thσ blocδ i≤ markeΣ b∙ thσ ì
usua∞ Begiε anΣ EnΣ iµ morσ thaε onσ statemen⌠ i≤ presen⌠ iε it.
è Thσá functioε EOF(filevariable⌐ i≤ ß Booleaε function¼á whicΦá return≤ ì
thσ valuσ TRU┼ iµ thσ recorΣ pointe≥ i≤ a⌠ thσ EO╞ marker¼á beyonΣ thσ las⌠ ì
componen⌠á oµ thσ filσ itself«á S∩ "Whilσ no⌠ EOF(..)ó mean≤ "executσá thσ ì
blocδá whilσ thσ recorΣ pointe≥ stil∞ point≤ t∩ ß recorΣ iε thσá file¼á anΣ ì
sto≡ a≤ sooε a≤ i⌠ read≤ thσ EO╞ marke≥ a⌠ thσ enΣ oµ thσ file."
Write ( ... :m:n )
Wheεá yo⌡ arσ writinτ something¼á yo⌡ caε definσ thσ widtΦá oµá thσ ì
fielΣá t∩á writσ i⌠ iε b∙ addinτ ß coloε anΣ aε intege≥ whicΦá define≤á thσ ì
numbe≥á oµ characte≥ space≤ i⌠ wil∞ takσ up«á Thi≤ ":mó ma∙ bσ appendeΣ t∩ ì
eithe≥ ß variablσ labe∞ o≥ ß string¼ a≤ yo⌡ seσ we'vσ donσ here¼ firstl∙ iε ì
thσá columε headers¼á anΣ secondl∙ iε thσ actua∞ recorΣ contents«á Iµá thσ ì
numbe≥ whicΦ i≤ beinτ printeΣ i≤ ß rea∞ number¼á theε yo⌡ caε adΣ ßá seconΣ ì
fielΣ widtΦ number¼ a≤ wσ havσ donσ fo≥ Cos⌠ anΣ Retai∞ here¼ whicΦ define≤ ì
thσ numbe≥ oµ column≤ useΣ fo≥ decima∞ fractioε digits«á S∩ herσ Cos⌠ wil∞ ì
bσá iε ß fielΣ 1░ characte≥ space≤ wide¼á tw∩ oµ whicΦ wil∞ bσ useΣ fo≥ thσ ì
decima∞á fractioεá digit≤ ¿ thσ cent≤ )¼á anΣ onσ fo≥á thσá decima∞á point¼ ì
leavinτ ╖ fo≥ thσ actua∞ intege≥ numbe≥ ¿ thσ dollar≤ ).
Row := Succ(Row)
Thσá functioεá Succ(x⌐á return≤á thσá valuσá whicΦá thσá T╨á manua∞ ì
describe≤á a≤ thσ "successoró oµ x¼á iµ i⌠ exists«á ° mus⌠ bσ oµ ßá scala≥ ì
type« Here¼ ° i≤ aε integer« Iµ ° ha≤ thσ valuσ oµ 1¼ it≤ successo≥ i≤ 2« ì
Iε fact¼á wσ havσ herσ aε alternativσ t∩ ° :╜ ° ½ 1«á Bu⌠ thσ functioε caε ì
bσ useΣ iε an∙ scala≥ type¼ excep⌠ REAL.
Iµá thσá typσ Weeδ wa≤ ß scala≥ typσ defineΣ a≤á thσá value≤á (Monday¼ ì
Tuesday¼á Wednesday¼ Thursday¼ Friday¼ Saturday¼ Sunday)¼ theε Succ(Monday⌐ ì
i≤ Tuesday.
If Row = ScreenLines
Thi≤á littlσá blocδ simpl∙ count≤ thσ numbe≥ oµ record≤ printeΣá oε ì
thσ screen¼á and¼ wheε tha⌠ numbe≥ equal≤ ß predefineΣ number¼ halt≤ outpu⌠ ì
unti∞ thσ use≥ presse≤ thσ returε key«
áááááááááUser≤ oµ dBAS┼ I╔ wil∞ bσ familia≥ witΦ thi≤ littlσ ì
ááááááááápiecσá oµ politeness¼áiε thσ "Waitinτ .«á ó messagσ ì
áááááááááwheε yo⌡ DISPLA┘ AL╠ record≤ iε ß file«á I⌠á mean≤ ì
ááááááááátha⌠ thσ use≥ caε reaΣ thσ displa∙ witΦ ease¼ rath-ì
áááááááááe≥á thaε havinτ i⌠ scrol∞ u≡ thσ screeε a⌠ ßá speeΣ ì
ááááááááátoo fast for him to read.
Yo⌡ wil∞ noticσ witΦ thi≤ listinτ tha⌠ thσ screeε displa∙ doe≤á no⌠ ì
indicatσ whethe≥ o≥ no⌠ ß recorΣ ha≤ beeε markeΣ fo≥ deletion« Tha⌠ littlσ ì
good∙ wil∞ come¼á bu⌠ we'vσ reserveΣ i⌠ fo≥ thσ nex⌠ procedure¼á whicΦ wil∞ ì
finΣ ß particula≥ item¼ anΣ displa∙ i⌠ nicel∙ oε thσ screen.
Wσ wil∞ neeΣ t∩ adΣ t∩ thσ INVENT.PA╙ codσ thσ followinτ changes
a) in the Menu array contents
MenuList[9] := ' 8 : List on screen all items of stock');
b) in the 'Case Item of' block
8 : Listem;è Somσá peoplσ havσ askeΣ mσ t∩ recommenΣ ß gooΣ Pasca∞ tex⌠á book«á Thσ ì
onσá ╔ havσ founΣ mos⌠ helpfu∞ i≤ Koffman'≤ "Probleφ Solvinτ anΣ StructureΣ ì
Programminτá iε Pascal"¼á publisheΣ b∙ Addison-Wesley«á I⌠ i≤ writteεá fo≥ ì
Pasca∞ oε ß largσ computer¼á anΣ somσ oµ thσ nicσ function≤ whicΦ appea≥ iε ì
TurboPasca∞á - fo≥á example¼á thσ String[▌ definition≤ - d∩ no⌠á appea≥á iε ì
these¼á generall∙ older¼á versions« Thσ booδ assume≤ tha⌠ al∞ strinτ inpu⌠ ì
wil∞á bσá deal⌠ witΦ oε ß character-by-characte≥ basis¼á rathe≥ thaεá oεá ß ì
characte≥ strinτ basis¼á a≤ wσ caε iε Turb∩ Pascal«á Nonetheless¼ thσ booδ ì
certainl∙ explain≤ thing≤ iε ß ver∙ clea≥ way«á TurboPasca∞ i≤ ver∙á closσ ì
t∩ UCS─ Pascal¼á s∩ book≤ writteε abou⌠ tha⌠ dialec⌠ oµ thσ languagσ ma∙ bσ ì
oµ use¼á althougΦ al∞ text≤ wil∞ bσ oµ somσ help¼ a≤ thσ basiπ structurσ oµ ì
Pasca∞ i≤ thσ same¼ n∩ matte≥ wha⌠ thσ dia-lec⌠ chosen« Thσ variou≤ Pasca∞ ì
dialect≤á arσá certainl∙á morσ closel∙ relateΣ t∩ eacΦ othe≥ thaεá arσá thσ ì
variou≤ Basiπ dialects«
END OF PART EIGHT.