home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-03-14 | 5.4 KB | 194 lines | [TEXT/AxoC] |
- LocalLanguage Pascal
- { -------------------------------------------------
-
- The following 7 programs demonstrate various aspects of
- AxoCalculator's Pascal programming language.
-
- • To load all 7 programs, choose "Select All" under
- the "Edit" menu, then press "enter".
-
- • To run a program, either select it under the
- "Calculator" menu, or type its name and press "enter".
-
- • After the programs are loaded, this file does not need
- to remain open in order to use them.
-
- --------------------------------------------------}
-
- { ----------------- Global Variables ------------------
- The following 3 lines demonstrate how to declare
- global variables. See "The Programming Language" for more
- on variable declaration. Because global "Real"
- variables can be created on the fly, global
- declarations will most commonly be used for creating
- "Boolean", "Integer" or "Array" variables.
- -----------------------------------------------------}
- var
- i : Integer
- globalArr : Array[1..10]
-
-
- { ------------------- DoCount -----------------------
- A very simple program which counts to 10.
- It demonstrates how to declare a program, and assign it a
- menu string (Count To 10) with a command key option (/1).
- ----------------------------------------------------}
- program DoCount 'Count To 10/4'
- begin
- for i = 1 to 10 do write (i)
- writeln
- end
-
- { ---------------- Factorial ----------------------
- A slightly more complex program which calculates
- all the factorial numbers from 1 to 15.
- It demonstrates how to declare a local variable ( f ),
- and uses a multi-parameter "WriteLn" statement.
- -------------------------------------------------}
- program Fact 'Factorial 1 to 10/5'
- var
- f : real
- begin
- f = 1
- for i = 1 to 10 do
- begin
- {• Calculate factorial •}
- f = f * i
- writeln ('Factorial ',i,' = ',f)
- end
- end
-
-
- { ------------------ Trigonometry ---------------
- This program uses an internal trigonometric function.
- It uses "print" instead of "WriteLn".
- -------------------------------------------------}
- program Trig 'Cos 0 to 90/6'
- var
- cosResult, degrees : real
- begin
- {• Calculate the cosine of angles from 0 to 90 in steps of 10 •}
- for i = 0 to 9 do
- begin
- degrees = i * 10
- cosResult = cos (degrees)
- print ('cos ( ',degrees,') = ',cosResult)
- end
- end
-
-
- { ------------ String Variables ------------
- This program shows how to create and initialize
- string variables. It shows how to pass them as
- arguments to a procedure or function.
- -----------------------------------------------}
- Procedure Print2Strings (aString, bString: Str255)
- begin
- writeln ('1) ', aString)
- writeln ('2) ', bString)
- end
-
- program DemoString 'String Variable Example/7'
- Var
- aString: Str255 {• A standard string declaration •}
- bString: String {• More memorable alternative to "Str255" •}
- begin
- aString = 'Anhydrohydroxyprogesterone'
- bString = 'synthetic female hormone'
-
- {• String created "on the fly". •}
- {• The "Concat" function combines 2 or more strings. •}
- cString = concat (aString,': ',bString)
-
- aString = 'Trinitrophenylmethylnitramine'
- bString = 'a type of explosive.'
-
- {• String created procedurally •}
- NewString (dString)
- dString = concat (aString,': ',bString)
-
- {• Strings passed as arguments to a subroutine •}
- Print2Strings (cString, dString)
- end
-
- { ------------ Test Array Arithmetic ------------
- This program initialize the global array, "globalArr", and
- creates and initializes a local array, "localArr".
- It adds, the two arrays, and outputs the result.
- -----------------------------------------------}
- program testArr 'Array Example/8'
- var
- localArr : Array[1..10]
- begin
- {• Initialize the local and global arrays •}
- for i = 1 to 10 do
- begin
- localArr[i] = 100
- globalArr[i] = i
- end
-
- {• Add the two arrays •}
- globalArr = globalArr + localArr
- writeArr (globalArr)
- end
-
-
- { ------------ Sphere Volume and S.A. ----------------
- This program demonstrates the "poseDialog" and "Alert"
- commands. It uses poseDialog to prompt the user for
- a sphere's radius, then calculates the volume and
- surface area of the sphere, and returns the results
- to the user in an alert dialog.
- -----------------------------------------------------}
- program sphere 'Volume and S.A. of Sphere/9'
- var
- radius, theVolume, theSA : Real
- begin
- {• Ask the user for the radius of the sphere •}
- poseDialog ('\rCalculate the volume and surface area of a sphere',
- & 'Radius of sphere ',radius)
-
- {• Calculate the surface area and volume •}
- theSA = 4 * pi * radius ^ 2
- theVolume = (4 / 3) * pi * radius ^ 3
-
- {• Send the results to an alert dialog •}
- Alert ('The volume and surface area of a \r sphere with radius ',
- & radius,' are : \r Volume = ',theVolume,
- & '\r Surface area = ',theSA)
- end
-
-
-
-
- { ----------------- Count Down ----------------------
- This program demonstrates the "FlushOutput" and "Beep"
- commands. It counts down from 10 to 0 beeping at each
- count. A pause is introduces between each count by
- performing several hundred exponential calculations.
- -----------------------------------------------------}
- program CountDown 'Lift Off/0'
- begin
- WriteLn
- WriteLn ('Prepare for count down.')
- FlushOutput
- { Pause }
- For k = 1 to 100 do a = exp(2.0)
- { Start the count down }
- j = 10
- While j >= 0 do
- begin
- if (j = 3) then
- WriteLn ('Ignition')
- if (j <> 0) then
- WriteLn (j)
- else
- WriteLn ('Lift Off !!')
- FlushOutput
- Beep
- j = j - 1
- { Slow down the count }
- For k = 1 to 50 do a = exp(2.0)
- end
- end
-