Google
 

Trailing-Edge - PDP-10 Archives - decuslib20-01 - decus/20-0024/tutr12.bas
There are 2 other files named tutr12.bas in the archive. Click here to see a list.
00001REM   TUT12
00100PRINT"BEFORE WE GO ON TO DEFINING FUNCTIONS, WOULD YOU LIKE TO REVIEW"
00110PRINT"THE MEANINGS OF THE STANDARD ONES (0=NO, 1=YES) ";
00120INPUTY
00130PRINT
00140IFY=0THEN1020
00150IFY=1THEN180
00160PRINT"PLEASE USE BINARY (ONLY '0' OR '1'). WHICH IS IT . . . . ";
00170GOTO120
00180PRINT"GOOD. USE THIS ANSWER SELECTION:"
00190PRINT
00200PRINT"    (1) SIN(X)    (2) COS(X)    (3) TAN(X)    (4) ATN(X)"
00210PRINT
00220PRINT"    (5) EXP(X)    (6) ABS(X)    (7) LOG(X)    (8) SQR(X)"
             00230PRINT
00240LETR=0
00250PRINT"USE THE NUMBER OF YOUR CHOICE FOR EACH QUESTION BELOW."
00260PRINT
00270PRINT"WHICH FUNCTION FINDS THE ABSOLUTE VALUE";
00280INPUTA
00290LETR=R+1
00300PRINT
00310IFA=6THEN360
00320PRINT"NOPE, THE FUNCTION NAME IS AN ABBREVIATION FOR WHAT IT DOES."
00330PRINT"TRY AGAIN - WHICH ONE....";
00340GOTO280
00350GOTO310
00360PRINT"GOOD. THE NEXT QUESTION IS HARDER: WHAT FUNCTION DETERMINES THE"
00370PRINT"NATURAL LOGARITHM OF 'X'";
00380INPUTA
00390LETR=R+1
00400PRINT
00410	IF A=7 THEN 440
00420PRINT"NO - CHECK THE ABBREVIATION FOR 'LOGARITHM'. NOW WHICH....";
00430GOTO380
00440PRINT"VERY GOOD. THE NEXT ONE IS EASY: WHAT'S THE SINE FUNCTION";
00450INPUTA
00460LETR=R+1
00470PRINT
00480IFA=1THEN510
00490PRINT"TRY AGAIN, PLEASE. WHICH ONE....";
00500GOTO450
00510PRINT"RIGHT. WHICH FUNCTION GIVES AN ANGLE WHOSE TANGENT IS 'X'";
00520INPUTA
00530LETR=R+1
00540PRINT
00550IFA=4THEN580
00560PRINT"IT'S TRICKY. TRY AGAIN: WHICH IS IT..";
00570GOTO520
00580PRINT"EXCELLENT. NOW FOR THE HARDEST: WHAT FUNCTION COMPUTES 'E^X'";
        00590INPUTA
00600LETR=R+1
00610PRINT
00620IFA=5THEN650
00630PRINT"WELL IT'S HARD. HINT: WHAT IS THE EXPONENTIAL (POWER) OF 'E'";
00640GOTO590
00650PRINT"TERRIFIC. THE REST ARE TRIVIAL, SO WE MIGHT AS WELL MOVE ON."
00660IFR=5THEN680
00670GOTO690
00680PRINT"BY THE WAY, YOU GET A 'BIG FAT GOLD STAR' FOR A PERFECT SCORE."
00690PRINT"HERE ARE SOME RESTRICTIONS WHICH APPLY TO CERTAIN FUNCTIONS:"
00700PRINT"THE ARGUMENT OF THE SINE, COSINE, AND TANGENT FUNCTIONS MUST"
00710PRINT"BE IN RADIAN MEASURE. THE ARCTANGENT GIVES AN ANGLE IN RADIANS."
   00720PRINT
00730PRINT"THE LOGARITHM OF A NEGATIVE NUMBER IS NOT DEFINED. SO IF THE"
00740PRINT"ARGUMENT IS NEGATIVE, AN ERROR MESSAGE WILL APPEAR AND THE"
00750PRINT"COMMAND WILL BE EXECUTED WITH A POSITIVE ARGUMENT. IF 'SQR' HAS"
00760PRINT"A NEGATIVE ARGUMENT, THEN ANOTHER ERROR MESSAGE APPEARS AND A"
00770PRINT"POSITIVE ARGUMENT IS USED. THE ARGUMENT OF A FUNCTION MAY BE ANY"
00780PRINT"EXPRESSION, AS LONG AS IT HAS A NUMERICAL VALUE."
00790PRINT
00800PRINT"LET'S MAKE A TABLE OF 'X' AND 'SIN(X)' FOR 0<=X<=360 DEGREES IN"
   00810PRINT"STEPS OF 60 DEGREES. HERE'S A PROGRAM WHICH WILL DO IT:"
00820PRINT
00830PRINT"    10 LET X=3.14159/180           (DEGREES TO RADIANS)"
00840PRINT"    20 FOR I=0 TO 360 STEP 60      (START OF LOOP)"
00850PRINT"    30 PRINT I, SIN(X*I)           (OUTPUT STATEMENT)"
00860PRINT"    40 NEXT I                      (END OF LOOP)"
00870PRINT"    50 END                         (LAST STATEMENT)"
00880PRINT
00890PRINT"IF YOU WOULD LIKE TO HAVE THIS PROGRAM RUN, TYPE '1'. IF NOT,"
00900PRINT"TYPE ANY OTHER NUMBER. WOULD YOU....";
                            00910INPUTB
00920PRINT
00930IFB<>1THEN1040
00940LETX=3.14159/180
00950FORI=0TO360STEP60
00960PRINTI,SIN(X*I)
00970NEXTI
00980PRINT
00990PRINT"COLUMN HEADINGS WOULD PROBABLY HAVE IMPROVED THE OUTPUT. ALSO,"
01000PRINT"TWO FUNCTIONS WERE NOT SHOWN ABOVE. 'INT' EXTRACTS THE WHOLE"
01010GOTO1060
01020PRINT"OK, BUT TWO SHOULD INTEREST YOU. 'INT' EXTRACTS THE WHOLE"
01030GOTO1060
01040PRINT"ANYWAY, IT DOES THE JOB. DON'T FORGET: IN ADDITION TO THE "
01050PRINT"EIGHT FUNCTIONS ABOVE, THERE'S 'INT', WHICH EXTRACTS THE WHOLE"
  01060PRINT"NUMBER PART OF ANY NUMBER. IF N=27.68, THEN WHEN THE STATEMENT"
01070PRINT"'PRINT INT(N)' IS USED, THE COMPUTER WILL PRINT '27'. THE OTHER"
01080PRINT"STANDARD FUNCTION IS 'RND(X)', WHICH GENERATES A NUMBER (NOT"
01090PRINT"SPECIFIED) BETWEEN 0 AND 1. IT HAS AN UNUSED ('DUMMY') ARGUMENT."
01100PRINT
01110IFY=0THEN1130
01120PRINT"I'LL REMIND YOU OF A PROGRAM ON STANDARD FUNCTIONS LATER. NOW"
01130PRINT"LET'S SHOW HOW WE CAN WRITE OUR OWN FUNCTIONS. THIS IS DONE"
01140PRINT"BY MEANS OF THE TERM 'DEF' (FOR 'DEFINE'). HERE IS AN EXAMPLE:"
  01150PRINT
01160PRINT"     DEF FNP(C) = C+.57*C"
01170PRINT
01180PRINT"THE 'FN' MEANS 'FUNCTION' TO THE COMPUTER, AND 'P' IS THE NAME"
01190PRINT"OF THE FUNCTION. A FUNCTION NAME IS A SINGLE LETTER, SO YOU"
01200PRINT"ARE ALLOWED 26 PER PROGRAM. TYPE '1' IF YOU THINK 'C' IS THE"
01210PRINT"ARGUMENT. OTHERWISE TYPE ANOTHER NUMBER. WHAT DO YOU SAY";
01220INPUTA
01230PRINT
01240IFA=1THEN1270
01250PRINT"WRONG GUESS - 'C' IS OPERATED ON; THE RIGHT SIDE SHOWS HOW."
01260GOTO1280
01270PRINT"OF COURSE. ANY FUNCTION NEEDS AN ARGUMENT. ON THE RIGHT SIDE,"
       01280PRINT"'C+.57*C' WILL HAVE A VALUE DEPENDENT UPON THE SIZE OF 'C'. IF"
01290PRINT"'P' IS A SALES PRICE BASED ON A 57 PERCENT MARKUP OVER COST,"
01300PRINT"THEN THE EXPRESSION COULD BE READ: 'THE PRICE FUNCTION OF COST"
01310PRINT"IS DEFINED AS C+.57*C'."
01320PRINT
01330PRINT"THE FOLLOWING SAMPLE PROGRAM INCORPORATES THE ABOVE FUNCTION:"
01340PRINT
01350PRINT"     100 DEF FNP(C) = C+.57*C"
01360PRINT"     110 READ C"
01410PRINT
01420PRINT"FOR A COMPLICATED FUNCTION USED MORE THAN ONCE IN A PROGRAM,"
01430PRINT"THE DEFINE STATEMENT HAS OBVIOUS ADVANTAGES. MORE EXAMPLES"
       01440PRINT"OF USING DEFINED FUNCTIONS WILL BE INCLUDED IN LATER LESSONS."
01450PRINT
01460PRINT"WE'LL CONCLUDE THIS LESSON WITH A DISCUSSION OF SUBROUTINES"
01470PRINT"AND A BRIEF EXPLANATION OF THE USE OF THE 'REMARK' STATEMENT."
01480PRINT"YOU'LL FIND THESE THINGS IN THE PROGRAM CALLED 'TUTR13*'."
01490IFY=0THEN1520
01500PRINT"REMEMBER, YOU CAN GET PRACTICE WITH STANDARD FUNCTIONS IF YOU"
01510PRINT"CALL IN 'TUTR11*' BEFORE YOU DO 'TUTR13*'. YOUR CHOICE...."
01520END