Google
 

Trailing-Edge - PDP-10 Archives - decuslib20-01 - decus/20-0024/tutr13.bas
There are 2 other files named tutr13.bas in the archive. Click here to see a list.
00001REM   TUT13
00100PRINT"A SUBROUTINE MAY BE THOUGHT OF AS A PROGRAM WITHIN A PROGRAM."
00110PRINT"THE STANDARD FUNCTIONS ARE USUALLY SUBROUTINES, SINCE WHEN ONE"
00120PRINT"OF THEM IS CALLED FOR, THE MACHINE SUBSTITUTES THE ARGUMENT INTO"
00130PRINT"A SERIES (SUM OF TERMS) TO EVALUATE THE FUNCTION. WE MAY WRITE"
00140PRINT"OUR OWN SUBROUTINE FOR A PROCESS TO BE DONE MORE THAN ONCE IN"
00150PRINT"OUR MAIN PROGRAM. THE SUBROUTINE WILL BE EXECUTED WHEN THE MAIN"
00160PRINT"PROGRAM TRANSFERS CONTROL TO IT. NOTE THESE EXPRESSIONS:"
             00170PRINT
00180PRINT"    (1) GOSUB    (2) DOSUB    (3) GOFOR    (4) ROUTINE"
00190PRINT
00200PRINT"WHICH LOOKS LIKE IT MIGHT CALL IN A SUBROUTINE (NUMBER ONLY) ";
00210INPUTS
00220PRINT
00230IFS=1THEN290
00240IFS<=4THEN270
00250PRINT"WAIT A MINUTE, NOW. USE '1', '2', '3', OR '4'. AGAIN: WHICH";
00260GOTO210
00270PRINT"IT DOESN'T, THOUGH. TRY ANOTHER ONE, OK";
00280GOTO210
00290PRINT"THAT'S IT. FOR INSTANCE, 'GOSUB 400' MEANS 'GO TO THE PROGRAM"
00300PRINT"(SUBROUTINE) WHICH BEGINS ON LINE 400'. AFTER THE SUBPROGRAM"
        00310PRINT"HAS BEEN EXECUTED, CONTROL IS RETURNED TO THE STATEMENT AFTER"
00320PRINT"THE ONE WHICH CALLED FOR THE SUBROUTINE. HOW IS THIS DONE:"
00330PRINT
00340PRINT"    (1) GOBACK    (2) MAIN    (3) RETURN    (4) GO TO"
00350PRINT
00360PRINT"DO YOU THINK (NUMBER OF CHOICE) ";
00370INPUTR
00380PRINT
00390IFR=3THEN420
00400PRINT"YOU HAVEN'T HIT THE RIGHT KEY, YET. NUMBER OF CHOICE....";
00410GOTO370
00420PRINT"YOU'VE GOT IT. YOU USE THIS ONE AS THE LAST STATEMENT IN YOUR"
00430PRINT"SUBPROGRAM SO AS TO RETURN TO THE POINT WHERE YOU LEFT THE MAIN"
   00440PRINT"PROGRAM. THE NEXT STATEMENT IN THE LATTER IS THEN EXECUTED."
00460PRINT"WE'LL TRY AN EXAMPLE. DO YOU PREFER A (1) GEOMETRY OR (2) LOGIC"
00470PRINT"SUBPROGRAM (TYPE IN NUMBER OF CHOICE) AS AN ILLUSTRATION";
00480INPUTE
00490PRINT
00500IFE=1THEN570
00510IFE=2THEN540
00520PRINT"WE DON'T HAVE THAT ONE. IS IT '1' OR '2'";
00530GOTO480
00540PRINT"HERE'S ONE THAT WILL GIVE US THE MAXIMUM AND MINIMUM VALUES OF"
00550PRINT"N NUMBERS, ASSUMING NO TWO NUMBERS ARE EQUAL. I'LL LEAVE ONE OF"
00560GOTO590
00570PRINT"HERE'S ONE TO COMPUTE THE RADIUS OF A CIRCLE, GIVEN TWO POINTS"
   00580PRINT"(X1,Y1) AND (X2,Y2) PLUS THE CROWN HEIGHT H. I'LL LEAVE ONE OF"
00590PRINT"THE MAIN PROBLEM STATEMENTS BLANK; WHEN I STOP TYPING, YOU FILL"
00600PRINT"IT IN CORRECTLY SO THAT IT WILL CALL IN OUR SUBROUTINE."
00620FORJ=100TO130STEP10
00630PRINT
00640PRINT"    ";J;"(MAIN PROGRAM STATEMENT)"
00650NEXT J
00660PRINT
00670PRINT"    ";J+10
00680FORJ=150TO170STEP 10
00690PRINT
00700PRINT"    ";J;"(MAIN PROGRAM STATEMENT)"
00710NEXTJ
00720PRINT
00730PRINT"(THE NEXT 8 STATEMENTS CONSTITUTE THE SUBROUTINE)"
                  00740PRINT
00750IFE=1THEN1080
00760PRINT"     200 LET B=A(1)"
00770PRINT
00780PRINT"     210 LET C=A(1)"
00790PRINT
00800PRINT"     220 FOR I=2 TO N"
00810PRINT
00820PRINT"     230 IF A(I)<=B THEN 250"
00830PRINT
00840PRINT"     240 LET B=A(I)"
00850PRINT
00860PRINT"     250 IF A(I)>=C THEN 260"
00870PRINT
00875PRINT"     255 LET C=A(I)"
00877PRINT
00880PRINT"     260 NEXT I"
00890PRINT
00900PRINT"     270"
00930PRINT
00940PRINT"NOW FILL IN LINE 140. WHAT STATEMENT DID YOU REFER TO";
             00950INPUTU
00960PRINT
00961IFU=140THEN966
00962IFU=200THEN975
00963PRINT"IT'S A LINE NUMBER IN THE SUBROUTINE. WHICH ONE";
00964GOTO967
00966PRINT"NO, I MEAN WHAT SUBROUTINE STATEMENT DID YOU REFER TO";
00967INPUTV
00968PRINT
00969IFV=200THEN975
00970PRINT"IT HAS TO BE 200. THIS IS THE FIRST LINE IN THE SUBROUTINE. NOW"
00971GOTO980
00975PRINT"RIGHT, SINCE THIS ONE IS THE FIRST LINE IN THE SUBROUTINE. NOW"
00980PRINT"FILL IN LINE 270. WHAT IS THE FIRST LETTER YOU PUT DOWN";
00990INPUTL
01000	PRINT
01010	PRINT"IT'S 'R', BECAUSE ALL YOU NEED HERE IS THE WORD 'RETURN'. THE"
01020PRINT"COMPUTER WILL RETURN CONTROL TO LINE 150. SEE HOW IT'S DONE?"
01030PRINT"TO COMPLETE THE PROGRAM, AN 'END' STATEMENT IS NECESSARY. THIS"
01040PRINT"MUST CARRY THE HIGHEST LINE NUMBER - SUBROUTINES INCLUDED."
01060GOTO2000
01080PRINT"     200 IF H<.000001 THEN 240"
01090PRINT
01100PRINT"     210 IF SQR((X2-X1)^2+(Y2-Y1)^2)<.000001 THEN 260"
01110PRINT
01120PRINT"     220 LET R=.5*H+.25/H*((X2-X1)^2+(Y2-Y1)^2)"
01130PRINT
01140PRINT"     230 GO TO 270"
                                               01150PRINT
01160PRINT"     240 PRINT ''CROWN HEIGHT CANNOT BE ZERO''"
01170PRINT
01180PRINT"     250 GO TO 270"
01190PRINT
01200PRINT"     260 PRINT ''YOU HAVE DEFINED ONLY ONE POINT''"
01210PRINT
01220PRINT"     270"
01230GOTO930
02000PRINT
02010PRINT"IF THE SUBROUTINE OCCURS BETWEEN THE MAIN PROGRAM AND THE 'END'"
02020PRINT"STATEMENT, A 'STOP' STATEMENT MAY ALSO BE NEEDED TO AVOID A"
02030PRINT"'NONSENSE' OUTPUT. SO THE FINAL PROGRAM COULD IN GENERAL BE:"
02050PRINT
02060PRINT"     100 (MAIN PROGRAM BEGINS)"
                                     02070PRINT"      .   ...."
02080PRINT"      .   ...."
02100PRINT"     140 GOSUB 200"
02110PRINT"      . (MAIN PROGRAM RESUMES)"
02120PRINT"      .   ...."
02130PRINT"     190 STOP"
02140PRINT"     200 (SUBROUTINE BEGINS)"
02150PRINT"      .   ...."
02160PRINT"      .   ...."
02170PRINT"     270 RETURN"
02180PRINT"     300 END"
02190PRINT
02200PRINT"I HOPE YOU WILL TRY USING SUBROUTINES IN YOUR OWN PROGRAMS,"
02210PRINT"SO THAT YOU CAN BECOME PROFICIENT AT WRITING THEM."
02215PRINT
02220PRINT"THERE IS AN EASY WAY OF ADDING GENERAL INFO TO YOUR PROGRAM."
       02250PRINT"THE COMPUTER WILL NOT EXECUTE (BUT IT WILL LIST) THE STATEMENT."
02255PRINT"HERE IS AN EXAMPLE OF A REMARK:"
02260PRINT
02270PRINT"     460 REM THIS PROGRAM COMPUTES PROBABLE HEAT LOSS"
02280PRINT
02290PRINT"NOTE THAT A STATEMENT NUMBER IS REQUIRED. SINCE THE COMPUTER"
02300PRINT"IGNORES A REMARK, CONTROL SHOULD NOT BE TRANSFERRED TO IT."
02310PRINT"REMARKS, LIKE OTHER STATEMENTS, MUST PRECEDE 'END'. OBVIOUSLY"
02320PRINT"THE PURPOSE OF 'REM' IS TO ENABLE A PROGRAMMER TO PUT COMMENTS"
02330PRINT"THROUGHOUT HIS PROGRAM."
                                          02340PRINT"CALL 'TUTR14*' FOR YOUR NEXT LESSON."
02400END