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 Basic / Example Functions next >
Encoding:
Text File  |  1993-03-12  |  2.7 KB  |  90 lines  |  [TEXT/AxoC]

  1. LocalLanguage Basic
  2. '-------------------------------------------------------
  3. '    The following functions demonstrate various aspects of 
  4. '    AxoCalculator's Basic programming language. 
  5. '
  6. '    •  To load all the demo functions, choose "Select All" 
  7. '        under the "Edit" menu, then press "enter". 
  8. '
  9. '    •  To run a function, type its name followed
  10. '        by any parameters, then press "enter".
  11. '
  12. '    •  After the functions are loaded, this file does 
  13. '        not need to remain open in order to use them.
  14. '
  15. '    •  Here are some examples of how to use the functions
  16. '        (remove the ( ' ) at the start of each line before testing) .
  17. '
  18. '    BoxVolume (10,15,20)
  19. '    Factorial (10)
  20. '    RecursiveFact (10)
  21. '    SameBirthDateProb(25)
  22. '--------------------------------------------------
  23.  
  24. '---------------- RectArea ------------------------
  25. '    This function calculates the area of a rectangle
  26. '    given its height and width.
  27. '-------------------------------------------------
  28. function RectArea (height, width)
  29.     RectArea = height * width
  30. end
  31.  
  32. '---------------- BoxVolume ----------------------
  33. '    This function calculates the volume of a box 
  34. '    given its height, width and depth. It calls the
  35. '    function RectArea to get the area of the bottom of
  36. '    the box, then multiplies the result by the box depth. 
  37. '-------------------------------------------------
  38. function BoxVolume (height, width, depth)
  39.     BoxVolume = RectArea (height, width) * depth
  40. end
  41.  
  42. '---------------- Factorial ---------------------
  43. '    This function calculates the factorial of a number.
  44. '----------------------------------------------
  45. function Factorial (number)
  46.     f = 1
  47.     for i = 1 to number 
  48.         f = f * i
  49.     next i
  50.     Factorial = f
  51. end
  52.  
  53. '    ---------------- RecursiveFact -------------------
  54. '  This function also calculates the factorial of a number,
  55. '  but it uses a recursive algorithm. This approach is
  56. '  inefficient, but demonstrates recursion.
  57. '    -----------------------------------------------}
  58. function RecursiveFact (number)
  59.     if number > 1 then
  60.         RecursiveFact = number * RecursiveFact (number - 1)
  61.     else
  62.         RecursiveFact = 1
  63. end
  64.  
  65.  
  66. '---------------- SameBirthDateProb ------------------
  67. '  This function calculates the probability that two or more
  68. '  people in a group have the same birth date, given the
  69. '  number of people in the group. It works by calculating
  70. '  1 - the probability that everyone in the group has a 
  71. '  different birth date.
  72. '----------------------------------------------------
  73. function SameBirthDateProb (numberOfPeople)
  74.     if (numberOfPeople < 2) then 
  75.         DiffBirthDateProb = 1
  76.     else 
  77.         if (numberOfPeople > 365) then 
  78.             DiffBirthDateProb = 0
  79.         else
  80.             DiffBirthDateProb = 1
  81.             For i = 2 to numberOfPeople  
  82.                 DiffBirthDateProb = DiffBirthDateProb * (366-i) / 365
  83.             next i
  84.         end if
  85.     end if
  86.     SameBirthDateProb = 1 - DiffBirthDateProb
  87. end
  88.     
  89.  
  90.