Web pdp-10.trailing-edge.com

Trailing-Edge - PDP-10 Archives - decus_20tap1_198111 - decus/20-0024/tutr14.bas
There are 2 other files named tutr14.bas in the archive. Click here to see a list.
```00001REM   TUT14
00100PRINT"GLAD TO SEE YOU AGAIN.  I HOPE YOU HAVE BEEN PRACTICING"
00110PRINT"THE INSTRUCTIONS AS YOU LEARN THEM.  LEARNING HOW TO PROGRAM"
00120PRINT"WELL IS LIKE MASTERING A FOREIGN LANGUAGE.  ONLY REPEATED"
00130PRINT"EXERCISE CAN MAKE YOU PROFICIENT."
00140LETW=0
00150PRINT
00160PRINT"BEFORE WE UNDERTAKE ANY NEW WORK, LETS FIRST REVIEW SOME OF THE"
00170PRINT"BASIC STATEMENTS YOU HAVE PREVIOUSLY BEEN INTRODUCED TO."
00180PRINT
00190PRINT"AN ARITHMETIC FUNCTION MAY BE USED TO AVOID WRITING AN "
00200PRINT"IDENTICAL STATEMENT REPETITIOUSLY.  FOR EXAMPLE, YOUR"
00210PRINT"PROGRAM MAY REQUIRE THE FOLLOWING STATEMENTS;"
00220PRINT
00230PRINT"     120 LET U=(C1*X^2 + C2*X + C3) * SIN(X)"
00240PRINT"          ."
00250PRINT"          ."
00260PRINT"     280 LET V=(C1*Y^2 + C2*Y + C3)^2"
00270PRINT"          ."
00280PRINT"          ."
00290PRINT"     370 LET W=C1*Z^2 + C2*Z + C3"
00300PRINT"          ."
00310PRINT
00320PRINT"AN EASIER WAY TO DO THIS WOULD BE TO USE THE FUNCTION STATEMENT."
00330PRINT"WHICH OF THE FOLLOWING STATEMENTS WOULD BE INVOLVED (TYPE"
00340PRINT"THE NUMBER OF THE STATEMENT)"
00350PRINT
00360PRINT"    (1) GO TO     (2) REM     (3) DEF     (4) IF...THEN..."
00370PRINT
00380INPUTZ
00390PRINT
00400IFZ=3THEN460
00410LETW=W+1
00420PRINT"YOU'RE PUTTING ME ON.  A FUNCTION MUST BE PRECEDED BY THE"
00430PRINT"SYMBOL 'DEF', AN ABBREVIATION OF THE WORD 'DEFINE'."
00440PRINT
00450GOTO470
00460PRINT"RIGHT.  ";
00470PRINT"   YOU WOULD WRITE, FOR EXAMPLE, THE FOLLOWING ;"
00480PRINT
00490PRINT"      90 DEF FNR(Q)=C1*Q^2 + C2*Q + C3"
00500PRINT"          ."
00510PRINT"          ."
00520PRINT"     120 LET U=FNR(X) * SIN(X)"
00530PRINT"          ."
00540PRINT"          ."
00550PRINT"     280 LET V=FNR(Y)^2"
00560PRINT"          ."
00570PRINT"          ."
00580PRINT"     370 LET W=FNR(Z)"
00590PRINT
00600PRINT"REMEMBER - A FUNCTION, LIKE THE PARENTS OF A TEENAGER, ALWAYS"
00610PRINT"REQUIRES AN ARGUMENT.  IN THE DEFINING STATEMENT (90) THE"
00620PRINT"ARGUMENT IS Q.  WHEN USED IN THE BODY OF THE PROGRAM, THE"
00630PRINT"CALLED FOR ARGUMENT REPLACES THE 'DUMMY' ARGUMENT Q."
00640PRINT
00650PRINT"FOR EX., IF C1=1, C2=3, AND C3=6, WHAT IS THE VALUE OF FNR(3) ";
00660INPUTZ
00670PRINT
00680IFZ=24THEN720
00690LETW=W+1
00700PRINT"NO.  WOULD YOU BELIEVE 24?   (1*9 + 3*3 + 6)"
00710GOTO730
00720PRINT"VERY GOOD. "
00730PRINT
00740PRINT
00750PRINT"DID YOU UNDERSTAND THE DIFFERENCE BETWEEN A FUNCTION AND A"
00760PRINT"SUBROUTINE?  A SUBROUTINE IS USED TO AVOID WRITING IDENTICAL"
00770PRINT"GROUPS OF INSTRUCTIONS, WHEREAS A FUNCTION TREATS ONLY A SINGLE"
00780PRINT"LINE."
00790	PRINT
00800	PRINT"WHICH TWO OF THE FOLLOWING SYMBOLES DO YOU ASSOCIATE WITH THE"
00810PRINT"USE OF A SUBROUTINE? (TYPE THE 2 NUMBERS SEPARATED BY A COMMA)"
00820PRINT
00830PRINT"  (1) GO TO  (2) RETURN  (3) NEXT  (4) GOSUB  (5) END    ";
00840INPUTZ1,Z2
00850PRINT
00860LETZ=Z1*Z2
00870IFZ=8THEN940
00880LETW=W+1
00890IFW=1THEN920
00900PRINT"X@)@ZG@;=8C>:@<      (THE COMPUTER EQUIVALENT OF TSK, TSK)"
00910GOTO950
00920PRINT"SINCE THIS YOUR FIRST MISTAKE, I WON'T REPRIMAND YOU."
00930GOTO950
00940PRINT"RIGHT.   "
00950PRINT
00960PRINT"GOSUB XXX IS AN ABBREVIATED WAY OF INDICATING 'GO TO THE"
00970PRINT"SUBROUTINE WHICH STARTS AT LINE NUMBER XXX'.  THE RETURN"
00980PRINT"STATEMENT,WHICH SHOULD BE THE LAST STATEMENT IN THE SUBROUTINE,"
00990PRINT"IS A SIGNAL THAT WHEN THE SUBROUTINE HAS BEEN EXECUTED, CONTROL"
01000PRINT"WILL BE SENT BACK TO THE INSTRUCTION FOLLOWING THE GOSUB."
01010PRINT
01020PRINT
01030PRINT"THE FUNCTION AND SUBROUTINE CALLS ARE VERY POWERFUL INSTRUCTIONS"
01040PRINT"AND SHOULD BE MASTERED."
01050IFW<2THEN1080
01060PRINT"SINCE YOU MISSED ";W;"OF THE ABOVE QUESTIONS ABOVE, PERHAPS"
01070PRINT"YOU SHOULD REVIEW 'TUTR09' WHEN YOU ARE THROUGH HERE."
01080PRINT
01090PRINT
01100PRINT"YOU PROBABLY NOTICED THAT BLANKS WERE INSERTED BETWEEN SOME"
01110PRINT"OF THE WORDS USED IN THE STATEMENTS ABOVE.  TO IMPROVE"
01120PRINT"LEGIBILITY, BLANKS MAY BE USED FREELY IN ALL STATEMENTS,WITHOUT"
01130PRINT"AFFECTING THE INTENT OF THE STATEMENT IN ANY WAY,WITH BUT ONE"
01140PRINT"EXCEPTION.  WHICH ONE OF THE FOLLOWING EXAMPLES INDICATE WHAT"
01150PRINT"THIS EXCEPTION MIGHT BE?"
01151PRINT
01160PRINT"   (1) NEXTN             NEXT N"
01170PRINT"   (2) DEFFNG(Y)=...     DEF FN G(Y) = ..."
01180PRINT"   (3) GOTO200           GO TO 200"
01190PRINT"   (4) PRINT''RATE='';X  PRINT''RATE =   '';X   "
01200PRINT"   (5) INPUTX,Y,Z        INPUT X, Y, Z"
01210PRINT"   (6) LETX=2*Y+Z        LET X = 2*Y + Z"
01220PRINT"   (7) FORI=1TOK         FOR I = 1 TO K"
01230PRINT"   (8) END               E  N  D"
01240PRINT"   (9) GOSUB1245         GO SUB 1245"
01250	PRINT
01260PRINT"TYPE IN THE NUMBER OF YOUR CHOICE.   ";
01270INPUTZ
01280PRINT
01290PRINT"THIS WAS PRETTY TRICKY. ";
01300IFZ=4THEN1330
01310PRINT"NUMBER FOUR WAS THE CORRECT ANSWER."
01320GOTO1340
01340PRINT
01350PRINT"IN PRINTING OUT ALPHABETIC MESSAGES, A BLANK IS TREATED AS"
01360PRINT"ANY OTHER CHARACTER. THIS ALLOWS YOU TO SPACE THE MESSAGE"
01370PRINT"AS YOU LIKE.  HOWEVER, YOU CAN SEE THAT BLANKS CAN BE USED"
01380PRINT"AT WILL IN ALL OTHER STATEMENTS WHEN WRITING YOUR PROGRAM."
01390PRINT
01400PRINT"-----A WORD OF CAUTION - NO STATEMENT NUMBER MAY INCLUDE BLANKS"
01410PRINT"     EMBEDDED IN THEM.  THAT IS, 1 3 2 0 IS NOT TREATED AS 1320"
01420PRINT
01430PRINT"REMEMBER TO USE THE 'REM', OR REMARK, TO MAKE FOOTNOTES IN "