3000 REM ************************************* 3010 REM ** INTER1.BAS ** 3020 REM ************************************* 3030 filename$="INTER1.BAS":GOTO 2290 4000 PRINT cls$:PRINT "GENERAL COMMANDS FOR PROGRAM CREATION ":filename$="INTER1.BAS" 4010 PRINT "************************************* " 4020 PRINT:PRINT: 4030 PRINT "This section covers the following commands " 4040 PRINT:PRINT "NEW","AUTO","LIST","EDIT","SAVE","LOAD","RUN","RENUM","REM","RENUM","SYSTEM","END","STOP","CONT","TYPE","DISPLAY","VERSION","WIDTH" 4050 PRINT:PRINT:PRINT 4100 GOSUB 40050 4110 PRINT cls$:TYPE INTER.A 4120 GOSUB 40150 4130 ON code GOTO 6000,6000,4100,4100,2290,2290 6000 PRINT cls$:PRINT "Mathematics":filename$="INTER1.BAS" 6010 PRINT "*********** " 6020 PRINT:PRINT: 6030 PRINT "This section covers the following commands " 6040 PRINT:PRINT "SIN","COS","TAN","ATN","LOG","LOG10","EXP","SQR","^" 6050 PRINT "+","-","*","/","\","MOD" 6060 PRINT "MAX","MIN","ABS","SGN","INT","FIX","ROUND" 6070 PRINT "%","!","#","&H","&O", 6080 PRINT "DEFINT","DEFSNG","DEFDBL" 6090 PRINT:PRINT 6100 GOSUB 40050 6110 PRINT cls$:TYPE INTER.B 6120 GOSUB 40150 6130 ON code GOTO 6200,6200,6110,6110,2290,2290 6200 PRINT cls$ 6210 LIST 6220-6330 6220 PRINT "***** TRIGONOMETRY ******" 6230 PRINT " This program works out the values of sine,cosine,tangent and arctangent for any value of angle BETWEEN 0 to 90 degrees inclusive. Just type your figure (in decimal) at the prompt " 6240 PRINT: INPUT " What angle would you like "; a 6250 IF a<=0 OR a>=90 THEN PRINT "A number BETWEEN 0 to 90 please": GOTO 6240 6260 rad = a*6.284/360 :REM convert degrees to RADIANS 6270 PRINT TAB(30) " Cosine ......." a"degrees =" COS(rad) 6280 PRINT TAB(30) " Sine ........." a"degrees =" SIN(rad) 6290 PRINT TAB(30) " Tangent ......" a"degrees =" TAN(rad) 6300 INPUT " Another angle ? y/n ",a$: IF a$="y" OR a$="Y" THEN 6240 ELSE 6310 6310 IF a$="n" OR a$="N" THEN 6400 ELSE PRINT " y or n please ":GOTO 6300 6315 '********************************************************* 6320 '* To run this program type GOTO 6220 then press RETURN * 6330 '********************************************************* 6400 GOSUB 40100: PRINT cls$:LIST 6410-6500 6410 PRINT "***** LOGARITHMS *****" 6420 PRINT " This program gives the logarithms of a range of numbers on demand. Both common logs(to base 10) and Naperian logs(to base e) are given .Just type your number at the prompt. 6430 PRINT:INPUT " Type any number "; L 6440 PRINT TAB(30) "log10 of " l " is .........."LOG10(L) 6450 PRINT TAB(30) "log e of " L " is .........." LOG(L) 6460 INPUT "Do you want another number y/n "; a$ 6470 IF a$= "y" OR a$= "Y" THEN 6430 ELSE IF a$= "n" OR a$= "N" THEN 6490 ELSE 6480 6480 PRINT "type y or n please ": GOTO 6460 6485 REM **************************************************************** 6490 REM **** To run this program type GOTO 6410 then press [return] **** 6500 REM **************************************************************** 6550 GOSUB 40100:PRINT cls$:LIST 6560-6660 6560 PRINT "***** POWERS OF NUMBERS ***** " 6570 PRINT :INPUT " Enter a number ", n 6580 PRINT TAB(30) " the square root of "n" =" SQR(n) 6590 PRINT TAB(30) n " cubed =" n^3 6600 PRINT TAB(30) " the fifth power of "n" =" n^5 6610 PRINT TAB(30) " the reciprocal of "n" =" n^-1 6620 PRINT TAB(30) " the square root of "n" =" n^0.5 :REM an alternative way 6630 PRINT TAB(30) " the fourth root of "n" =" n^0.25 6640 REM The exponential symbol ^ is typed by EXTRA + ; (semicolon) 6645 REM ************************************************************** 6650 REM *** To run this program type GOTO 6560 then press [RETURN] *** 6660 REM **************************************************************: GOSUB 40100 6710 GOSUB 40100: PRINT cls$: LIST 6720-6860 6720 PRINT " ***** FORMATTED PRINTING ***** " 6730 PRINT " This shows how to print columns of numbers, keeping the decimal points in line. It is also used for printing sums of money." 6740 PRINT: 6750 INPUT " enter your first decimal number " ,num(1) 6760 INPUT " enter your second decimal number" ,num(2) 6770 INPUT " enter your third decimal number " ,num(3) 6780 PRINT:total = num(1)+num(2)+num(3) 6790 FOR a= 1 TO 3 6800 PRINT TAB(20) num(a); TAB(50) USING "######.##"; num(a) 6810 NEXT 6820 PRINT TAB(20) "======="; TAB(50) "===========" 6830 PRINT TAB(20) total; TAB(50) USING "######.##";total 6840 REM ************************************************************** 6850 REM *** To run this program type GOTO 6720 then press [RETURN] *** 6860 REM ************************************************************** 8000 GOSUB 40100: PRINT cls$:PRINT "String manipulation " :filename$= "INTER1.BAS" 8010 PRINT "******************* " 8020 PRINT:PRINT: 8030 PRINT "This section covers the following commands " 8040 PRINT:PRINT "LEFT$","RIGHT$","MID$","UPPER$","LOWER$","INSTR","LEN" 8050 PRINT:PRINT:PRINT 8100 GOSUB 40050 8110 PRINT cls$:TYPE INTER.C 8120 GOSUB 40150 8130 ON code GOTO 10000,10000,8100,8100,2290,2290 10000 PRINT cls$:PRINT "More on Variables" :filename$= "INTER1.BAS" 10010 PRINT "***************** " 10020 PRINT:PRINT: 10030 PRINT "This section covers the following commands " 10040 PRINT:PRINT "DEFINT","DEFSGL","DEFDBL","DEFSTR" 10045 PRINT:PRINT "and the following variable type suffixes" 10050 PRINT:PRINT "%","!","#","$" 10060 PRINT:PRINT:PRINT 10100 GOSUB 40050 10110 PRINT cls$:TYPE INTER.D 10120 GOSUB 40150 10130 ON code GOTO 12000,12000,10100,10100,2290,2290 10190 ON ERROR GOTO 11500 10200 PRINT:PRINT "For a program demonstrating DEFINT,DEFSNG,DEFDBL and DEFSTR see DEFINT.BAS" 10210 PRINT "as was discussed in the previous file INTER.D" 10290 PRINT 10300 PRINT " NUMERIC VARIABLE TYPE SUFFIXES % , ! , # " 10310 PRINT "******************************************* " 10320 PRINT:PRINT " The variable num has been chosen by me to represent various numbers" 10330 PRINT " to be entered by you. Try various numbers and see how they are affected" 10340 PRINT " Numeric variables are limited on the range of numbers they can represent " 10350 PRINT " For example num% (integer) is limited to -32768 to +32767. If you try " 10360 PRINT " to enter too large a number you will be asked to try again" 10370 PRINT " Note that numbers out of range of num% may be acceptable by num,num! or num#" 10380 PRINT " This program only accepts a small range for demonstration. Check this point!" 10510 PRINT:INPUT " Enter a decimal number e.g 24.9876 then press [RETURN] ", num 10520 PRINT:PRINT:PRINT:num%=num:num!=num:num#=num 10530 PRINT "With no suffix the number you have entered is processed as...." num 10540 PRINT "With suffix % the number you have entered is processed as...." num% 10550 PRINT "With suffix ! the number you have entered is processed as...." num! 10560 PRINT "With suffix # the number you have entered is processed as...." num# 10600 PRINT:INPUT" Do you wish to try another number? y/n ", z$ 10610 IF z$="y" OR z$="Y" THEN GOTO 10510 10620 IF z$="n" OR z$="N" THEN GOTO 10700 10630 PRINT "please type y or n " :GOTO 10600 10700 PRINT:PRINT " STRING VARIABLE SUFFIX $ " 10710 PRINT " ************************ " 10715 PRINT: INPUT " Type in your name then press [RETURN] ", name$ 10720 PRINT: INPUT " Type in another name then press [RETURN] ", name1$ 10730 PRINT:PRINT "Your name is in variable name$, the other name in variable name1$" 10740 PRINT:PRINT " PRINT name$ ........." ; name$ 10750 PRINT " PRINT name1$ ........" ; name1$ 10760 PRINT:PRINT " SWAP " 10770 PRINT " **** " 10780 PRINT :PRINT " SWAP name$, name1$ ": SWAP name$, name1$ 10790 PRINT:PRINT " PRINT name$ ........." ; name$ 10800 PRINT " PRINT name1$ ........" ; name1$ 10810 PRINT: PRINT:PRINT " To list this section type LIST 10000-11500. You will then " 10820 PRINT " see how I have 'cheated' to reveal variables that would not usually " 10830 PRINT " be seen in a program being run " 10850 GOSUB 40100 10860 GOTO 12000 10990 END 11500 PRINT "OVERFLOW ... Try a smaller number": GOTO 10510 11520 REM ************************************************************** 11530 REM ** Type GOTO 1000 then press [RETURN] to rerun the program ** 11540 REM ************************************************************** 12000 PRINT cls$:PRINT "Further work on Loops ":filename$= "INTER1.BAS" 12010 PRINT "********************* " 12020 PRINT:PRINT: 12030 PRINT "This section covers the following commands " 12040 PRINT:PRINT "WHILE...WEND","","GOTO","","GOSUB...RETURN" 12045 PRINT:PRINT "IF...THEN...ELSE","","ON xxx GOTO/GOSUB" 12050 PRINT:PRINT:PRINT 12070 PRINT:PRINT:PRINT 12100 GOSUB 40050 12110 PRINT cls$:TYPE INTER.E 12120 GOSUB 40150 12130 ON code GOTO 14000,14000,12100,12100,2290,2290 12150 PRINT:PRINT "NESTING a FOR...NEXT loop" 12160 PRINT "*************************" 12170 GOSUB 40100:PRINT:PRINT cls$:LIST 12180-12290 12180 FOR a=1 TO 4 12190 PRINT "Have a "; 12200 FOR b=1 TO 4 12210 PRINT "nice "; 12220 FOR c=1 TO 4 12230 PRINT "day."; 12240 NEXT c 12250 NEXT b 12260 NEXT a 12270 REM ******************************************************************* 12280 REM ** To see how this loop runs type GOTO 12180 then press [RETURN] ** 12290 REM ******************************************************************* 12300 PRINT:PRINT:PRINT "Perhaps not what you expected!; but see how the nested loops sequence" 12310 PRINT "First the program runs through from 12180 to 12240 printing 'Have a nice day' 12320 PRINT "At line 12240 the NEXT sends it back to the 'c' loop which loops until c=4 " 12330 PRINT "Then the NEXT at line 12250 sends it back to go through the 'b' loop (which 12340 PRINT "includes another 'c' loop and so on. Study this and experiment with it please" 12500 PRINT:PRINT " The WHILE......WEND loop " 12510 PRINT " ************************ " 12530 GOSUB 40100:PRINT cls$: LIST 12540-12610 12540 n=0 12550 WHILE n<10 12560 PRINT "Hello " n 12570 n=n+1 12580 WEND 12590 REM *********************************************************************** 12600 REM ** To see how this listing runs type GOTO 12540 then press [RETURN] *** 12610 REM *********************************************************************** 12620 PRINT :PRINT" NOTES: n<10 means 'n is less than 10'. n starts with a value of " 12630 PRINT " 0 and increases by one at each loop until it reaches 9. On the next " 12640 PRINT " loop n is no longer less than 10 and so the program continues." 12645 GOSUB 40100: PRINT cls$: LIST 12660-12730 12650 PRINT :PRINT 12660 INPUT "What is the capital city of England? ", city$ 12670 WHILE UPPER$(city$)<> "LONDON" 12680 PRINT "Wrong - try again " : GOTO 12660 12690 WEND 12700 PRINT " Correct- well done!" 12710 REM ********************************************************************** 12720 REM ** To see how this loop runs type GOTO 12660 then press [RETURN] ***** 12730 REM ********************************************************************** 12740 PRINT:PRINT " Your answer to the question is stored in the variable city$." 12750 PRINT" If you give the wrong answer the WHILE condition is met and the loop " 12760 PRINT" operates, printing line 12680 and returning to line 12660 (GOTO loop)" 12770 PRINT" Line 12670 puts your answer into upper case and compares it with LONDON" 12780 PRINT" If your answer matches,the condition is not met ( <> means 'not equal to')" 12790 PRINT" and the loop drops through to line 12700" 12800 PRINT :PRINT " Nesting a WHILE.......WEND loop " 12810 PRINT "*********************************" 12820 GOSUB 40100 :PRINT cls$ 12830 LIST 12840 - 12920 12840 n=2:WHILE n MOD 2=0 12850 INPUT " Type any number .......", n 12860 IF n MOD 2=0 THEN PRINT "Your number is even" ELSE PRINT "Your number is odd; dropping through the loop !" 12870 PRINT "Press any key" 12880 WHILE INKEY$="" 12885 WEND 12890 WEND 12900 REM ************************************************************************** 12910 REM *** To see how this program runs type GOTO 12840 then press [RETURN] ***** 12920 REM ************************************************************************** 12950 PRINT:PRINT "Finding an example of nested WHILE....WEND loops has not been easy, and I" 12960 PRINT "have fallen back on the well-used loop in 12880 for the inner loop; at least" 12970 PRINT "it demonstrates the method. Line 12840 starts n as an even number and then" 12980 PRINT "the loop operates as long as you keep entering even numbers. (n MOD 2 divides" 12990 PRINT "n by 2 and gives the remainder). Note that each loop has it's own WEND and " 13000 PRINT "the loops are nested in the same way as the FOR...NEXT loops" 13010 PRINT " To rerun the last listing type GOTO 12830, then [RETURN] " 13050 PRINT :PRINT " Nesting an IF...THEN command inside a WHILE...WEND loop" 13060 PRINT " *******************************************************" 13070 GOSUB 40100:PRINT cls$ :LIST 13080-13160 13080 count=0 13090 WHILE count <3 13100 INPUT "Enter an integer between 6 and 50 ..........", x 13110 IF x MOD 2=0 OR x MOD 3=0 OR x MOD 5=0 THEN PRINT "Your number is not a prime" ELSE PRINT "Your number is a prime" 13120 count = count +1 13130 WEND 13140 REM ********************************************************************** 13150 REM ** To see how this loop runs type GOTO 13080 then press [RETURN] ** 13160 REM ********************************************************************** 13190 PRINT :PRINT "The variable 'count' is set to 0 (line 13080). The loop will operate until count =3 13200 PRINT "Line 13120 adds 1 to 'count' at each loop and so the loop goes 3 times before dropping " 13210 PRINT "through " 13220 PRINT "The foregoing are examples of types of loops, but the possibilities are" 13230 PRINT "endless. Please look for examples of loops in books and magazines and " 13240 PRINT "try some for yourself. " 14000 PRINT cls$:PRINT "Tables & Arrays ":filename$= "INTER1.BAS" 14010 PRINT "*************** " 14020 PRINT:PRINT: 14030 PRINT "This section covers the following commands " 14040 PRINT:PRINT "DIM","RESTORE","READ","DATA" 14050 PRINT:PRINT:PRINT 14100 GOSUB 40050 14110 PRINT cls$:TYPE INTER.F 14120 GOSUB 40150 14130 ON code GOTO 14200,14200,14100,14100,2290,2290 14200 PRINT cls$: LIST 14210-14350 14210 DIM name$(12) 14220 FOR y= 1 TO 12 14230 READ name$(y) 14240 NEXT 14250 DATA " Dave "," Jim "," Bob "," Alec "," Harry "," Frank " 14260 DATA " Bill "," John "," Dave "," Terry "," Andy "," Don " 14270 FOR a= 1 TO 12 STEP 2 14280 PRINT name$(a); 14290 NEXT 14300 PRINT:PRINT "*********** press any key ************" 14310 WHILE INKEY$="":WEND 14320 PRINT name$(4);name$(8);name$(12) 14330 '**************************************************************** 14340 '** To see how this listing runs type GOTO 14210 then [RETURN] ** 14350 '**************************************************************** 14400 PRINT "The above program demonstrates how to form and use a simple array" 14410 PRINT " 1) Reserve space in memory for array of more than 10 items [line 14210]" 14420 PRINT " 2) READ data into the series of variable [lines 14220 to 14440] 14430 PRINT " 3) DATA lines. Note that these can be anywhere in the program. They can" 14440 PRINT " be before the READ section or split up. READ will find them. Try it!" 14450 PRINT " 4) Simple ways of recovering the data [lines 14470 to 14320]. 14460 PRINT:PRINT "*********** press any key ************" 14465 WHILE INKEY$="":WEND 14466 LIST 14470-14560 14470 DATA " Bill "," John "," Dave "," Terry "," Andy "," Don " 14480 RESTORE 14470 14490 FOR c=1 TO 6 14500 READ team$(c) 14510 NEXT 14520 PRINT " The team for Saturday's match will be" team$(2)" and" team$(5) 14540 '**************************************************************** 14550 '** To see how this listing runs type GOTO 14480 then [RETURN] ** 14560 '**************************************************************** 14570 PRINT:PRINT "*********** press any key ************" 14580 WHILE INKEY$="":WEND 14590 PRINT cls$ 14600 LIST 14610-14783 14610 DIM n$(3,5) 14620 RESTORE 14680 14630 FOR a=1 TO 3 14640 FOR b=1 TO 5 14650 READ n$(a,b) 14660 NEXT b 14670 NEXT a 14680 DATA "a","b","c","d","e","f","g","h","i","j","k","l","m","n","p" 14690 PRINT " A simple 2-dimensional array contains the 15 letters a to p. Select various" 14700 PRINT " columns and rows and build up a representation of the array on paper." 14710 PRINT " To escape, type in a as 0 (zero)" 14720 PRINT:PRINT:INPUT " Which row (1 to 3)", a 14730 IF a=0 THEN GOTO 14790 14740 IF a<1 OR a>3 THEN PRINT "number out of range-try again": GOTO 14720 14750 INPUT " Which column(1 to 5)",b 14760 IF b<1 OR b>5 THEN PRINT "number out of range-try again": GOTO 14750 14770 PRINT n$(a,b) 14780 GOTO 14720 14781 '**************************************************************** 14782 '** To see how this listing runs type GOTO 14610 then [RETURN] ** 14783 '**************************************************************** 14790 PRINT "*** END OF INTER1.BAS == press any key to return to section menu ***" 14800 WHILE INKEY$="":WEND 14810 PRINT cls$:GOTO 2300 39990 END INTER1.BAS == press any key to return to section menu ***" 14800 WHILE INKEY$="":WEND 14810 PRINT cls$:GOTO 2300