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

  1.                       PASCAL  FOR  BASIC  PROGRAMMERS
  2.  
  3.                                Dixon Kenney
  4.  
  5.                                   PART  V
  6.  
  7.      Iεá thi≤ episodσ oµ ou≥ excitinτ seria∞ ¿ o≥ maybσ it'≤ a≤ un-invitinτ ì
  8. a≤ cerea∞ t∩ yo⌡ !⌐ wσ arσ leavinτ thσ Bankinτ program¼á anΣ movinτ oε int∩ ì
  9. ne≈á ground«á  Wσá arσ introducinτ thσ concep⌠ oµ ßá pro-cedure¼á thσá CAS┼ ì
  10. statement¼á anΣ ß differen⌠ kinΣ oµ loop¼á onσ whicΦ i≤ unavailablσ iεá BE┼ ì
  11. BASIC.
  12.  
  13.      Here'≤á thσ codσ oµ thσ program¼á which¼á a≤ yo⌡ caε see¼á i≤ thσá be-ì
  14. ginninτ oµ ß stock-contro∞ program«á  Wσ won'⌠ ge⌠ to∩ fa≥ witΦ it¼á bu⌠ i⌠ ì
  15. ma∙ givσ yo⌡ somσ gooΣ ideas.
  16.  
  17.      Thi≤á codσá doe≤á no⌠ underlinσ reserveΣ words¼á a≤ wσá havσá donσá iε ì
  18. previou≤ listings«  The∙ arσ no⌠ normall∙ underlineΣ wheε codσ i≤ written.
  19.  
  20.  1ááPrograφ Inventory;
  21.  
  22.  3ááType
  23.  4áá  St3░ ╜ String[30];
  24.  
  25.  6ááConst
  26.  7áá  MenuItem≤ ╜ 10;
  27.  
  28.  9ááVar
  29. 10áá  MenuLis⌠ ║ Arra∙ █ ░ .« 1╡ ▌ oµ St30;
  30. 11áá  Iteφ     ║ Integer;
  31. 12áá  Loope≥   ║ Boolean;
  32.  
  33. 14ááááááá√ **¬ Thi≤ i≤ thσ beginninτ oµ ß procedurσ **¬ }
  34.   
  35. 16áááááááProcedurσ MenuWritσ ;
  36.   
  37. 18áááááááVar
  38. 19ááááááá  ╔ ║ Integer;
  39.   
  40. 21áááááááBegin
  41. 22ááááááá  ClrScr;
  42. 23ááááááá  Writeln╗ Writeln;
  43. 24ááááááá  Writeln(º ':20¼ MenuList[0]);
  44. 25ááááááá  Writeln╗ Writeln;
  45. 26ááááááá  Fo≥ ╔ :╜ ▒ t∩ MenuItem≤ do
  46. 27ááááááá      Writeln(º ':10,MenuList[I]);
  47. 28áááááááEnd╗   √ Procedurσ MenuWritσ }
  48.   
  49. 30ááááááá√ **¬ End of procedure for this program }
  50.  
  51. 32ááBegin
  52.   
  53. 34áá  Loope≥      :╜ True;
  54. 36áá  MenuList[0▌ :╜ 'MASTE╥ INVENTOR┘ MENU';
  55. 37áá  MenuList[1▌ :╜ º  0║  Qui⌠ thσ Program';
  56. 38áá  MenuList[2▌ :╜ º  1║  Ente≥ ß ne≈ iteφ t∩ thσ list';
  57. 39áá  MenuList[3▌ :╜ º  2║  Deletσ aε iteφ froφ thσ list';
  58. 40áá  MenuList[4▌ :╜ º  3║  Edi⌠ aε existinτ item';
  59. 41áá  MenuList[5▌ :╜ º  4║  Quer∙ aε existinτ item';è42áá  MenuList[6▌ :╜ º  5║  Lis⌠ item≤ belo≈ re-orde≥ level';
  60. 43áá  MenuList[7▌ :╜ º  6║  Sale≤ transaction';
  61. 44áá  MenuList[8▌ :╜ º  7║  Purchasσ transaction';
  62. 45áá  MenuList[9▌ :╜ º  8:';
  63. 46áá  MenuList[10]:╜ º  9║  Star⌠ ß ne≈ file';
  64.   
  65. 48ááRepeat
  66.   
  67. 50áá  MenuWrite;
  68.   
  69. 52áá  Writeln;
  70. 53áá  Write('Typσ iε numbe≥ oµ actioε desireΣ ║ ');
  71. 54áá  Readln(Item);
  72.  
  73. 56áá    Casσ Iteφ of
  74. 57áá      0║ Halt;
  75. 58áá      1║ Begiε Writeln('Iteφ 1')╗  Delay(2000⌐ End;
  76. 59áá      2║ Begiε Writeln('Iteφ 2')╗  Delay(2000⌐ End;
  77. 60áá      3║ Begiε Writeln('Iteφ 3')╗  Delay(2000⌐ End;
  78. 61áá      4║ Begiε Writeln('Iteφ 4')╗  Delay(2000⌐ End;
  79. 62áá      5║ Begiε Writeln('Iteφ 5')╗  Delay(2000⌐ End;
  80. 63áá      6║ Begiε Writeln('Iteφ 6')╗  Delay(2000⌐ End;
  81. 64áá      7║ Begiε Writeln('Iteφ 7')╗  Delay(2000⌐ End;
  82. 65áá      8║ Delay(2000);
  83. 66áá      9║ Begiε Writeln('Iteφ 9')╗  Delay(2000⌐ End;
  84. 67áá    Else
  85. 68áá      Begin
  86. 69áá        Writeln╗ Writeln;
  87. 70áá        Writeln(º ':20,'N∩ actioε possiblσ fo≥ typeΣ input');
  88. 71áá        Writeln(º ':30,'Typσ ß valiΣ number');
  89. 72áá        Delay(2000)
  90. 73áá      EnΣ      √ Elsσ ..}
  91. 74áá    End╗   √ Casσ Iteφ ..« }
  92.   
  93. 76áá  Unti∞ Loope≥ ╜ False;
  94.   
  95. 78ááEnd.
  96.  
  97.      Firs⌠ oµ all¼á noticσ line≤ │ anΣ 4«  Iε previou≤ programs¼ we'vσ useΣ ì
  98. thσ concep⌠ oµ ß strinτ declaratioε - eg¼ iε Par⌠ I╔ :
  99.  
  100.                           CustName := String[20];
  101.  
  102. wherσá thi≤á versioεá oµá Pasca∞ declare≤ ß strinτ oµ character≤á t∩á bσá ß ì
  103. certaiε maximuφ length.
  104.  
  105.      We'vσ alread∙ me⌠ datß type≤ sucΦ a≤ Integer¼ Booleaε anΣ Real«  Thesσ ì
  106. arσá PRE-DEFINE─ iε PASCAL¼á jus⌠ likσ numeriπ anΣ strinτ type≤á iεá BASIC«  ì
  107. Therσá i≤ anothe≥ pre-defineΣ typσ - CHA╥ (which¼á a≤ yo⌡ ma∙ guess¼á i≤á ß ì
  108. "characteróá type)«á  ┴á variablσ oµ typσ CHA╥ i≤ an∙ onσ oµ thσá printablσ ì
  109. ASCI╔á character≤á whicΦá thσá compute≥ use≤ - i⌠á ma∙á  bσá aεá alphabetiπ ì
  110. character¼á ß numeriπ digit¼á ß punctuatioε mark«á  Wheε i⌠ i≤ defined¼á i⌠ ì
  111. look≤ somethinτ likσ thi≤ -
  112.  
  113.                          Const       Dash = '-';
  114.                          Var         NextLetter : Char;
  115.  
  116.  
  117. è     Thσá constan⌠  declaratioε i≤ equivalen⌠ t∩á BASIC'≤á A1$="-"╗á noticσ ì
  118. tha⌠á iεá PASCAL¼á singlσá quote≤ arσ useΣ arounΣá thσá character(s⌐á beinτ ì
  119. assigneΣá t∩á thσ variablσ label«á  However¼á thσ variablσá NextLette≥á caε ì
  120. consis⌠á oµá onl∙ ON┼ character¼á whateve≥ i⌠ ma∙ be¼á sincσ typσá CHA╥á i≤ ì
  121. defineΣ a≤ consistinτ oµ onσ character.
  122.  
  123.      Mos⌠ version≤ oµ PASCA╠ founΣ oε micro≤ definσ ß STRING[▌ type¼á whicΦ ì
  124. i≤á reall∙ aε arra∙ oµ characters«á  Iε Turb∩ Pascal¼á ß STRING[▌ typσá caε ì
  125. var∙á dynamicall∙ iε lengtΦ betweeε ░ anΣ thσ defineΣ uppe≥ limi⌠ - iε thi≤ ì
  126. i⌠ differ≤ froφ aε array¼ iε whicΦ thσ numbe≥ oµ element≤ i≤ fixed«  S∩ ou≥ ì
  127. defineΣ strinτ "CustNameó abovσ caε havσ betweeε ░ anΣ 2░ character≤ iε it«  ì
  128. Thσ longes⌠ strinτ caε bσ 25╡ character≤ iε length¼ jus⌠ a≤ iε BASIC.
  129.  
  130.      Iµ wσ wan⌠ t∩ usσ ß lo⌠ oµ string≤ oµ characters¼á wσ caε definσ ß ne≈ ì
  131. datß type«á  Herσ iε line≤ │ anΣ 4¼ thσ ne≈ typσ i≤ ß strinτ oµ characters¼ ì
  132. whicΦ caε havσ ß maximuφ lengtΦ oµ 30«á  We'vσ calleΣ thσ typσ St3░ ¿ whicΦ ì
  133. mean≤á "Strinτ oµ 3░ characters"¼á naturall∙ )«á  So¼á alongsidσá integers¼ ì
  134. reals¼á boolean≤ anΣ chars¼ wσ no≈ havσ ß ne≈ type¼ defineΣ b∙ us¼ whicΦ i≤ ì
  135. ß strinτ oµ 3░ characters«á  Iε linσ 10¼ wσ caε se⌠ u≡ aε array¼ usinτ thi≤ ì
  136. ne≈ type«  Wσ mus⌠ definσ thσ arra∙ iε thi≤ way¼ rathe≥ thaε a≤ ARRA┘ .« O╞ ì
  137. STRING[30]¼á sincσá thσá arra∙ mus⌠ bσ defineΣ a≤ ßá defineΣá TYPE¼á eithe≥ ì
  138. predefineΣ b∙ TP¼ o≥ defineΣ b∙ u≤ a≤ wσ havσ donσ i⌠ here.
  139.  
  140.      Thi≤ arra∙ i≤ defineΣ a≤ ß one-dimensiona∞ array¼ containinτ 1╢ items«  ì
  141. I⌠ i≤ equivalen⌠ t∩ ß BASI├ arra∙ dimensioneΣ a≤ A1$(16⌐ - althougΦá that'≤ ì
  142. no⌠á quitσ ho≈ it'≤ dimensioneΣ iε Beσ BASIC¼á oµ course«á  EacΦ elemen⌠ iε ì
  143. thi≤ arra∙ i≤ ß strinτ oµ no⌠ morσ thaε 3░ characters.
  144.  
  145.      Iε linσ 1▓ wσ definσ ß variablσ a≤ ß Booleaε datß type«  Thi≤ typσ caε ì
  146. takσ onl∙ thσ value≤ Truσ o≥ False¼á anΣ i≤ generall∙ useΣ fo≥ sucΦá thing≤ ì
  147. a≤á settinτá flags«á  Ofteεá iε BASIC¼á wσ equatσ ░ t∩ Falsσ anΣá -▒á ¿á o≥ ì
  148. sometime≤á +▒á ⌐ t∩ True¼á anΣ se⌠ ß variablσ t∩ bσ onσ o≥ othe≥á oµá thesσ ì
  149. value≤ t∩ ac⌠ a≤ ß flag«á  Iε fact¼ wha⌠ wσ arσ doinτ iε BASI├ i≤ writinτ ß ì
  150. numeriπá equivalen⌠ oµ ß PASCA╠ Booleaε variable«á  Iµ yo⌡ looδ a⌠ line≤ 3┤ ì
  151. anΣ 76¼ you'l∞ seσ thσ variablσ iε use.
  152.  
  153.      Iε line≤ 14-3░ wσ definσ ß Procedure«  ┴ Procedurσ iε Pasca∞ i≤ likσ ß ì
  154. GOSU┬ subroutinσ iε BASIC«á  Likσ sucΦ ß routinσ iε Beσ BASIC¼ yo⌡ caε pas≤ ì
  155. parameter≤ betweeε thσ maiε bod∙ oµ codσ anΣ thσ procedurσ iµ yo⌡ wan⌠á to«  ì
  156. However¼á therσá i≤ onσ biτ difference¼á whicΦ yo⌡ mus⌠ gras≡ holΣ of«á  Iε ì
  157. PASCAL¼ iµ yo⌡ declarσ ß variablσ iε thσ procedure¼ sucΦ a≤ wσ havσ donσ iε ì
  158. linσ 19¼á theε tha⌠ variablσ caε bσ useΣ ONL┘ INSID┼ TH┼ PROCEDUR┼ iε whicΦ ì
  159. i⌠á i≤á declared«á  I⌠ i≤ calleΣ ß LOCA╠ variable¼á iε distinctioεá t∩á an∙ ì
  160. variablσ declareΣ iε thσ maiε bod∙ oµ thσ program¼á whicΦ arσ calleΣ GLOBA╠ ì
  161. variables«  Iε mos⌠ version≤ oµ BASIC¼ al∞ variable≤ arσ GLOBAL.
  162.  
  163.      Iεá ou≥á procedure¼á wσ declarσ ß variablσ labelleΣ I«á  Iµ wσá haΣá ß ì
  164. simila≥á declaratioεá iε linσ 11¼á PASCA╠ woulΣ seσ thσ Globa∞á variablσá ╔ ì
  165. declareΣá iεá linσ 1▒ anΣ thσ Loca∞ variablσ ╔ declareΣ iε linσ 1╣á a≤á tw∩ ì
  166. totall∙ DIFFEREN╘ variables«á  The∙ arσ helΣ a⌠ differen⌠ addresse≤ iεá thσ ì
  167. computer'≤ memory¼ anΣ therσ i≤ n∩ wa∙ tha⌠ thσ compile≥ wil∞ confusσ them.
  168.  
  169.      Procedure≤á iε PASCA╠ arσ declareΣ BEFOR┼ thσ maiε bod∙ oµ thσ prograφ ì
  170. - therσá i≤á n∩ choicσ iε thσ matter¼á a≤ therσ i≤á iεá BASIC¼á wherσá sub-ì
  171. routine≤ caε bσ writteε anywherσ yo⌡ fancy«á  Thi≤ particula≥ procedurσ ha≤ ì
  172. n∩ parameter≤ passeΣ t∩ it.
  173.  
  174.  
  175. è     Therσ i≤ n∩ equivalen⌠ t∩ ß READ/DAT┴ BASI├ statemen⌠ iε PASCAL«á  Thσ ì
  176. onl∙ wa∙ t∩ assigε value≤ t∩ aε array¼á sucΦ a≤ wσ wan⌠ t∩ d∩ here¼á i≤á t∩ ì
  177. writσ i⌠ ou⌠ a≤ wσ havσ donσ iε line≤ 3╢ t∩ 46.
  178.  
  179.      Iε line≤ 4╕ t∩ 7╢ wσ havσ ß loop«á  Thi≤ i≤ ß REPEA╘ - UNTI╠ loop«  I⌠ ì
  180. i≤á differen⌠ froφ ß D╧ - WHIL┼ loop¼á iε tha⌠ thσ conditioε i≤ no⌠á testeΣ ì
  181. unti∞á thσ UNTI╠ statemen⌠ i≤ reached«á  Thi≤ mean≤ tha⌠ thσ loo≡ i≤ alway≤ ì
  182. executeΣá once«á  Iεá thi≤á case¼á i⌠ wil∞ bσ repeateΣá unti∞á thσá Booleaε ì
  183. variablσá "Looperó i≤ se⌠ t∩ False«á  Iε fact¼á thi≤ i≤ neve≥ donσ iεá thi≤ ì
  184. program¼á anΣá wσ havσ createΣ aε endles≤ loop«á  Normally¼á iε ßá program¼ ì
  185. therσ woulΣ bσ aε elegan⌠ wa∙ t∩ breaδ ou⌠ oµ sucΦ ß loop¼ whereb∙ "Looperó ì
  186. i≤ se⌠ t∩ True«á  Here¼ i⌠ i≤ optioε "0ó oµ thσ menu«  dBAS┼ I╔ enthusiast≤ ì
  187. migh⌠ bσ remindeΣ herσ oµ thσ loo≡ "D╧ WHIL┼ ╘ .« ENDDO".
  188.  
  189.      Noticσá iεá linσá 5░ ho≈ thσ Procedurσ i≤á calleΣá oεá fo≥á execution«  ì
  190. Simpl∙ b∙ usinτ thσ Procedure'≤ name¼ whicΦ thσ prograφ knows¼ sincσ i⌠ wa≤ ì
  191. defineΣ beforσ i⌠ wa≤ called¼ tha⌠ Procedurσ i≤ executed«  Somσ version≤ oµ ì
  192. BASI├ arσ ablσ t∩ calleΣ sub-routine≤ b∙ name¼á rathe≥ thaε G╧ SUBbinτ t∩ ß ì
  193. linσ number.
  194.  
  195.      Iεá line≤á 5╢á t∩ 74¼á wσ havσ ß CAS┼ statement«á  Thi≤á i≤á simpl∙á ß ì
  196. differen⌠ wa∙ oµ writinτ multiplσ I╞ .«á THENs«á  Wσ coulΣ havσ writteε thσ ì
  197. codσ a≤ -
  198.  
  199.      If Item = 0 then Halt
  200.      Else if Item = 1 then Begin .. End
  201.      Else if Item = 2   ....   and so on.
  202.  
  203.      Thi≤á i≤á ßá mucΦ easie≥ wa∙ t∩ writσ ßá multiplσá choicσá conditiona∞ ì
  204. statement«á  Noticσá tha⌠ iε TURB╧ PASCAL¼á Casσ statement≤ arσ alloweΣá aε ì
  205. ELS┼ clause¼á whicΦ simpl∙ mean≤ ó ..«á iε an∙ othe≥ case¼á d∩ thi≤ ..«á "«  ì
  206. Notice¼á too¼á tha⌠ thσ variablσ Iteφ froφ linσ 5┤ i≤ useΣ iε linσ 5╢ afte≥ ì
  207. thσ reserveΣ worΣ CASE«á  Then¼ iε ß list¼ arσ thσ allow-ablσ value≤ i⌠ caε ì
  208. takσ - ▒ througΦ ╣ - followeΣ b∙ thσ ELSE.
  209.  
  210.      Thσá verΓá DELA┘á stop≤á executioε fo≥ thσ defineΣá numbe≥á oµá milli-ì
  211. seconds«  Thi≤ numbe≥ mus⌠ bσ aε integer«  Iε Beσ BASIC¼ yo⌡ woulΣ probabl∙   ì
  212. PLA┘ 0,1╢   t∩ gaiε aε equivalen⌠ effect«  Thσ verΓ HALT¼ iε linσ 57¼ i≤ iε ì
  213. fac⌠ ß predefineΣ procedure¼ equivalen⌠ t∩ BASIC'≤ EN─ verb.
  214.  
  215.      Thi≤á i≤á aε eas∙ wa∙ t∩ develo≡ ß prograφ witΦ ßá menu«á  Thσá actioε ì
  216. takeε iε eacΦ casσ herσ i≤ simpl∙ t∩ prin⌠ ou⌠ oε thσ VD╘ thσ numbe≥ oµ thσ ì
  217. iteφá chosen«á  Thi≤ i≤ ß calleΣ ß men⌡ "stubó - wheε thσ routinσ fo≥á tha⌠ ì
  218. actioε i≤ codeΣ anΣ debugged¼á it≤ procedurσ cal∞ wil∞ bσ sub-stituteΣá fo≥ ì
  219. thσ stub¼á and¼ sincσ botΦ men⌡ anΣ procedurσ arσ correct¼ therσ wil∞ bσ n∩ ì
  220. neeΣ fo≥ furthe≥ testing«  You'l∞ notice¼ too¼ ho≈ ß sequencσ oµ statement≤ ì
  221. caε bσ writteε oε onσ line¼á as¼á fo≥ example¼ iε linσ 58¼ jus⌠ a≤ iε BASI├ ì
  222. wσ caε havσ ß multi-statemen⌠ line.
  223.  
  224.                              END OF PART FIVE.