home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-03-14 | 5.2 KB | 190 lines | [TEXT/AxoC] |
- LocalLanguage C
- /* -------------------------------------------------
-
- The following 6 programs demonstrate various aspects of
- AxoCalculator's C programming language.
-
- To load all 6 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 "Float"
- variables can be created on the fly, global
- declarations will most commonly be used for creating
- "boolean", "int" or array variables.
- -----------------------------------------------------*/
-
- int i
- float globalArr[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"
- {
- for (i = 1 ; i <= 10 ; i++) printf (i)
- }
-
-
- /* ---------------- 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 "printf" statement.
- -------------------------------------------------*/
- program Fact "Factorial 1 to 10/5"
- {
- float f
-
- f = 1
- for (i = 1 ; i <= 10 ; i++)
- {
- /* Calculate factorial */
- f = f * i
- printf ("Factorial ",i," = ",f)
- }
- }
-
-
- /* ------------------ Trigonometry ---------------
- This program uses an internal trigonometric function.
- -------------------------------------------------*/
- program Trig "Cos 0 to 90/6"
- {
- float cosResult, degrees
-
- /* Calculate the cosine of angles from 0 to 90 in steps of 10 */
- for (i = 0 ; i <= 9 ; i++)
- {
- degrees = i * 10
- cosResult = cos (degrees)
- printf ("cos ( ",degrees,") = ",cosResult)
- }
- }
-
-
- /* ------------ 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.
- --------------------------------------------- */
- void Print2Strings (String aString, bString)
- {
- writeln ("1) ", aString)
- writeln ("2) ", bString)
- }
-
- program DemoString "String Variable Example/7"
- {
- String aString, bString /* Declared strings */
-
- 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)
- }
- /* ------------ 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"
- {
- float localArr[10]
-
- /* Initialize the local and global arrays */
- for (i = 0 ; i < 10 ; i++)
- {
- localArr[i] = 100
- globalArr[i] = i
- }
-
- /* Add the two arrays */
- globalArr = globalArr + localArr
- writeArr (globalArr)
- }
-
-
- /* ------------ 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"
- {
- float radius, theVolume, theSA
-
- /* 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)
- }
-
-
-
-
- /* ----------------- 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"
- {
- printf
- printf ("Prepare for count down.")
- FlushOutput
- /* Pause */
- for (k = 1 ; k <= 50 ; k++) a = exp(2.0)
- /* Start the count down */
- j = 10
- While ( j >= 0 )
- {
- if (j == 3)
- printf ("Ignition")
- if (j != 0)
- printf (j)
- else
- printf ("Lift Off !!")
- FlushOutput
- Beep
- j = j - 1
- /* Slow down the count */
- for (k = 1 ; k <= 20 ; k++) a = exp(2.0)
- }
- }
-