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

  1. 3000    ' tutor 14
  2. 3010    GOSUB 37100
  3. 3020    T5$ = SPACE$(5) : T10$ = SPACE$(10) : T15$ = SPACE$(15) :VT$ = CHR$(11)
  4. 3030    PRINT T10$;"   Glad to see you again.  I hope you have been practicing"
  5. 3040    PRINT T10$;"the instructions as you learn them.  Learning how to program"
  6. 3050    PRINT T10$;"well is like mastering a foreign language.  Only repeated"
  7. 3060    PRINT T10$;"exercise can make you proficient."
  8. 3070    W = 0
  9. 3080    PRINT
  10. 3090    PRINT T10$;"   Before we undertake any new work, let's first review some"
  11. 3100    PRINT T10$;"of the basic statements to which you have previously been intro-"
  12. 3110    PRINT T10$;"duced."
  13. 3120    GOSUB 37000 : GOSUB 37100
  14. 3130    PRINT T10$;"   An arithmetic function may be used to avoid writing an "
  15. 3140    PRINT T10$;"identical statement repetitiously.  For example, your"
  16. 3150    PRINT T10$;"program may require the following statements;"
  17. 3160    PRINT
  18. 3170    PRINT "120 let u=(c1*x^2 + c2*x + c3) * sin(x)"
  19. 3180    PRINT "     ."
  20. 3190    PRINT "     ."
  21. 3200    PRINT "280 let v=(c1*y^2 + c2*y + c3)^2"
  22. 3210    PRINT "     ."
  23. 3220    PRINT "     ."
  24. 3230    PRINT "370 let w=c1*z^2 + c2*z + c3"
  25. 3240    PRINT "     ."
  26. 3250    PRINT T10$;"   An easier way to do this would be to use the function state-"
  27. 3260    PRINT T10$;"ment.  Which of the following statements would be involved? "
  28. 3270    PRINT
  29. 3280    PRINT T10$;"    (1) go to     (2) rem   (3) def     (4) if...then..."
  30. 3290    PRINT CRLF$;FNCENTER$("Your choice? ");
  31. 3300    GOSUB 40900 : Z$ = CVTSTR$
  32. 3310    PRINT
  33. 3320    IF Z$ = "3" OR Z$ = "DEF" THEN 3370
  34. 3330    W = W + 1
  35. 3340    PRINT T10$;"  You're putting me on. A function definition must be preceded by the"
  36. 3350    PRINT T10$;"symbol 'def', an abbreviation of the word 'define'."
  37. 3360    GOSUB 37000 : GOSUB 37100 : GOTO 3380
  38. 3370    PRINT T10$;"RIGHT!" : GOTO 3360
  39. 3380    PRINT T10$;"   For example, you could write:"
  40. 3390    GOSUB 5000
  41. 3400    PRINT T10$;"   Remember - a function, like the parents of a teenager,"
  42. 3410    PRINT T10$;"always requires an argument.  In the defining statement (90)"
  43. 3420    PRINT T10$;"the argument is q.  When used in the body of the program, the"
  44. 3430    PRINT T10$;"called for argument replaces the 'dummy' argument q."
  45. 3440    GOSUB 37000 : GOSUB 37100 : GOSUB 5000
  46. 3450    PRINT T10$;"   For example, if c1 = 1 , c2 = 3, and c3 = 6,"
  47. 3460    PRINT T10$;"what is the value of fnr(3)? ";
  48. 3470    GOSUB 40900 : Z$ = CVTSTR$
  49. 3480    PRINT
  50. 3490    IF Z$ = "24" THEN 3530
  51. 3500    W = W + 1
  52. 3510    PRINT T10$;"No. Would you believe 24?   (1*9 + 3*3 + 6)"
  53. 3520    GOTO 3540
  54. 3530    PRINT T10$;"Very good. "
  55. 3540    PRINT
  56. 3550    PRINT T10$;"   Did you understand the difference between a function and a"
  57. 3560    PRINT T10$;"subroutine?  A subroutine is used to avoid writing identical"
  58. 3570    PRINT T10$;"groups of instructions, whereas a function treats only a single"
  59. 3580    PRINT T10$;"line."
  60. 3590    GOSUB 37000 : GOSUB 37100
  61. 3600    PRINT T15$;"(1) goto  (2) return  (3) next  (4) gosub  (5) end";CRLF$
  62. 3610    PRINT T10$;"   Which two of the above symbols do you associate with the"
  63. 3620    PRINT T10$;"use of a subroutine (1st choice, 2nd choice)? ";
  64. 3630    GOSUB 40900 : GOSUB 40400 : Z$ = CVTSTR$
  65. 3640    PRINT CRLF$;CRLF$
  66. 3650    IF Z$ = "2,4" OR Z$ = "4,2" OR Z$ = "RETURN,GOSUB" OR 
  67.         Z$ = "GOSUB,RETURN" THEN 3720
  68. 3660    W = W + 1
  69. 3670    IF W = 1 THEN 3700
  70. 3680    PRINT T10$;"X@)@zG!@;=8&C>:@<    (the computer equivalent of tsk, tsk)"
  71. 3690    GOTO 3730
  72. 3700    PRINT T10$;"Since this your first mistake, I won't reprimand you."
  73. 3710    GOTO 3730
  74. 3720    PRINT T10$;"Right."
  75. 3730    PRINT
  76. 3740    PRINT T10$;"   GOSUB xxx is an abbreviated way of indicating 'go to the"
  77. 3750    PRINT T10$;"subroutine which starts at line number xxx'.  The 'RETURN'"
  78. 3760    PRINT T10$;"statement, which should be the last statement in the subroutine,"
  79. 3770    PRINT T10$;"is a signal that when the subroutine has been executed, control"
  80. 3780    PRINT T10$;"will be sent back to the instruction following the gosub."
  81. 3790    PRINT
  82. 3800    PRINT T10$;"   The function and subroutine calls are very powerful instruc-"
  83. 3810    PRINT T10$;"tions and should be mastered."
  84. 3820    GOSUB 37000 : GOSUB 37100
  85. 3830    IF W < 2 THEN 3860
  86. 3840    PRINT T10$;"   Since you missed "; W; "of the above questions, perhaps"
  87. 3850    PRINT T10$;"you should review 'TUTR09' when you are through here."
  88. 3860    PRINT
  89. 3870    PRINT
  90. 3880    PRINT T10$;"   You probably noticed that blanks were inserted between some"
  91. 3890    PRINT T10$;"of the words used in the statements above to improve legibility."
  92. 3900    PRINT T10$;"Blanks may be used almost at will in all basic statements without"
  93. 3910    PRINT T10$;"affecting the intent of the statement in any way.  But there"
  94. 3920    PRINT T10$;"are exceptions. Blanks(spaces) cannot be embedded within command"
  95. 3930    PRINT T10$;"words, standard function names, operator names or your own"
  96. 3940    PRINT T10$;"variables. ( CORRECT$  not COR RECT $ )."
  97. 3950    PRINT T10$;"(i.e. ";CHR$(34);">=";CHR$(34);" not ";CHR$(34);"> =";CHR$(34);")"
  98. 3960    GOSUB 37000 : GOSUB 37100
  99. 3970    PRINT T10$;"   In printing alphabetic messages, a blank is treated as"
  100. 3980    PRINT T10$;"any other character. This allows you to space the message"
  101. 3990    PRINT T10$;"as you like. (Beware of 'TABS' (ctrl I) in PRINT"
  102. 4000    PRINT T10$;"statements!!) Spaces (blanks) should be used to improve"
  103. 4010    PRINT T10$;"the legibilty of your program."
  104. 4020    PRINT
  105. 4030    PRINT T10$;"   Remember to use the 'REM'(') or remark statement to make"
  106. 4040    PRINT T10$;"notes in your programs. The slight cost in disk and memory"
  107. 4050    PRINT T10$;"space is rewarded whenever you or someone else needs to"
  108. 4060    PRINT T10$;"modify your work.";CRLF$
  109. 4070    PRINT T10$;"   See you in lesson 15.";CRLF$;CRLF$
  110. 4080    PRINT FNCENTER$("press any key for menu");
  111. 4090    FOR CT = 1 TO 22 : PRINT CHR$(8); : NEXT CT : GOSUB 40800
  112. 4100    GOTO 39999
  113.  
  114. 5000    PRINT
  115. 5020    PRINT "90 def fnr(q) = c1 * q^2 + c2 * q + c3"
  116. 5030    PRINT "    ."
  117. 5040    PRINT "    ."
  118. 5050    PRINT "120 let u = fnr(x) * sin(x)"
  119. 5060    PRINT "    ."
  120. 5070    PRINT "    ."
  121. 5080    PRINT "280 let v = fnr(y)^2"
  122. 5090    PRINT "    ."
  123. 5100    PRINT "    ."
  124. 5110    PRINT "370 let w = fnr(z)"
  125. 5120    PRINT
  126. 5199    RETURN
  127.  
  128. 37000    'press any key pause
  129. 37010    PRINT T10$;CRLF$;CRLF$;FNCENTER$("press any key to continue");
  130. 37020    FOR CT= 1 TO 25 : PRINT CHR$(8); : NEXT CT
  131. 37030    GOSUB 40800
  132. 37099    RETURN
  133.  
  134. 37100    ' heading
  135. 37110    PRINT CLS$;FNPOSCUR$(4,1);FNCENTER$("Tutor -- Lesson 14");CRLF$
  136. 37199    RETURN
  137.  
  138. 38000    ' converted for Non-linear Systems, Kaypro Educational Division
  139. 38010    ' by t.crew , Simple Software, San Diego CA
  140. 38020    ' has to be run with mentutr to get all variables
  141. 38030    ' tutor lesson 14 version 2.0  released to nls 1 aug 83
  142.  
  143. 39999    RUN "MENU" 'end of overlay
  144.  
  145.