home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / A / AxoCalculator Package / AxoCalculator Documentation / Programming in Pascal / Example Programs < prev    next >
Encoding:
Text File  |  1993-03-14  |  5.4 KB  |  194 lines  |  [TEXT/AxoC]

  1. LocalLanguage Pascal
  2. { -------------------------------------------------
  3.  
  4.   The following 7 programs demonstrate various aspects of 
  5.   AxoCalculator's Pascal programming language. 
  6.  
  7. •  To load all 7 programs, choose "Select All" under 
  8.     the "Edit" menu, then press "enter". 
  9.  
  10. •  To run a program, either select it under the 
  11.     "Calculator" menu, or type its name and press "enter".
  12.  
  13. •  After the programs are loaded, this file does not need
  14.     to remain open in order to use them.
  15.  
  16. --------------------------------------------------}
  17.  
  18. { ----------------- Global Variables  ------------------
  19.   The following 3 lines demonstrate how to declare
  20.   global variables. See "The Programming Language" for more
  21.   on variable declaration. Because global "Real" 
  22.   variables can be created on the fly, global
  23.   declarations will most commonly be used for creating
  24.   "Boolean", "Integer" or "Array" variables. 
  25. -----------------------------------------------------}
  26. var
  27.     i : Integer
  28.     globalArr : Array[1..10]
  29.  
  30.  
  31. { ------------------- DoCount -----------------------
  32.   A very simple program which counts to 10.
  33.   It demonstrates how to declare a program, and assign it a 
  34.   menu string (Count To 10) with a command key option (/1).
  35. ----------------------------------------------------}
  36. program DoCount 'Count To 10/4'
  37. begin
  38.     for i = 1 to 10 do write (i)
  39.     writeln
  40. end
  41.  
  42. { ---------------- Factorial ----------------------
  43.   A slightly more complex program which calculates
  44.   all the  factorial numbers from 1 to 15.
  45.   It demonstrates how to declare a local variable ( f ),
  46.   and uses a multi-parameter "WriteLn" statement.
  47. -------------------------------------------------}
  48. program Fact 'Factorial 1 to 10/5'
  49. var
  50.     f : real
  51. begin
  52.     f = 1
  53.     for i = 1 to 10 do
  54.     begin
  55.     {• Calculate factorial •}
  56.         f = f * i
  57.         writeln ('Factorial ',i,' = ',f)
  58.     end
  59. end
  60.  
  61.  
  62. { ------------------ Trigonometry ---------------
  63.   This program uses an internal trigonometric function.
  64.   It uses "print" instead of "WriteLn".
  65. -------------------------------------------------}
  66. program Trig 'Cos 0 to 90/6'
  67. var
  68.     cosResult, degrees : real
  69. begin
  70. {• Calculate the cosine of angles from 0 to 90 in steps of 10 •}
  71.     for i = 0 to 9 do
  72.     begin
  73.         degrees = i * 10
  74.         cosResult = cos (degrees)
  75.         print ('cos ( ',degrees,') = ',cosResult)
  76.     end
  77. end
  78.  
  79.  
  80. { ------------ String Variables ------------
  81.   This program shows how to create and initialize
  82.   string variables. It shows how to pass them as 
  83.   arguments to a procedure or function.
  84. -----------------------------------------------}
  85. Procedure Print2Strings (aString, bString:    Str255)
  86. begin
  87.     writeln ('1) ', aString)
  88.     writeln ('2) ', bString)
  89. end
  90.  
  91. program DemoString 'String Variable Example/7'
  92. Var
  93.     aString:    Str255            {• A standard string declaration •}
  94.     bString:    String            {• More memorable alternative to "Str255" •}
  95. begin
  96.     aString = 'Anhydrohydroxyprogesterone'
  97.     bString = 'synthetic female hormone'
  98.     
  99.     {• String created "on the fly". •}
  100.     {• The "Concat" function combines 2 or more strings. •}
  101.     cString = concat (aString,':  ',bString)
  102.     
  103.     aString = 'Trinitrophenylmethylnitramine'
  104.     bString = 'a type of explosive.'
  105.     
  106.     {• String created procedurally •}
  107.     NewString (dString)
  108.     dString = concat (aString,':  ',bString)
  109.     
  110.     {• Strings passed as arguments to a subroutine •}
  111.     Print2Strings (cString, dString)
  112. end
  113.  
  114. { ------------ Test Array Arithmetic ------------
  115.   This program initialize the global array, "globalArr", and
  116.   creates and initializes a local array, "localArr".
  117.   It adds, the two arrays, and outputs the result.
  118. -----------------------------------------------}
  119. program testArr 'Array Example/8'
  120. var
  121.     localArr : Array[1..10]
  122. begin
  123. {• Initialize the local and global arrays •}
  124.     for i = 1 to 10 do
  125.     begin
  126.         localArr[i] = 100
  127.         globalArr[i] = i
  128.     end
  129.     
  130. {• Add the two arrays •}
  131.     globalArr = globalArr + localArr
  132.     writeArr (globalArr)
  133. end
  134.  
  135.  
  136. { ------------ Sphere Volume and S.A. ----------------
  137.   This program demonstrates the "poseDialog" and "Alert"
  138.   commands. It uses poseDialog to prompt the user for
  139.   a sphere's radius, then calculates the volume and
  140.   surface area of the sphere, and returns the results
  141.   to the user in an alert dialog.
  142. -----------------------------------------------------}
  143. program sphere 'Volume and S.A. of Sphere/9'
  144. var
  145.     radius, theVolume, theSA : Real
  146. begin
  147. {• Ask the user for the radius of the sphere •}
  148.     poseDialog ('\rCalculate the volume and surface area of a sphere', 
  149. &                        'Radius of sphere ',radius)
  150.  
  151. {• Calculate the surface area and volume •}
  152.     theSA = 4 * pi * radius ^ 2
  153.     theVolume = (4 / 3) * pi * radius ^ 3
  154.  
  155. {• Send the results to an alert dialog •}
  156.     Alert ('The volume and surface area of a \r sphere with radius ', 
  157. &                    radius,' are : \r Volume = ',theVolume,
  158. &                      '\r Surface area = ',theSA)
  159. end
  160.  
  161.  
  162.  
  163.  
  164. { ----------------- Count Down ----------------------
  165.   This program demonstrates the "FlushOutput" and "Beep"
  166.   commands. It counts down from 10 to 0 beeping at each
  167.   count. A pause is introduces between each count by
  168.   performing several hundred exponential calculations.
  169. -----------------------------------------------------}
  170. program CountDown 'Lift Off/0'
  171. begin
  172.     WriteLn
  173.     WriteLn ('Prepare for count down.')
  174.     FlushOutput
  175. { Pause }
  176.     For k = 1 to 100 do a = exp(2.0)
  177. { Start the count down }
  178.     j = 10
  179.     While j >= 0 do
  180.     begin
  181.         if (j = 3) then 
  182.             WriteLn ('Ignition')
  183.         if (j <> 0) then 
  184.             WriteLn (j)
  185.         else
  186.             WriteLn ('Lift Off !!')
  187.         FlushOutput
  188.         Beep
  189.         j = j - 1
  190.     { Slow down the count }
  191.         For k = 1 to 50 do a = exp(2.0)
  192.     end
  193. end
  194.