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