home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug003.arc / PASCAL.008 < prev    next >
Text File  |  1979-12-31  |  8KB  |  190 lines

  1.                     PASCAL   FOR   BASIC   PROGRAMMERS
  2.  
  3.                                Dixon Kenney
  4.  
  5.                                  PART VIII              
  6.  
  7.     Iεá thi≤á article¼á wσá arσá goinτ t∩ adΣ ß ne≈á procedurσá t∩á ou≥ ì
  8. Inventor∙ program«á  Thi≤ prograφ wil∞ lis⌠ al∞ thσ item≤ oµ ou≥á database«  ì
  9. Iε orde≥ t∩ usσ thσ databasσ later¼á wσ arσ als∩ goinτ t∩ adΣ anothe≥ fielΣ ì
  10. t∩ thσ record¼ s∩ tha⌠ i⌠ wil∞ no≈ looδ likσ thi≤ -
  11.  
  12. áááááááááááááá  PartReπ ╜ Record
  13. áááááááááááááá    PartNuφ      ║ 100░ .« 9999;
  14. áááááááááááááá    Descriptioε  ║ St20;
  15. áááááááááááááá    Cos⌠         ║ Real;
  16. áááááááááááááá    Retai∞       ║ Real;
  17. áááááááááááááá    MinO╚        ║ Integer;
  18. áááááááááááááá    MaxReorde≥   ║ Integer;
  19. áááááááááááááá    CurrentO╚    ║ Integer;
  20. áááááááááááááá    DeleteΣ      ║ Boolean;
  21. áááááááááááááá End;
  22.  
  23. Thσá ne≈ fielΣ i≤ thσ las⌠ one¼á whicΦ wil∞ bσ useΣ t∩ marδ ß recorΣ iµá wσ ì
  24. wan⌠á t∩á deletσ i⌠ froφ thσ database«á  A⌠ datß entry¼á i⌠ wil∞ bσ se⌠á t∩ ì
  25. false«  T∩ d∩ this¼ alte≥ thσ listinτ oµ "NEWITEM.PROó t∩ looδ likσ thi≤ -
  26.  
  27.         GoToXY(32,11); Read(MaxReorder);
  28.         GoTOXY(32,13); Read(CurrentOH);
  29.         Deleted := False;
  30.         Write(PartFile, Part)
  31.     End;
  32.  
  33. The addition is the line which sets the field "Deleted" to False.
  34.  
  35.      Herσá i≤á thσ listinτ fo≥ thσ procedurσ whicΦ list≤ al∞ thσá item≤á oµ ì
  36. stocδ oε thσ screeε :
  37.  
  38. áááááProcedurσ Listem;
  39.  
  40. áááááConst
  41. ááááá  Heade≥      ╜ º ¬ LISTIN╟ O╞ AL╠ ITEM╙ O╞ STOC╦ ¬ ';
  42. ááááá  ScreenLine≤ ╜ 15;
  43.  
  44. áááááVar
  45. ááááá  YesN∩       ║ Char;
  46. ááááá  Ro≈         ║ Integer;
  47.  
  48. áááááBegin
  49.  
  50. ááááá  Assign(PartFile,FileName);
  51. ááááá  Reset(PartFile);
  52.  
  53. ááááá  ClrScr;
  54. ááááá  Writeln(º ':20¼ Header);
  55. ááááá  Write('Iteφ #':6,º       Description':22,º    Cost':10);
  56. ááááá  Writeln(º  Retail':10,'Minimum':8,'Maximum':8,'Oε Hand':8);
  57. ááááá  Writeln;
  58.  
  59. ááááá  Ro≈ :╜ 0;èááááá  Whilσ no⌠ EOF(PartFile⌐ do
  60. ááááá    Begin
  61. ááááá    Read(PartFile,Part);
  62. ááááá    WitΦ Par⌠ do
  63. ááááá      Begin
  64. ááááá      Write(PartNum:6,Description:22,Cost:10:2,Retail:10:2);
  65. ááááá      Writeln(MinOH:8,MaxReorder:8,CurrentOH:8);
  66. ááááá      Ro≈ :╜ Succ(Row);
  67.  
  68. ááááá      Iµ Ro≈ ╜ ScreenLine≤ then
  69. ááááá        Begin
  70. ááááá          Writeln;
  71. ááááá          Write('Pres≤ <RETURN> t∩ continue');
  72. ááááá          Readln(YesNo);
  73. ááááá          Ro≈ :╜ 0
  74. ááááá      EnΣ     √ oµ Iµ Ro≈ }
  75. ááááá    EnΣ       √ oµ WitΦ Par⌠ D∩ }
  76. ááááá  End╗        √ oµ Whilσ No⌠ EO╞ }
  77.  
  78. ááááá  Close(PartFile);
  79.  
  80. ááááá  Writeln;
  81. ááááá  Write('Typσá <RETURN╛á ke∙á wheε yo⌡ havσá finisheΣá witΦá thi≤ ì
  82. ááááádispla∙ ');
  83. ááááá  Readln(YesNo);
  84.  
  85. áááááEnd╗           √ oµ Procedurσ Listeφ }
  86.  
  87. The skeleton of this procedure looks like this -
  88.  
  89. 1    Open the File, and put the record pointer to zero.
  90. 2    Clear the Screen, and write the column headers on it.
  91. 3    a    Get a record from the disk
  92.      b    Write it to the screen
  93.      c    If the screen is full ( by calculation a fixed number
  94.           of records, called ScreenLines ), pause until the
  95.           user presses a key.
  96. 4    When the file is fully listed, wait until the user types
  97.      a key, and then return to the Main Menu.
  98.  
  99. Comments on this procedure -
  100.  
  101.                       While Not EOF(Partfile) do
  102.  
  103.     Thi≤ forma⌠ create≤ ß loop«á  Thi≤ i≤ onσ oµ thσ │ type≤ oµ loopinτ ì
  104. o≥ repetitivσ statement≤ availablσ iε Pascal«á  Wσ havσ seeε thσ othe≥á tw∩ ì
  105. alread∙ - thσ 'FO╥ ° :╜ bottoφ t∩ to≡ doº type¼á anΣ thσ 'REPEA╘ .«á UNTILº  ì
  106. type«  Thi≤ presen⌠ typσ ha≤ thσ format
  107.  
  108.           While < condition > do [ Begin .... End ]
  109.  
  110.     Thσá conditioεá i≤ evaluateΣ a⌠ thσ beginninτ oµá thσá loop«á  Thi≤ ì
  111. mean≤á tha⌠á thσ loo≡ ma∙ no⌠ bσ executeΣ a⌠ all¼á sincσ thσ conditioεá ma∙ ì
  112. turε ou⌠ t∩ bσ falsσ beforσ thσ loo≡ i≤ entered« Thσ blocδ i≤ markeΣ b∙ thσ ì
  113. usua∞ Begiε anΣ EnΣ iµ morσ thaε onσ statemen⌠ i≤ presen⌠ iε it.
  114.  
  115.  
  116.  
  117. è     Thσá functioε EOF(filevariable⌐ i≤ ß Booleaε function¼á whicΦá return≤ ì
  118. thσ valuσ TRU┼ iµ thσ recorΣ pointe≥ i≤ a⌠ thσ EO╞ marker¼á beyonΣ thσ las⌠ ì
  119. componen⌠á oµ thσ filσ itself«á  S∩ "Whilσ no⌠ EOF(..)ó mean≤ "executσá thσ ì
  120. blocδá whilσ thσ recorΣ pointe≥ stil∞ point≤ t∩ ß recorΣ iε thσá file¼á anΣ ì
  121. sto≡ a≤ sooε a≤ i⌠ read≤ thσ EO╞ marke≥ a⌠ thσ enΣ oµ thσ file."
  122.  
  123.                           Write ( ... :m:n )
  124.  
  125.     Wheεá yo⌡ arσ writinτ something¼á yo⌡ caε definσ thσ widtΦá oµá thσ ì
  126. fielΣá t∩á writσ i⌠ iε b∙ addinτ ß coloε anΣ aε intege≥ whicΦá define≤á thσ ì
  127. numbe≥á oµ characte≥ space≤ i⌠ wil∞ takσ up«á  Thi≤ ":mó ma∙ bσ appendeΣ t∩ ì
  128. eithe≥ ß variablσ labe∞ o≥ ß string¼ a≤ yo⌡ seσ we'vσ donσ here¼ firstl∙ iε ì
  129. thσá columε headers¼á anΣ secondl∙ iε thσ actua∞ recorΣ contents«á  Iµá thσ ì
  130. numbe≥ whicΦ i≤ beinτ printeΣ i≤ ß rea∞ number¼á theε yo⌡ caε adΣ ßá seconΣ ì
  131. fielΣ widtΦ number¼ a≤ wσ havσ donσ fo≥ Cos⌠ anΣ Retai∞ here¼ whicΦ define≤ ì
  132. thσ numbe≥ oµ column≤ useΣ fo≥ decima∞ fractioε digits«á  S∩ herσ Cos⌠ wil∞ ì
  133. bσá iε ß fielΣ 1░ characte≥ space≤ wide¼á tw∩ oµ whicΦ wil∞ bσ useΣ fo≥ thσ ì
  134. decima∞á fractioεá digit≤ ¿ thσ cent≤ )¼á anΣ onσ fo≥á thσá decima∞á point¼ ì
  135. leavinτ ╖ fo≥ thσ actua∞ intege≥ numbe≥ ¿ thσ dollar≤ ).
  136.  
  137.                            Row := Succ(Row)
  138.  
  139.     Thσá functioεá Succ(x⌐á return≤á thσá valuσá whicΦá thσá T╨á manua∞ ì
  140. describe≤á a≤ thσ "successoró oµ x¼á iµ i⌠ exists«á  ° mus⌠ bσ oµ ßá scala≥ ì
  141. type«  Here¼ ° i≤ aε integer«  Iµ ° ha≤ thσ valuσ oµ 1¼ it≤ successo≥ i≤ 2«  ì
  142. Iε fact¼á wσ havσ herσ aε alternativσ t∩ ° :╜ ° ½ 1«á  Bu⌠ thσ functioε caε ì
  143. bσ useΣ iε an∙ scala≥ type¼ excep⌠ REAL.
  144.  
  145.      Iµá thσá typσ Weeδ wa≤ ß scala≥ typσ defineΣ a≤á thσá value≤á (Monday¼ ì
  146. Tuesday¼á Wednesday¼ Thursday¼ Friday¼ Saturday¼ Sunday)¼ theε Succ(Monday⌐ ì
  147. i≤ Tuesday.
  148.  
  149.                          If Row = ScreenLines
  150.  
  151.     Thi≤á littlσá blocδ simpl∙ count≤ thσ numbe≥ oµ record≤ printeΣá oε ì
  152. thσ screen¼á and¼ wheε tha⌠ numbe≥ equal≤ ß predefineΣ number¼ halt≤ outpu⌠ ì
  153. unti∞ thσ use≥ presse≤ thσ returε key«  
  154.  
  155. áááááááááUser≤ oµ dBAS┼ I╔ wil∞ bσ familia≥ witΦ thi≤ littlσ ì
  156. ááááááááápiecσá oµ politeness¼áiε thσ "Waitinτ .«á ó messagσ ì
  157. áááááááááwheε yo⌡ DISPLA┘ AL╠ record≤ iε ß file«á  I⌠á mean≤ ì
  158. ááááááááátha⌠ thσ use≥ caε reaΣ thσ displa∙ witΦ ease¼ rath-ì
  159. áááááááááe≥á thaε havinτ i⌠ scrol∞ u≡ thσ screeε a⌠ ßá speeΣ ì
  160. ááááááááátoo fast for him to read.
  161.  
  162.     Yo⌡ wil∞ noticσ witΦ thi≤ listinτ tha⌠ thσ screeε displa∙ doe≤á no⌠ ì
  163. indicatσ whethe≥ o≥ no⌠ ß recorΣ ha≤ beeε markeΣ fo≥ deletion«  Tha⌠ littlσ ì
  164. good∙ wil∞ come¼á bu⌠ we'vσ reserveΣ i⌠ fo≥ thσ nex⌠ procedure¼á whicΦ wil∞ ì
  165. finΣ ß particula≥ item¼ anΣ displa∙ i⌠ nicel∙ oε thσ screen.
  166.  
  167.      Wσ wil∞ neeΣ t∩ adΣ t∩ thσ INVENT.PA╙ codσ thσ followinτ changes
  168.  
  169.      a) in the Menu array contents
  170.  
  171.           MenuList[9] := ' 8 : List on screen all items of stock');
  172.  
  173.      b) in the 'Case Item of' block
  174.  
  175.           8 : Listem;è     Somσá peoplσ havσ askeΣ mσ t∩ recommenΣ ß gooΣ Pasca∞ tex⌠á book«á Thσ ì
  176. onσá ╔ havσ founΣ mos⌠ helpfu∞ i≤ Koffman'≤ "Probleφ Solvinτ anΣ StructureΣ ì
  177. Programminτá iε Pascal"¼á publisheΣ b∙ Addison-Wesley«á  I⌠ i≤ writteεá fo≥ ì
  178. Pasca∞ oε ß largσ computer¼á anΣ somσ oµ thσ nicσ function≤ whicΦ appea≥ iε ì
  179. TurboPasca∞á - fo≥á example¼á thσ String[▌ definition≤ - d∩ no⌠á appea≥á iε ì
  180. these¼á generall∙ older¼á versions«  Thσ booδ assume≤ tha⌠ al∞ strinτ inpu⌠ ì
  181. wil∞á bσá deal⌠ witΦ oε ß character-by-characte≥ basis¼á rathe≥ thaεá oεá ß ì
  182. characte≥ strinτ basis¼á a≤ wσ caε iε Turb∩ Pascal«á  Nonetheless¼ thσ booδ ì
  183. certainl∙ explain≤ thing≤ iε ß ver∙ clea≥ way«á  TurboPasca∞ i≤ ver∙á closσ ì
  184. t∩ UCS─ Pascal¼á s∩ book≤ writteε abou⌠ tha⌠ dialec⌠ oµ thσ languagσ ma∙ bσ ì
  185. oµ use¼á althougΦ al∞ text≤ wil∞ bσ oµ somσ help¼ a≤ thσ basiπ structurσ oµ ì
  186. Pasca∞ i≤ thσ same¼ n∩ matte≥ wha⌠ thσ dia-lec⌠ chosen«  Thσ variou≤ Pasca∞ ì
  187. dialect≤á arσá certainl∙á morσ closel∙ relateΣ t∩ eacΦ othe≥ thaεá arσá thσ ì
  188. variou≤ Basiπ dialects«    
  189.  
  190.                             END OF PART EIGHT.