home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / basic / basictut.ark / TUTR.12 < prev    next >
Encoding:
Text File  |  1985-02-10  |  8.3 KB  |  180 lines

  1. 3000    ' tutor 12
  2. 3010    GOSUB 37100
  3. 3020    T5$ = SPACE$(5) : T10$ = SPACE$(10) : T15$ = SPACE$(15) :VT$ = CHR$(11)
  4. 3030    PRINT T10$;"   Before we go on to defining functions, would you like to"
  5. 3040    PRINT T10$;"review the meanings of the standard ones? ";
  6. 3050    GOSUB 40900 : Y$ = CVTSTR$
  7. 3060    PRINT
  8. 3070    IF LEFT$(Y$,1) = "N" THEN 4060
  9. 3080    IF LEFT$(Y$,1) = "Y" THEN 3110
  10. 3090    PRINT T10$;"Please type 'yes' or 'no', which is it...";VT$;VT$;CR$;
  11. 3100    GOTO 3040
  12. 3110    GOSUB 37100
  13. 3120    PRINT T10$;"Good. Use this answer selection table:"
  14. 3130    PRINT
  15. 3140    PRINT T10$;"    (1) sin(x)    (2) cos(x)    (3) tan(x)    (4) atn(x)"
  16. 3150    PRINT
  17. 3160    PRINT T10$;"    (5) exp(x)    (6) abs(x)    (7) log(x)    (8) sqr(x)"
  18. 3170    PRINT
  19. 3180    PRINT T10$;"    (9) fix(x)    (10) sgn(x)";CRLF$
  20. 3190    R = 0
  21. 3200    PRINT T10$;"   Note: the above functions are in lower case. Mbasic will accept"
  22. 3210    PRINT T10$;"programs written in lower case and automatically convert them to"
  23. 3220    PRINT T10$;"upper case."
  24. 3230    GOSUB 37000 : PRINT FNPOSCUR$(14,1);EES$;
  25. 3240    PRINT T10$;"Which function finds the absolute value? ";
  26. 3250    GOSUB 40900 : A$ = CVTSTR$
  27. 3260    R = R + 1
  28. 3270    PRINT
  29. 3280    IF A$ = "6" OR (LEN(A$) > 1 AND LEFT$(A$,2) = "AB") THEN 3320
  30. 3290    PRINT T10$;"Nope, the function name is an abbreviation for what it does."
  31. 3300    PRINT T10$;"Try again - which one....";VT$;VT$;VT$;CR$;
  32. 3310    GOTO 3240
  33. 3320    PRINT VT$;VT$;CR$;EES$;
  34. 3330    PRINT T10$;"Good! The next question is harder: what function determines the"
  35. 3340    PRINT T10$;"natural logarithm of 'x'? ";
  36. 3350    GOSUB 40900 : A$ = CVTSTR$
  37. 3360    R = R + 1
  38. 3370    PRINT
  39. 3380    IF A$ = "7" OR (LEN(A$) > 1 AND LEFT$(A$,2) = "LO")  THEN 3410
  40. 3390    PRINT T10$;"No - check the abbreviation for 'logarithm'. Now which....";
  41.         VT$;VT$;CR$;
  42. 3400    GOTO 3340
  43. 3410    PRINT VT$;VT$;VT$;CR$;EES$;
  44. 3420    PRINT T10$;"Very Good! The next one is easy: what's the sine function? ";
  45. 3430    GOSUB 40900 : A$ = CVTSTR$
  46. 3440    R = R + 1
  47. 3450    PRINT
  48. 3460    IF A$ = "1" OR (LEN(A$) > 1 AND LEFT$(A$,2) = "SI")  THEN 3490
  49. 3470    PRINT T10$;"Try again, please. Which one....";VT$;VT$;CR$;
  50. 3480    GOTO 3420
  51. 3490    PRINT VT$;VT$;CR$;EES$;
  52. 3500    PRINT T10$;"Right. Which function gives an angle whose tangent is 'x'? ";
  53. 3510    GOSUB 40900 : A$ = CVTSTR$
  54. 3520    R = R + 1
  55. 3530    PRINT
  56. 3540    IF A$ = "4" OR (LEN(A$) > 1 AND LEFT$(A$,2) = "AT")  THEN 3570
  57. 3550    PRINT T10$;"It's tricky. Try again.";VT$;VT$;CR$;
  58. 3560    GOTO 3500
  59. 3570    PRINT VT$;VT$;CR$;EES$;
  60. 3580    PRINT T10$;"Excellent. Now for the hardest: what function computes 'e^x'? ";
  61. 3590    GOSUB 40900 : A$ = CVTSTR$
  62. 3600    R = R + 1
  63. 3610    PRINT
  64. 3620    IF A$ = "5" OR (LEN(A$) > 1 AND LEFT$(A$,2) = "EX")  THEN 3650
  65. 3630    PRINT T10$;"Well it's hard. Hint: what is the exponential (power) of 'e'";VT$;VT$;CR$;
  66. 3640    GOTO 3580
  67. 3650    PRINT T10$;"Terrific. The rest are trivial, so we might as well move on."
  68. 3660    PRINT
  69. 3670    IF R = 5 THEN 3690
  70. 3680    GOTO 3700
  71. 3690    PRINT T10$;"By the way, you get a 'big gold star' for a perfect score."
  72. 3700    GOSUB 37000 : PRINT FNPOSCUR$(12,1);EES$;
  73. 3710    PRINT T10$;"   Here are some restrictions which apply to certain functions:"
  74. 3720    PRINT T10$;"the argument of the sine, cosine, and tangent functions must"
  75. 3730    PRINT T10$;"be in radian measure. The arctangent gives an angle in radians."
  76. 3740    PRINT
  77. 3750    PRINT T10$;"   The logarithm of a negative number is not defined. So if the"
  78. 3760    PRINT T10$;"argument is negative, an error message will appear and the"
  79. 3770    PRINT T10$;"command will be executed with a positive argument. If 'sqr' has"
  80. 3780    PRINT T10$;"a negative argument, then another error message appears and a"
  81. 3790    PRINT T10$;"positive argument is used. The argument of a function may be any"
  82. 3800    PRINT T10$;"expression, as long as it has a numerical value."
  83. 3810    GOSUB 37000 : GOSUB 37100
  84. 3820    PRINT T10$;"   Let's make a table of 'x' and 'sin(x)' for 0<=x<=360 degrees"
  85. 3830    PRINT T10$;"in steps of 60 degrees. Here's a program which will do it:"
  86. 3840    PRINT
  87. 3850    PRINT "5  pi = 22/7"
  88. 3860    PRINT "10 let x = pi/180            ' (degrees to radians)"
  89. 3870    PRINT "20 for i = 0 to 360 step 60  ' (start of loop)"
  90. 3880    PRINT "30 print i, sin(x*i)         ' (output statement)"
  91. 3890    PRINT "40 next i                    ' (end of loop)"
  92. 3900    PRINT "50 end                       ' (last statement)"
  93. 3910    PRINT
  94. 3920    PRINT T10$;"Would you like to have this program run? ";
  95. 3930    GOSUB 40900 : B$ = CVTSTR$
  96. 3940    PRINT
  97. 3950    IF LEN(B$) = 0 OR LEFT$(B$,1) <> "Y" THEN 4080
  98. 3960    GOSUB 37100
  99. 3970    X = (22/7) / 180
  100. 3980    FOR I = 0 TO 360 STEP 60
  101. 3990    PRINT I, SIN(X * I)
  102. 4000    NEXT I
  103. 4010    PRINT "Ok"
  104. 4020    PRINT
  105. 4030    PRINT T10$;"   Column headings would probably have improved the output. Also,"
  106. 4040    PRINT T10$;"two functions were not shown above. 'INT' extracts the whole"
  107. 4050    GOTO 4100
  108. 4060    PRINT:PRINT T10$;"   OK, but two should interest you. 'INT' extracts the whole"
  109. 4070    GOTO 4100
  110. 4080    PRINT T10$;"Anyway, it does the job. Don't forget: in addition to the "
  111. 4090    PRINT T10$;"eight functions above, there's 'int', which extracts the whole"
  112. 4100    PRINT T10$;"number part of any number. If n=27.68, then when the statement"
  113. 4110    PRINT T10$;"'print int(n)' is used, the computer will print '27'. The other"
  114. 4120    PRINT T10$;"standard function is 'rnd(x)', which generates a number (not"
  115. 4130    PRINT T10$;"specified) between 0 and 1. It has an unused ('dummy') argument."
  116. 4140    PRINT T10$;"'rnd' is equivalent to 'rnd(0)'"
  117. 4150    PRINT
  118. 4160    IF LEFT$(Y$,1) = "N" THEN 4180
  119. 4170    PRINT T10$;"I'll remind you of a program on standard functions later."
  120. 4180    PRINT T10$;"Let's show how we can write our own functions. This is done"
  121. 4190    PRINT T10$;"by means of the term 'def' (for 'define')."
  122. 4200    PRINT : PRINT FNCENTER$("press any key for an example");
  123. 4210    FOR CT = 1 TO 28 : PRINT CHR$(8); : NEXT CT : GOSUB 40800 : GOSUB 37100
  124. 4220    PRINT "10 def fnp(c) = c + .57 * c"
  125. 4230    PRINT
  126. 4240    PRINT T10$;"The 'fn' means 'function' to the computer, and 'p' is the name"
  127. 4250    PRINT T10$;"of the function. A function name is any legal variable name";CRLF$
  128. 4260    PRINT T10$;"What is the argument in the above definition? ";
  129. 4270    GOSUB 40900 : A$ = CVTSTR$
  130. 4280    PRINT
  131. 4290    IF A$ = "C" THEN 4320
  132. 4300    PRINT T10$;"   Wrong - 'c' is operated on; the right side shows how."
  133. 4310    GOTO 4330
  134. 4320    PRINT T10$;"   Of course. Any function needs an argument. on the right side,"
  135. 4330    PRINT T10$;"'c + .57 * c' will have a value dependent upon the size of 'c'. If"
  136. 4340    PRINT T10$;"'p' is a sales price based on a 57 percent markup over cost,"
  137. 4350    PRINT T10$;"then the expression could be read: 'the price function of cost"
  138. 4360    PRINT T10$;"is defined as c + .57 * c'."
  139. 4370    GOSUB 37000 : GOSUB 37100
  140. 4380    PRINT T10$;"The following sample program incorporates the example function:"
  141. 4390    PRINT
  142. 4400    PRINT "100 def fnp(c) = c+.57*c"
  143. 4410    PRINT "110 read c"
  144. 4420    PRINT "120 data .27"
  145. 4430    PRINT "130 print "; CHR$(34); "Cost is"; CHR$(34); ";c,"; CHR$(34); "Sales price is"; CHR$(34); ";fnp(c)"
  146. 4440    PRINT "140 end";CRLF$
  147. 4450    PRINT T10$;"Do you wish to see the results of running this program? ";
  148. 4460    GOSUB 40900 : A$ = CVTSTR$ : IF LEFT$(A$,1) <> "Y" THEN 4500
  149. 4470    GOSUB 37100
  150. 4480    DEF FNP(C) = C + .57 * C : READ C : DATA .27
  151. 4490    PRINT : PRINT "Cost is"; C, "Sales price is"; FNP(C) : PRINT "Ok"
  152. 4500    PRINT
  153. 4510    PRINT T10$;"   For a complicated function used more than once in a program,"
  154. 4520    PRINT T10$;"the define statement has obvious advantages. More examples"
  155. 4530    PRINT T10$;"of using defined functions will be included in later lessons."
  156. 4540    PRINT
  157. 4550    PRINT T10$;"Lesson 13 discusses subroutines and the 'REM' statement"
  158. 4560    PRINT CRLF$;FNCENTER$("press any key for menu");
  159. 4570    FOR CT = 1 TO 22 : PRINT CHR$(8); : NEXT CT : GOSUB 40800
  160. 4580    GOTO 39999
  161.  
  162. 37000    'press any key pause
  163. 37010    PRINT T10$;CRLF$;CRLF$;FNCENTER$("press any key to continue");
  164. 37020    FOR CT= 1 TO 25 : PRINT CHR$(8); : NEXT CT
  165. 37030    GOSUB 40800
  166. 37099    RETURN
  167.  
  168. 37100    ' heading
  169. 37110    PRINT CLS$;FNPOSCUR$(4,1);FNCENTER$("Tutor -- Lesson 12");CRLF$
  170. 37199    RETURN
  171.  
  172. 38000    ' converted for Non-linear Systems, Kaypro Educational Division
  173. 38010    ' by t.crew , Simple Software, San Diego CA
  174. 38020    ' has to be run with mentutr to get all variables
  175. 38030    ' tutor lesson 12 version 2.0  released to nls 1 aug 83
  176.  
  177. 39999    RUN "MENU" 'end of overlay
  178.  
  179. utr to get all variables
  180. 38030    ' tutor lesson 12 version 2.0