home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-03-12 | 2.7 KB | 90 lines | [TEXT/AxoC] |
- LocalLanguage Basic
- '-------------------------------------------------------
- ' The following functions demonstrate various aspects of
- ' AxoCalculator's Basic programming language.
- '
- ' • To load all the demo functions, choose "Select All"
- ' under the "Edit" menu, then press "enter".
- '
- ' • To run a function, type its name followed
- ' by any parameters, then press "enter".
- '
- ' • After the functions are loaded, this file does
- ' not need to remain open in order to use them.
- '
- ' • Here are some examples of how to use the functions
- ' (remove the ( ' ) at the start of each line before testing) .
- '
- ' BoxVolume (10,15,20)
- ' Factorial (10)
- ' RecursiveFact (10)
- ' SameBirthDateProb(25)
- '--------------------------------------------------
-
- '---------------- RectArea ------------------------
- ' This function calculates the area of a rectangle
- ' given its height and width.
- '-------------------------------------------------
- function RectArea (height, width)
- RectArea = height * width
- end
-
- '---------------- BoxVolume ----------------------
- ' This function calculates the volume of a box
- ' given its height, width and depth. It calls the
- ' function RectArea to get the area of the bottom of
- ' the box, then multiplies the result by the box depth.
- '-------------------------------------------------
- function BoxVolume (height, width, depth)
- BoxVolume = RectArea (height, width) * depth
- end
-
- '---------------- Factorial ---------------------
- ' This function calculates the factorial of a number.
- '----------------------------------------------
- function Factorial (number)
- f = 1
- for i = 1 to number
- f = f * i
- next i
- Factorial = f
- end
-
- ' ---------------- RecursiveFact -------------------
- ' This function also calculates the factorial of a number,
- ' but it uses a recursive algorithm. This approach is
- ' inefficient, but demonstrates recursion.
- ' -----------------------------------------------}
- function RecursiveFact (number)
- if number > 1 then
- RecursiveFact = number * RecursiveFact (number - 1)
- else
- RecursiveFact = 1
- end
-
-
- '---------------- SameBirthDateProb ------------------
- ' This function calculates the probability that two or more
- ' people in a group have the same birth date, given the
- ' number of people in the group. It works by calculating
- ' 1 - the probability that everyone in the group has a
- ' different birth date.
- '----------------------------------------------------
- function SameBirthDateProb (numberOfPeople)
- if (numberOfPeople < 2) then
- DiffBirthDateProb = 1
- else
- if (numberOfPeople > 365) then
- DiffBirthDateProb = 0
- else
- DiffBirthDateProb = 1
- For i = 2 to numberOfPeople
- DiffBirthDateProb = DiffBirthDateProb * (366-i) / 365
- next i
- end if
- end if
- SameBirthDateProb = 1 - DiffBirthDateProb
- end
-
-
-