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 C / Example Programs < prev    next >
Encoding:
Text File  |  1993-03-14  |  5.2 KB  |  190 lines  |  [TEXT/AxoC]

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