background image

Summary of Contents for TRS-80 Model 100

Page 1: ... MODEL 100 BASIC LANGUAGE LAB I I 1 ...

Page 2: ...TOM MIO lilli IIi 0 _ u_ tfl S OJI II l_ 00 IfCT IIi fIW t_ _ KIlo La _ 00 lUI 0 l Il S OS 0Il lh 1lMW U lING USf _ _ 01 ClMWI l orwlO ll III roo OT _ _ t KI IlfJS Of _ 011 WIll _ M I os 011 _ OIl _ u u _ _ _ _ tOOl IlOS _ SUIlOUT _ Q _ M lIDIE l 0I l l lQEO orr IOtI M JOIi _ _ _ _ _ _ t _ _ _ _ _or _11 _ _ _ __ _ _ _ _ _ _1 Q Sl _ _ _ _ _ _ _ I r _ _ _ __J _ wsK lOlll M __ _ _ _ _ o CI IO _ _ _ _...

Page 3: ...Model 100 BASIC Language Lab A DIVISION OF TANDY CORPORATION FORT WORTH TEXAS 78102 ...

Page 4: ...tion or use without express written permission from Tandy Corporation uf any portion of this manual is prohibited While reasonable efforts have been taken in the preparation of this manual to assure its accuracy Tandy Corporation assumes no liability resulting from any errors or omissions in this manual or from the use of the information contained herein 109 8 7 6 5 4 3 2 1 ...

Page 5: ...sing the Editor 69 Lesson 7 Sales Trend 87 Lesson 8 Plot Your Data 99 Lesson 9 Functions 111 Lesson 10 Data Files 123 Lesson 11 Average Sales 131 Lesson 12 Sound Simulation 145 Lesson 13 Function Keys 155 Lesson 14 Using the COM Option 165 Lesson 15 TELCOM Applications 175 Application 1 Calculator 185 Application 2 Memory Master Game 189 Application 3 Descriptive Statistics 195 Index 203 ...

Page 6: ......

Page 7: ...rs Write programs for a wide range of applications such as forecasting sales trends and performing interest or mortgage calculations Make use of the computer s graphic and sound capabilities and a host of other operations This course will show you how to perform operations such as these by explaining in detail the BASIC section of your Model 100 Owner s Manual This means that by the time you ve fi...

Page 8: ......

Page 9: ...s pressed After pressing ENTER the line just typed is placed in memory for processing by the Computer Throughout this Manual the phrase enter this command will be used often This simply means that you should press after typing the command or instruction Also when we tell you to press you should press both SHIFT and PAUSE together Accessing BASIC Prior to typing or editing a BASIC program you must ...

Page 10: ...mediately In this experiment you will learn how to enter a simple command First you will attempt to have the Model 100 print out a name on the display Type the name JOHN SMITH You may use any other name Now press As soon as you do this the Computer displays the message 8N Error This message indicates that an error specifically a syntax error has been made The syntax error occurred because the Comp...

Page 11: ...g of only one statement the PRINT statement accomplishes the same thing as the command PRINT JOHN SMITH CENnID But because the word PRINT is being used in a program and preceded by a line number it is now called a statement The number H J which is typed before the PRINT statement is called a line number Every line in a BASIC program must have a line number even if the program contains only a singl...

Page 12: ...g is that the PRINT instruction has a smaller line number than the GOTO instruction Execute the program with the RUN command or by pressing As you can see unlike the first single line program this second program prints the name within quotation marks repeatedly This is known as an infinite loop program because the GOTO statement in the second line of the program simply transfers control back to th...

Page 13: ...the program run a few seconds terminate it by pressing This time after pressing enter the command CONT As you can see the program resumes execution The CONT command is used to CONTinue execution after the program has been broken Execution will start at the same place where the program was interrupted Experiment 3 Simple Editing Here s the program from the previous experiment 1121 PRINT RADIO SHACK...

Page 14: ...ey again Pausing a program may be useful when you want to read what is being displayed before it scrolls off view Of course this program must still be terminated by pressing BREAK because it still is in an infinite loop Try a few other experiments with the PRINT command Type in the following program 10 PRINT MY NAME IS 20 PRINT LEE Run this program The output should be M NAJvIE IS LEE Ok Now retyp...

Page 15: ...ed to space the name further apart you could add more spaces after IS or you could add spaces before LEE in line 20 Another way to space the printing is to use a comma instead of a semicolon Retype line 10 so that it reads 10 PRINT MY NAME IS Now list the program and it should read LIST 10 PRINT MY NAME IS 20 PRINT LEE Ok Run this program The output should appear as NAME IS L EE This time IS and L...

Page 16: ... without a space Now if line 10 is retyped so that the comma is changed to a semicolon and the semicolon at the end of the statement is omitted 1121 PRINT HOW NOW 2121 PRINT BROWN COW the output would be HOW NOW BROWNCOW The second PRINT statement produces output on the second line because the carriage return after the first PRINT statement has not been suppressed with a semicolon or comma If you ...

Page 17: ...ine from a program all you have to do is to type the line number of the statement you wish to delete and press For example list the current program PRI NT HOW NOW PRINT BROWN COW Now type 20 If you list the program again you will see that line 20 has been effectively deleted 1 PRINT HOW NOW Ok I Retype line 20 to restore your program to its previous form 10 PRINT HOW NOW 20 PR I NT BROWN j COW 11 ...

Page 18: ...o use line numbers that are multiples of 10 or at least 5 Here s your program again 10 PRINT HOW j NOW j 20 PRINT BROWN II j COW Suppose you want to insert a line between 10 and 20 Simply type 15 PRINT SPLENDID When you list the program now it will show PRINT HOW NOW PRINT SPL ENDID i PRINT BROWN I COW Even though line 15 was typed after lines 10 and 20 it takes its correct place in the program be...

Page 19: ...es in memory 10 PRINT HOW NOW is PRINT SPLENDID 20 PRINT BROWN COW Now without deleting this program enter the following new program 10 PRINT MY COMPUTER IS A 20 PRINT TOOL If you list the program you will find it is LIST 10 PRINT MY COMPUTER IS A 15 PRINT SPLENDID 20 PRINT TOOL K Note that line 15 still exists because that line number was not used in the new program So remember before typing a ne...

Page 20: ......

Page 21: ... a program in RAM in effect you create a program file The following program serves to demonstrate how any program can be saved in RAM 10 PRINT THIS IS A TEST 20 PRINT OF THE MODEL 100 COMPUTER Access BASIC Clear working memory with the NEW command and then type the program as it appears above Execute the program The following will be displayed THIS 1 1 A TEf3 T OF THE MODEL 100 COMPUTER Uk II The ...

Page 22: ...ot been wiped out It has been erased from working memory but it now exists in RAM To confirm that this is true enter the command FILES ENTER or press the FILES Function Key In response to this command the names of all the file stored in RAM including all BASIC programs will be displayed In this case if you haven t SAVEd any other programs or files the name PROG1 BA will be displayed This is your p...

Page 23: ...ntifying it in the Main Menu and pressing ENTERJ However if you wish to modify or alter the program in any way it is very convenient to LOAD it into the BASIC system Let s use PROG1 which you SAVEd in the last experiment and LOAD it into the BASIC system You can do that with the command LOAD PROG1 Another way to LOAD the program is to press the LOAD Function Key CE2l After pressing the message Loa...

Page 24: ...IS IS A TEST OF THE MODEL 100 COMPUTER Ok 11 This illustrates a useful option of the RUN command If the RUN command is followed by the name of a program stored in RAM the name must be enclosed in quotes then the program will be loaded into working memory and executed immediately Thus the command RUN PROG1 00 lID is equivalent to the two commands LOAD PROG1 mEID RUN CEHnID Use the LIST command to v...

Page 25: ...LIST command You should see PRINT THIS IS A TEST PRINT OF THE MODEL 1 0 COMPUTER PRINT AND ITS ABILITY TO STORE FILES The new line was effectively incorporated in PROGI which is stored in RAM You can also LOAD and execute a BASIC program directly from the Main Menu Press fI to exit BASIC and return to the Main Menu You should see something similar to 21350 Bytes tree Jun 22 1983 Wed 10 37 07 TEXT ...

Page 26: ...ram name you wish to assign to it For example if you wish to change the filename PROG1 to TEST typc NAME PROG 1 BA AS TEST 1 BA ENTER Verify the name change with the FILES command or by pressing CEf Now using the NAME AS command change the file name back to PROGl NAME TEST1 BA AS PROG1 BA Again you may confirm that the name was changed to PROGI with the FILES command Experiment 4 Saving a Program ...

Page 27: ...st the leader If you use Radio Shack Leaderless cassettes catalog number 26 3019 this isn t necessary Press the RECORD red key and PLAY keys down together They should stay down but the tape will not move If it does you do not have the remote jack inserted Insert the jack Now you are ready to save the program onto the tape Enter the following command CSAVE PROG1 The recorder will run briefly and th...

Page 28: ...t the tape will not advance Enter the following command CLOAO PROG1 As soon as you press ENTER the tape will start turning and the program will be read into the Computer If this is accomplished successfully the computer will display FOUI ID Pf OG1 Ok If the tape was not read successfully an 110 InpuUOutput error message will be displayed If this happens rewind the tape and adjust the volume contro...

Page 29: ...ommand is entered the cassette recorder will run briefly and then stop Also the computer will display FOUND PROGl Ok II indicating that the program was read successfully List the program in memory with the LIST command You will see that the same program was loaded from the tape This illustrates another option of the CLOAD command When the filename of the program is omitted the first program encoun...

Page 30: ...ored on tape was not SAVEd into working memory but was compared character by character with the program already in working memory If an inconsistency is found at any point an error message will be displayed indicating that the prugram saved on the cassette tape was not the same as the one in working memory If an error has occured you can reSAVE the program and use the CLOAD command again to check ...

Page 31: ...he message Verify failed will be displayed indicating that the two programs are not the same Don t forget the question mark after CLOAD since otherwise the program saved on tape will be loaded into working memory replacing the resident program there If the CLOAD command indicates a bad program on tape then the CSAVE command can be used again to resave it Experiment 7 Merging two Programs Rewind th...

Page 32: ...sion DO for DOcument will be attached to any BASIC program saved with the ASCII option There are several reasons why you might want to save a file in the ASCII format As it will be illustrated later in this experiment merging files is one of the main ones Delete the program from working memory with the NEW command and type the following one line program S PR I NT HELLO MODEL 100 USER ENTER Merge P...

Page 33: ...PROG2 CENTER List the program It will be 1 5 PRINT HELLO MODEL 100 USER P RI f IT Ti n 3 n A lEST PRINT OF THE MODEL 100 COMPUTER PRINT 1 10 ITS A BH ITY TO STORE FILES Line 10 of the program PROG2 saved in RAM replaced line 10 of the program resident in working memory This will always happen If two programs to be MERGEd have any line numbers in common the lines of the program SAVEd in RAM will re...

Page 34: ...e a file from the RAM storage area with the KILL command The general form of the KILL command is KILL filename extension where filename is the name of the program you wish to delete and extension specifies the characters BA in the case of a BASIC program DO in the case of a program SAVEd with the A option or a text document and CO in the case of a machine language program Use the KILL command to d...

Page 35: ...ou have learned You have learned how to SAVE BASIC programs in RAM and on cassette tape You learned how to LOAD a program from RAM or from tape and how to verify that a program has been saved correctly You also learned how to MERGE a SAVEd program with a program in working memory You found out that in MERGE operations if line numbers in RAM are in common with line numbers in working memory the lin...

Page 36: ......

Page 37: ...borrowed at the simple interest rate r then the amount S that must be repaid after t years is given by the fonnula S P l rt S is called the sum and P is the principal The first program in this lesson calculates S for the following values of P rand t P 10 000 r 18 per year t 10 years CarefUlly enter the following program into the Computer 10 P 1111000 2 III R 18 3 III T 10 L10 5 P 1 R T 50 PRINT TH...

Page 38: ... assigns it to the variable S Note that the expression P 1 R T looks very much like the formula previously seen for calculating the sum The symbol is used to denote multiplication and as usual denotes addition Line 58 prints an explanatory message and the value of S The variables P R T and S are all valid examples of numeric variables A numeric variable can be a any letter b any two letters or c a...

Page 39: ... J9 together before multiplying their sum times F you would have to place parentheses around H8 J9 F H8 J9 In this case the addition is performed first because the operation inside the parentheses is carried out before the outside multiplication Multiplication and division have equal priority and will be performed from left to right The same is true of addition and subtraction If you look at line ...

Page 40: ...lay numbers in dollars and cents format The expression in line 50 P l R K T K uses addition multiplication and exponentiation operators The exponentiation operator has the highest priority and will be performed before multiplication or division and of course before addition and subtraction Because of this priority it was necessary to place parentheses around the exponent T K Otherwise the computer...

Page 41: ...the value for P When a value for P is entered for example 5000 the program will execute as before and print out the total Be sure to press CENTER after typing the amount for P Here is what the output looks like ENTER THE PRINCIPAL 5000 TOTAL 18 8030 5561733465 Line 10 prints the prompt message The semicolon at the end of the line suppresses the carriage return so that the next character printed wi...

Page 42: ...enter the value for P The ending quotation mark must be followed by a semicolon a comma cannot be used List the program It should read 10 INPUT PRINCIPAL P 20 R 12 30 T 5 40 K 4 50 S P 1 R K T K 60 PRINT TOTAL IS S Execute the program The following output occurs when you type 1000 for the principal PRINCIPAL7 1000 TOTAL IS 1806 1112346693 Ok II Run the program several times entering different valu...

Page 43: ...t When the INPUT statement is executed you must type a value for each variable separating the values with commas After the last value has been typed you should press ENTER Two separate INPUT statements could have been used the first for the principal P and the second for the rate R as follows 113 INPUT PRINCIPAL P 213 INPUT RATE R However it is more convenient to use just a single statement as was...

Page 44: ... ask for values for the variables until you terminate the program manually by pressing BREAK Line 18 prints a prompt and allows you to enter values for the principal P and the rate R Line 38 prints a prompt and allows you to enter values for the time T and the number of periods K Lines 10 and 30 could have been combined into one line if desired Line 68 prints out the message TOTAL IS and the value...

Page 45: ...INT TOTAL FOR 65 PRINT N IS S 7121 PRINT 80 GoTo 1121 When you execute the program you will be prompted as before for the principal rate time and number of periods In addition you will be prompted for a name After this data is entered the name and the amount of the investment will be printed Run the program and enter the data as indicated below of course you may enter any other name you wish PRINC...

Page 46: ...les N A3 DA AD ST In line 40 it is essential that the variable be a string variable If you tried to use a numeric variable the computer would continue to ask for data until a numeric constant was entered The assignment of the name to the string variable N was made with the INPUT statement It is possible to use assignment statements with string variables and constants just as with numeric variables...

Page 47: ...rogram you will be prompted for the interest rate the amount of the loan and the length in years of the loan If the interest rate is 12 then 12 should be entered not 12 Here is an example of the execution of the program INTEREST RATE 0 100 12 AMOUNT OF LOAN 30000 NUMBER OF YEARS 25 MONTHLY PAYMENT IS 315 967242659281 Line 10 allows the interest rate to be entered and stores it in variable R Line 2...

Page 48: ...d vary the interest rate while keeping the other variables constant Experiment 9 Calculation of Total Amount and Loan Balance In addition to calculating the monthly mortgage payment as in the last experiment you might wish to compute the total amount you have to pay This is done by multiplying the number of pay periods N by the monthly payment MP Type in lines 100 and 110 as follows 100 TA N MP 11...

Page 49: ... the loan would be 71 200 The discouraging result of running this example is that the total you will have to pay over the 30 years is 273 559 51 By entering a current year of 10 you can see that the principal remaining unpaid after 10 years is still 66 883 23 This means that in 10 years you have paid 71 200 66 883 23 4 316 77 toward the original amount borrowed What you have learned In this lesson...

Page 50: ......

Page 51: ...M ST 15 3121 IF ST 2121121121 THEN CM CM 20 ST 2121121121 4121 PRINT COMMISSION IS CM Execute this program The program begins by asking you to enter the amount of sales Type 1121121121 to compute the commission on one thousand dollars sales Note that a dollar sign is not entered The computer will respond with the message COMMISSION IS 15121 indicating a commission of 150 Since the sales were less ...

Page 52: ...e and printed Line ut allows you to enter the total sales which is stored in the variable ST Line 28 computes the flat rate sales commission and stores it in the variable eM Line 38 contains a new statement the IFITHEN statement As can be seen from the flow chart in figure 4 1 the program must branchafter line 20 If the sales exceed 2000 an additional computation must be performed However if this ...

Page 53: ...al flat rate commission The general format of the IF THEN statement is IF condition THEN statement where statement is executed only when condition is true In either case the next line executed is the one following the IFITHEN statement The condition is usually the comparison of two numeric or string expressions Two numeric expressions are compared with the use of a relational operator In this case...

Page 54: ...h time One way of accomplishing this is to use a different print statement Instead of using PRINT the PRINTUSING statement can be used to format the output Make the following changes to the program Change line 40 as follows 40 PRINT COMMISSION IS and add a new line 50 50 PRINTUSING CM Line 40 will display the message COMMISSION IS and line 50 will print the value of the commission Now if you execu...

Page 55: ...with line 50 above The following table gives the output for various format specifiers format specifler A A A A output 1416 38 1416 4 1416 381 1416 38120 Experiment 3 Dollar Signs There are other possibilities for format specifiers Change line 45 in the program so that it is as A Now run the program and input a variety of values for the sales In each case there will be a dollar sign printed to the ...

Page 56: ...ve specified for example printing 34 56 with the number will be printed anyway but the symbol will be printed to the left of the number to indicate the field overflow Experiment 5 Sales Commission Revisited Change the sales commission program so that it is computed according to the following scheme if sales are 2000 or under commission is 15 of sales if sales are over 2000 commission is 20 of sale...

Page 57: ...deleting line 20 and replacing line 30 3121 IF ST 2121121121 THEN CM 15 ST ELSE CM 2121 ST Since this line requires more than 40 columns it will not fit on a single line of the display of your Model 100 but will overflow to the next line A line in your program may contain up to 255 characters in which case it will extend over several lines of the display 51 ...

Page 58: ...atement following ELSE is executed instead so that the commission is calculated as 20 of sales and again control passes to line 40 The general format of the IF THEN ELSE statement is IF condition THEN statement ELSE statement 2 statement is executedjf condition is true but statement 2 is executed if condition is false In either case control passes to the next line in the program The statements exe...

Page 59: ...ute the commission of a single salesman and execution would terminate If the program is to compute more than one sales commission it must branch back to line 10 This can be accomplished with the use of a GOTO statement after line 50 Type in a new line G0 GOTO 10 Now the program is complete 10 INPUT NAME SALES i NS ST 20 IF ST 2000 THEN CM 15 ST ELSE CM 20 ST 40 PRINT COMMISSION FOR iNS IS 45 A 50 ...

Page 60: ... any commission The dummy name was necessary because the INPUT statement in Line 10 requires you to enter two input quantities Since a negative sales amount terminates execution the name you enter will not be used You can have more than one STOP statement in your program Of course your program need not have any STOP statements in it at all Experiment 8 Individual Commissions for the Salesmen The S...

Page 61: ...it in the string variable NI It reads the first commission rate 15 and places it in the variable CR Line 24 compares the name in N which was entered in line 10 to that in NI If they are different the program jumps back to line 20 which then reads the next name and commission rate in the DATA statement The program continues looping in this way until a match is found When this happens CR will contai...

Page 62: ... be added to line 70 or placed in another DATA statement The computer treats multiple DATA statements as one continuous list What you have learned In this lesson you have learned how a program can be made to BRANCH and accomplish different tasks depending upon the value of a variable or expression This can be done by using the IFffHEN statement The PRINTUSING statement was used to format the outpu...

Page 63: ...using the DAY function Once initialized the day will be automatically updated If you have not already initialized the day this can be done by entering the following command DAY xxx where xxx are the first three letters of the current day For example if today is Monday enter DAY II M ON CEBIEID While the DAY function returns the first three letters of the day of the week it is often desirable to pr...

Page 64: ...acters stored in 0 DAY contains the first three characters of the current day SUN MON etc LEFT D 3 returns the three leftmost letters of the string stored in 0 If a match occurs the program jumps to line 40 otherwise line 30 is executed next Note that the IF statement does not contain the keyword THEN The keyword is optional in an IF statement when it is followed by a GOTO statement Line 38 The GO...

Page 65: ...hen Command PRINT LEFT D 1 PRINT LEFT D 2 PRINT LEFT D 5 etc T Th Thurs LEFT is a string function of two arguments the string D and the number of characters to be returned The first argument need not be a string variable it can also be a string constant For example PRINT LEFTS Model 100 3 would display as Mod When a string constant is used as the argument it must be enclosed in quotation marks The...

Page 66: ...e line and an equal number of asterisks are printed on both sides to fill the line If the current day is Tuesday which has 7 characters then 16 asterisks are printed on both sides so that 39 columns are used The function LEN returns the number of characters in a string variable or string constant For example if 0 contains Friday then the function LEN O returns the value 6 and LEN Friday also retur...

Page 67: ...TRING r x which constructs a string consisting of r repetitions of the character x The argument r can be a numeric constant variable or expression For example if J 3 and M 2 Command PRINT STRING 5 PRINT STRING J X PRINT STRING J M Displays as XXX Line 46 illustrates the concatenation operator The strings A D and A are joined together to form a new string which is then assigned to the variable 0 Th...

Page 68: ...the seconds The hour is in 24 hour format so that 3 PM is hour 15 For example if the current time is 3 05 PM type TIME 15 05 00 ENTER The following program will convert the string returned by TIME for example 14 18 00 to the customary format 2 18 PM Clear the previous program from memory with the NEW command and then type the following program 10 HH LEFT TIME 2 20 HH VAL HH 30 IF HH 12 THEN A PM E...

Page 69: ...k to the string variable HH This will be concatenated later with another string In order to do this a string variable must be used Line 68 This line uses the MID function to read the two minutes digits from TIME and stores this two character string in the string variable MM Note that the minutes are the 4th and 5th characters in the string 13 05 00 MID TIME 4 2 returns two characters starting with...

Page 70: ...they are returned by TIME The program will be changed so that the output will appear as THE TIME IS 1 05 PM AND 28 SECONDS Make the following changes to the program Type a new line 65 55 RIGHT TIME Z and change line 70 to 70 TS HHS MMS AS AND SSS SECONDS List the program to confirm that it is 10 HHS LEFTS TIMES 2 20 HH VAL HHS 30 IF HH 12 THEN AS PM ELSE AS AM 40 IF HH 12 THEN HH HH 12 50 HHS STRS...

Page 71: ... so by entering the following command DATE mm dd yy where mm is the number of the current month e g 03 for March dd is the day and yy the year For example if today is December 25 1983 enter DATE 12 25 83 Delete the previous program from memory with the NEW command The following program will print the date in the usual form i e the name of the month the day and the year For example DECEMBER 25t 198...

Page 72: ...m What s the date Works 10 SETMM TO MONTH 20 CONVERT MM TO NUMERIC MM 30 READ MONTH FROM DATA LIST 40 INCREMENT COUNTER 60 NO SETDD TO DAY 70 SETYV TO YEAR 80 0 Figure 5 2 Flowchart of Program What s the date 66 ...

Page 73: ...ead from the data list Eventually CT will equal MM When this happens MM will have the current month assigned to it and line 60 will be executed next Thus the months are read repeatedly into MM until the present month is reached and then the program jumps out of the loop lines 30 40 and 50 Line 68 The MID function is used to extract the day from DATE The day is given by the 4th and 5th characters o...

Page 74: ......

Page 75: ...d line must be deleted and the line retyped with a new line number An easier and more efficient way to make changes of this type is to use the built in Editor The Editor allows changes to be made to a line without retyping the entire line It also allows a line number to be changed without retyping the line There are other convenient features of the Editor as well These features will be examined in...

Page 76: ...g displayed 10 INPUT NAME NS 2 J I EAD 1 S j G 30 IF A N THEN GOTO 20 40 PRINT AGE IS A S0 DATA DAN 32 RON 38 LINDA 424 60 DATA BETTY 35 RALPH 29 SKIP 3 The Computer enters the editor mode and the program is displayed The cursor is on the first character of the program The symbol at the end of each line is used to display the carriage return character that is generated when ENTER is pressed The di...

Page 77: ...y by pressing CID Do NOT press ENTER after CID is pressed You will notice that the letter G is displayed in the correct place and the carriage return character moves one column to the right At this point the display should appear as INPUT NAME Ns4 j E tlD 1 1 6 IF A NS THEN GOTO 20 PF INT l iE I It G DATA DAN 32 RON 38 LINDA 42 DATA BETTY 35 RALPH 29 SKIP When the Editor is used the system is alwa...

Page 78: ...ct variable AG Execute the program Here is an example of the output NAME LINDA AGE IS 42 Ok II Run the program several times entering different names to verify that it is executing correctly Experiment 2 Inserting a Word Lines 10 and 40 of the previous program will be changed to 10 INPUT YOUR NAME NS l10 PRINT YOUR AGE IS AG The word YOUR must be inserted in both lines as shown above This will be ...

Page 79: ...line 40 This can be done using the Cursor Movement keys Be careful not to press any other keys while you are moving the cursor When you have the cursor positioned correctly line 40 should appear as 0 F R II IT IS AG The cursor is positioned correctly for the insertion so type the word YOUR followed by a space Line 40 should now appear as l10 PRINT YOUR AGE IS AG At this point editing is finished s...

Page 80: ... G Type the command ED I T ENTER to invoke the Editor The following should be displayed 10 INPUT NAME N 30 IF AS N THEN GOTO 20 40 PRINT YOUR AGE IS AG 50 DATA DAN 32 RON 38 LINDA 42 60 DATA BETTY 35 RALPH 29 SKIP The A in the variable AG in line 20 will be deleted first Position the cursor with the arrow keys so that it is over the letter G Line 20 should appear as Note that the cursor is positio...

Page 81: ...e character to be deleted Another very similar way to delete characters consists of entering the Editor positioning the cursor right over the character you wish to delete and then pressing DEL CSHIFT BKSP As with BKSP characters to the right of the deletion will shift to the left to fill the vacant space Experiment 4 Changing a Character Here is the previous program again as it currently exists in...

Page 82: ... should now appear as 10 PRINT YOUR AGE 15 G This is the desired form of line 40 You must remember that when COKSP is used the character deleted will be the one just to the left of the cursor If the deletion is done ftrst then the cursor will be positioned correctly for the insertion of the new character The operation can be carried out in the reverse order but after the insertion the cursor must ...

Page 83: ...Line 60 should appear as 60 DATA BETTY 35 MORT 29 SKIP Line 60 is in its desired form RALPH has been replaced by the name MORT Exit from the Editor List the program to confirm that it is 10 INPUT YOUR NAME N 20 READ A G 30 IF A N THEN GoTo 20 a0 PRINT YOUR AGE IS G 50 DATA DAN 32 RON 38 LINDA az 60 DATA BETTY 35 MORT 28 SKIP 3 Execute the program Here is an example of the output N ME 1 10RT YOUR A...

Page 84: ...le CT is a counter that records the number of values entered If the number entered is then the average is printed in line 6 Here is an example of the execution of the program NUMr ER i NUMBt rp 2 NUMBE F el AVE H 7iGE IS 2 Ok Obviously the program is not working correctly The average of the two numbers is 3 not 2 The reason for the inaccuracy is that the number 0 was counted by the variable CT The...

Page 85: ...the 0 in line 20 When this is done line 20 should appear as CT CT The cursor is positioned correctly to change the 2 to a 4 Delete the 2 by pressing Then insert the 4 by pressing CIJ on the keyboard Now the program should appear as 10 INPUT NUMBER 1 1 121 CT 1 l Z o Nt 40 IF N 2 THEN GOTO 60 5 ClOTO I 60 PRINT AVERAGE IS AV CT Next move the cursor down two lines so that it is over the zero of line...

Page 86: ...EN GoTo 60 30 AV AV N 40 CT CT 1 50 GO TO 10 60 PRINT AVERAGE IB AV CT The program is listed in the correct order because BASIC always lists the lines in your program according to their line numbers Here is an example of the execution of the program l IUMBER7 L JlJM E R NUI IBER7 0 AVEH IS 2 Ok The program seems to be working correctly Execute the program several times to verify that it will work ...

Page 87: ... THEN GOTO 60 ELSE CT CT 1 30 AV AV N 50 GOTO 10 60 PRINT AVERAGE IS AV CT Enter the EDIT command The program will be displayed as 10 INPUT NUMBER N 20 IF N 0 THEN GOTO 604 31 t V l lV l i 0 CT CT 1 4 i 21 GOfO l 6 PRIN r IIAVERA 3E IS 1i AV First the word ELSE will be added to line 20 Position the cursor in line 20 over the carriage return character Line 20 should appear as 20 IF N 2 THEN GOTO 6 ...

Page 88: ...d to a temporary storage area in the computer called the PASTE buffer The operation of deleting characters as done above is called a cut The remaining characters in line 40 namely the number 40 and the carriage return will now be deleted Position the cursor so that it is to the right of the carriage return character 1121 Press BKSPl three times This deletes what was left of line 40 Since BKSPl was...

Page 89: ...to confirm that it is correct 10 INPUT NUMBER N 20 IF N 0 THEN GOTO 60 ELSE CT CT 1 30 Alj AlJ N 50 GDTD 10 60 PRINT AljERAGE IS AlJ CT Execute the program to confirm that it works as it did before Experiment 8 Copying a Phrase without deleting it The previous program will be modified so that the sum of the numbers entered will be printed before the average value is printed The revised program wil...

Page 90: ...rsor down one line so that it is on the end of file marker Line 60 will now appear as Note that the entire line is in reverse video indicating that it is ready to be transfered to the PASTE buffer This line should not be deleted when it is transfered to the buffer so press the COpy Function Key Remember that transfers and deletes Now line 60 appears as 60 PfHNT II WERAGE ISII A lICT The cursor is ...

Page 91: ...end of the line so that it is over the carriage return character0 6 r1 FjR I I oor CUlv I Co A J i OOf l J i J 11 _ 0 Press three times to erase the characters Line 60 will be in the desired form 60 PRINT 8UM IS Av4 Exit from the Editor List the program to confirm that it is 1121 INPUT NUMBER N 2121 IF N 12I THEN GOTO SI2I ELSE CT CT 1 1112l AV AV N 5121 GOTO 1121 SI2I PRINT SUM IS AV 7121 PRINT A...

Page 92: ... program You should practice using the Editor to modify your programs Yau will find that it is a very convenient and quick way of making changes What you have learned You have learned how to use the Editor to modify your BASTC programs In most cases it is easier and quicker to make changes with the Editor than to make them by retyping entire lines 86 ...

Page 93: ...0 INPUT NUMBER OF PERIODS N 30 FOR X 1 TO N 110 PRINT SALES FOR PERIOO X 50 INPUT Y 60 SX SX X XX XX X X 70 SY SY Y XY XY X Y 80 NEXT X 80 B N XY SX SY N XX SX SX 100 A SY B SX N 110 PRINT FORECAST FOR PERIOD X IS 120 PRINT A II B X Execute this program The program begins by asking you to enter the number of periods of historical sales data Type 6 and press ENTER The program then prompts you for t...

Page 94: ... should not be inserted within the quotes of the prompt message When mEID is pressed the number which has been typed will be assigned to the numeric variable N Line 38 The FOR statement defines the beginning of a loop which is to be repeated with successive values for the index variable X You can think of this statement as saying Perform the following statements with X equal to I Then repeat the s...

Page 95: ... Keyboard NUMBER OF PERIODS Figure 7 1 Sales Trend Program Flowchart 89 ...

Page 96: ...tely after the word PERIOD The second semicolon tells the Computer not to move the cursor after printing the period number This means that the question mark automatically printed by the following INPUT statement will appear immediately after the period number The INPUT statement waits until a number is entered from the keyboard and stores this number in the variable Y The variable Y acts as a temp...

Page 97: ... Sales Trend Line Calculations Line 80 The NEXT X statement determines the end of the loop of statements which are to be repeated with successive values for the index variable X So long as the value of X is less than the upper limit specified in the matching FOR X statement the loop will start over again with the next value for X When X reaches its upper limit N in this case execution transfers to...

Page 98: ...e FOR NEXT statement pair introduced in this lesson is very useful when you need to repeat the same set of procedures a predetermined number of times Since this situation comes up regularly in computer programming you will no doubt want to use the FOR NEXT pair quite often in your own programs The following experiments will give you a few more ideas for its application and show you that the FOR st...

Page 99: ...les for a specified quarter in the future For example to predict the first quarter of year seven period 25 enter PRINT 148 225 8 4087 25 The numbers are rounded off to three or four decimal places The result 358 4425 which is displayed represents the trend line projection of sales to the next period in the future A new type of variable the subscripted variable has been introduced in this experimen...

Page 100: ...ge Ratio to Trend 200 300 400 Frequently sales data exhibit seasonal characteristics For example the first quarter might traditionally be slow compared to the rest of the year If this is the case it might be useful to modify the trend line forecast by the amount that the quarter is typically above or below the trend The amount above or below the trend is called the ratio to trend and is determined...

Page 101: ...st for the season The program can be easily modified to compute the average ratio to trend for the first period Enter the following changes 140 FOR X 1 TO N STEP 4 150 R Y X I A 6 X R 160 NEXT X 170 PRINT QUARTER 1 RATIO IS R 6 If you LIST the complete Sales Trend program you should now have 10 CLS 20 N 24 25 DIM Y 24 30 FOR X 1 TO N 50 READ Y X 60 SX SX X XX XX X X 70 SY SY Y X XY XY X Y X 80 NEX...

Page 102: ...t change to the FOR statement in line 140 140 FOR X 1 TO N STEP 4 This change in the FOR statement tells the computer to increment the index variable X in steps of 4 starting with the value 1 until X reaches the upper limit N Thus X will assume the values 1 5 9 13 17 and 21 which corresponds to the first quarter period number in years 1 2 3 4 5 and 6 respectively Line 159 computes the ratio to tre...

Page 103: ...UARTER 4 RATIO Ok X IS 8 4086956521739 IS 9230187061999 IS 1 0761822655641 IS 86424468709917 IS 1 1358281261464 Lines 138 and 198 define a program loop which repeats for each of the four quarters Notice that this loop contains within it another loop from line 140 to line 160 This is an example of a programming concept known as nested loops It simply means that there is a loop of statements within ...

Page 104: ...ASCII file Therefore enter the command SAVE SALES A Go to the Menu by pressing tIIl and confirm that file SALES DO is listed This file will be used in the next Lesson What you have learned You should now be able to use the FOR NEXT statements in your own programs to repeat a group of statements Using the STEP option with the FOR statement will allow you to control the increment for the index varia...

Page 105: ...0 63 ENTER PSET 239 0 PSET 239 63 EJrnID The cells are quite small so you will have to look carefully to see the illuminated dots You have probably figured out that the first number in the parentheses determines the horizontal X axis position on the display and the second number determines the vertical Y axis position Since the corners are the extreme points of the LCD display the range of X value...

Page 106: ... erase a line simply add a zero after the second coordinate L1NE 0 63 239 O O ENTER A simple extension of the LINE instruction makes it easy to draw a box CLS CEtffiID LINE 30 8 210 56 1 B ENTER Graphic data such as lines and boxes can appear on the LCD display at the same time as text The number I after the second set of coordinates says to draw the line with dark cells The letter B at the end of...

Page 107: ...43 78 79 Line 3 80 81 82 83 118 119 Line 8 280 281 282 283 318 319 Table 8 1 of PRINT positions Clear the display and print the name RADIO SHACK in the center of the display by entering CLS ENTER PRINT 135 RADIO SHACK ENTER You should see Ok PRINT 135 IIRADIO SHACK II RADIO SHACK Ok Note that the name RADIO SHACK begins printing in the 15th column of line 4 The PRINT position would be computed as ...

Page 108: ...ll show you how to draw standard X Y type axes which will allow sales data to be plotted in graph form Enter the following program 50 CLS 100 LINE 238t54 33t54 150 LINE 33t0 Execute this program You should see a pair of axes displayed Line 58 This statement clears the display Line lee The horizontal axis is drawn from right to left Line 158 The vertical axis is drawn from bottom to top Note that t...

Page 109: ... 50 10 O 150 200 300 500 600 CLS LINE 238 54 LINE 33 O FOR X 33 TO PSET X 53 FOR Y 51 TO PSET 34 Y 238 STEP 24 NEXT X o STEP 8 NEXT Y Execute this program to confirm that it now displays Lines 28t 388 This FOR NEXT loop displays the tick marks on the horizontal axis The first tick mark is displayed at coordinate 33 53 the second at 57 53 and so On The last tick mark will be at 225 53 Lines S8t 689...

Page 110: ...INT Z84 X X NEXT X 720 FOR Y l TO 7 730 PRINT 280 Y 40 100 Y 50 740 NEXT Y 2000 GOTO 2000 Execute the program to confirm that it displays 450 400 350 300 250 200 150 o 4 8 12 16 20 24 28 Note You will have to press to terminate this program Lines 58 688 The first part of the program remains unchanged and generates the axes and the tick marks Lines 788 718 This FOR NEXT loop prints the labels along...

Page 111: ...ata you saved in Lesson 7 will be plotted on the graph created in the previous experiment Enter the following new statements to your program 750 FOR X 1 TO 24 READ Y 760 PSET 33 X 6 54 Y 136 6425 770 NEXT X If you saved the Data statements under the file name SALES 00 as requested in Lesson 7 merge it with your program with the command MERGE SALES DO If you did not save file SALES DO simply type t...

Page 112: ...els the axes Line 758 This begins a FOR NEXT loop which reads the sales data from the Data statements There are six years of four quarters so the total number of points will be 24 Line 769 The PSET statement is used to tum on cells corresponding to each sales point The axes of the graph where X 0 and Y 136 is at graphic cell 33 54 Horizontally the quarters are spaced six cells apart The X coordina...

Page 113: ...o 50 The first quarter sales point is therefore graphic cell 39 50 Line 779 This NEXT statement terminates the FOR loop begun in Line 750 Lines 988 958 These Data statements contain the six years of sales values in chronological order Line 2888 This endless loop prevents termination of execution so that the cursor does not interfere with the graph Experiment 7 Connect the Points The readability of...

Page 114: ...l have to press to terminate execution of this program Line 745 The PSET statement turns on the graphic cell for the first quarter sales point Line 768 The LINE statement draws a line from the last cell referenced to the next sales point Recall that the first coordinate in the LINE statement is optional and if omitted draws a line from the last referenced cell In this case the second coordinate of...

Page 115: ...6 6 25 201 14 Add a new line to your program 800 LINE 33 52 201 14 and execute it to see the new display 450 400 350 300 250 200 150 o 4 8 24 28 You will have to press BREAK to terminate execution of this program One of the benefits of graphing the trend line is that it illustrates how next years sales might he forecast What you have learned In this lesson you have learned how to plot graphic data...

Page 116: ......

Page 117: ...e square root of 2 by entering PRINT SQR 2 and observe the correct result 1 414213562373 Finally try to print the square root of the negative number 4 by entering PRINT SQR 4 and obtain the error message FC Error The error message indicates a Function Call error which occured because the Computer cannot find the square root of negative numbers The square root function SQR x returns a numerical val...

Page 118: ...install a TV mast on your roof and would like to precut the guy wires to the top of the pole so that you can attach them easily when the pole is stood up vertically This is illustrated in the drawing below H Vertical Height L length of each guy wire 0 distance from mast to guy anchor Enter the following program 10 INPUT HEIGHTt DISTANCE HtD 20 L SQR H H D D 30 PRINT GUY WIRE LENGTH IS L 112 ...

Page 119: ... a right triangle using the Pythagorean Theorem Experiment 3 Calculate the height of a tree A problem similar to the guy wire length calculation is the determination of the height of a structure such as a tree The problem is illustrated below 0 distance to base illustration 3 A angle in degrees Using Trigonometry the height may be found if the distance to the base and the angle to the top are know...

Page 120: ... of the constant PI is required to convert the angle in degrees to radians While the constant could have been written out in decimal form this assignment statement eliminates the need to look it up in a table or to try to remember it It also serves to illustrate another function which is available in BASIC the arctangent ATN You might like to confirm that this expression calculates the constant co...

Page 121: ...ry regardless of the value of the argument To verify this type PRINT FRE 10 and you should see the same value displayed as before To determine the amount of memory used by a BASIC program type PRINT FRE 0 before you begin typing your program Then after having typed it type PRINT FRE 0 ENTER again This will print the amount of memory left or unused by your program Finally subtract the amount you ob...

Page 122: ...se including the quotation marks using the conventional PRINT statement PRINT GO WEST YOUNG MAN OOEID The unusual result o is due to the fact that the first pair of quotation marks define a string consisting of a single space The phrase GO WEST YOUNG MAN is interpreted as a numeric variable initialized to zero The second pair of quotation marks also print a single space after the zero This example...

Page 123: ...se arguments is illustrated in the table below Argument Character Value Returned 65 A 78 N 66 B 79 0 67 C 80 P 68 0 81 Q 69 E 82 R 70 F 83 S 71 G 84 T 72 H 85 U 73 I 86 V 74 J 87 W 75 K 88 X 76 L 89 Y 77 M 90 Z The number assigned to each letter in the table above is called its ASCII value The range of possible ASCII values is 0 to 255 and includes all characters which your computer can store in i...

Page 124: ...ch as line feed carriage return sound clear the screen and so on For a complete list of ASCII values refer to the Appendix in your Model 100 Owner s Manual Delete the current program from memory with the NEW command and type the following program 10 INPUT ASCI I VALUE A 20 PRINT CHR A 30 GOTO 10 Execute the program and enter an ASCII value of 7 when prompted to do so You should hear a beep This is...

Page 125: ... The PRINT statement displays an asterisk in position 100 which is approximately in the center of the display Line 288 The statement A INKEY causes the Computer to look at the keyboard to see if any key is being depressed If a key is being depressed when the statement is executed the INKEY function will return a one character string for that key For example if is being depressed when Line 200 is e...

Page 126: ...ve past the upper left corner the program will terminate execution with an error message FC Error in 300 This Function Call error occurs because the PRINT position goes negative if rn is pressed with the asterisk in the upper left corner PRINT position 0 The program can be modified to prevent this error from occurring At the same time it is relatively easy to allow the asterisk to be moved vertica...

Page 127: ...s either true or false For example the expression AT 0 is True if AT is greater than or equal to zero It will be False if AT is less than zero Similarly the combined expression AT 0 AND AT 318 will be True if AT is greater than or equal to zero and also less than or equal to 318 In general if Ll and L2 are two logical expressions then the logical expression L1 AND L2 is True if both Ll and L2 are ...

Page 128: ...ay Execution is then transferred back to line 200 to continue looking at the keyboard What you have learned In this lesson you have learned that BASIC has many useful built in functions in addition to the mathematical operations These include the square root tangent and arctangent BASIC also has general purpose functions such as FRE CHR and INKEY These can be used in many other types of applicatio...

Page 129: ...able RAM space When storing a large data file it is more practical to use cassette tape For example a mailing list of 1000 names and addresses would require around 80K bytes of memory This exceeds the maximum memory capacity of your Computer so a RAM data file is out of the question However a list of this size could fit easily on a cassette file Experiment 1 Writing a data file to RAM The program ...

Page 130: ...ent prompts you to enter a name from the keyboard It is stored in the string variable N Line 139 The IF statement checks for a null entry to determine the end of the list Line 148 If a file number is added to the PRINT statement as in PRINT 1 N the items in the print list will be output to the file corresponding to the file number The file number must have been previously defined in an OPEN statem...

Page 131: ...the next name in the data file and assigns it to the variable N Note that file number 1 refers to the RAM file NAMES DO as defined in the preceding OPEN statement The PRINT statement displays the name read from the data file Line 528 The IF statement tests for the end of the data file If it is not the end of file number 1 execution jumps back to line 510 to read another name If the end of file num...

Page 132: ... NAMES FOR OUTPUT AS 1 List the program to confirm that it is 100 CLS 110 OPEN CAS NAMES FOR OUTPUT AS 1 120 INPUT NAME N 130 IF N GOTo 200 1 10 PRINT 1 t N 150 N GO TO 120 This is the same program used in Experiment 1 to write a RAM file except that the device in the OPEN statement in LINE 110 has been changed to CAS Press the RECORD and PLAY keys on the cassette recorder together Execute the pro...

Page 133: ...layed Joan Smith Patty olf Allison T Cornpone Jill Shoe SallY Ma tnet Roxanne o ShacK OK I The only change required to change from a RAM file to a cassette file was to change the device specifier to CAS in the OPEN statement in line 500 Experiment 5 Transfer Data from RAM to Cassette Suppose that you have created a data file in RAM and would like to transfer it to cassette You might like to do thi...

Page 134: ...he cassette file NAMES Since this file will be written to cassette it is declared an OUTPUT file Line 138 The statement INPUT I N reads the name from the RAM file and stores it in the string variable N The PRINT 2 N statement writes the name to the cassette file The statement PRINT N displays the name Line 148 If the end of the RAM file has not been reaChed the program jumps back to line 130 where...

Page 135: ...number of 1 Since the file is written to it is declared an output file Lines 28 38 The FOR NEXT loop repeats 30 times corresponding to the 30 data values Each time through the loop the next sales value is read from the DATA statements and then output to file number 1 Lines 48 The DATA statements contain the 30 sales values in chronological order Once the RAM file has been created it can be used re...

Page 136: ......

Page 137: ...r the following program 5 OPEN RAM SALEDA DO FOR INPUT AS 1 10 FOR W 1 TO 8 FOR D 1 TO 5 20 INPUT 1 t S WtD 30 NEXT D NEXT W 1I0 PRINT WEEK MON TUE WED THU FRI 50 FOR W 1 TO 8 PRINT W 80 FOR D 1 TO 5 70 PRINT TA6 D 5 S WtD 80 NEXT D PRINT 80 NEXT W Execute this program The program will read the file SALEDA DO containing sales data The following table will then be output to the LCD WEEK MON TUE WED...

Page 138: ... 59 The first statement in the line begins another FOR NEXT loop This loop will display the daily sales for each week starting with week 1 then week 2 etc and ending with week 6 The sales were stored in chronological order so that the first five values are the sales for the first week the next five values are for the second week and so on The second statement PRINT Wi displays the week number The ...

Page 139: ...d in the print statement in line 50 the week number and daily sales for that week are all displayed on the same line Line 89 The NEXT statement defines the end of inner loop which displays the sales for each day The PRINT statement in this line generates a carriage return which causes the next week s sales to be displayed on the next line Line 99 The NEXT W statement defines the end of the outer l...

Page 140: ...nitialized to zero outside the loop lines 60 80 where the sum is computed The weekly sum is divided by five to obtain the average and displayed in line 80 Experiment 3 Computing the Average for Each Weekday The previous program will be changed so that the average sales for each weekday can be calculated There are six sales figures for each day so to calculate the average these six values must be a...

Page 141: ...A 0 initializes the daily sum to zero The second FOR statement FOR 14 1 TO 8 defines an inner loop which sums the six week s sales for a given day Line 118 The sales for a given day are added and stored in the numeric variable DA The NEXT statement defines the end of the inner loop Line 128 The daily average is displayed The TAB function is used to neatly space the output The INT function is used ...

Page 142: ...s over at the beginning of the array This time however it will only be necessary to go up through the next to the last element In this fashion the largest element goes to the end the next largest goes to the next to the end position etc The name bubble sort is descriptive of this process because of the way the large values pop up one at a time into their correct positions at the end of the array T...

Page 143: ...the smallest value will be placed in S 2 At that point S 1 must contain the smallest value so the array is sorted Line 510 This line starts the FOR NEXT loop in which the comparisons and possible interchanges will be made When I 1 J will range from 1 to N 1 when I 2 J will range from 1 to N 2 and so on When I 29 J will only have the value 1 Thus as more and more values are stored in their correct ...

Page 144: ...ndency the median Experiment 5 Computing the Median Now that you know how to sort the sales data you can easily change your program to compute the median The median is similar to the average in that they both measure central tendency The median is a number such that half of the data values are larger than the median and half of the data values are less than the median If the data values are sorted...

Page 145: ...LEOA OO FOR INPUT AS 1 10 DIM S 30 20 INPUT NUMBER OF DAYS 2 30 N 30 FOR I 1 TO 30 L10 INPUT 1 t S I 50 NEXT I 500 FOR I 1 TO N 1 510 FOR J 1 TO N I 520 IF S J S J 1 GOTO 5L10 530 S S J S J S J l S J l S 5L10 NEXT J NEXT I 550 N1 INT N 1 2 N2 INT N 2 2 560 MO S N 1 S N2 2 570 PRINT MEDIAN IS MO Execute the program This time you will be prompted for the number of days of sales to be read After you ...

Page 146: ... use of the INT function avoids any testing to determine whether N is even or odd Line 569 The median is calculated in this line If N is even then the average of the two middle values is computed If N is odd then the values stored in NI and N2 are the same and so the median is correctly calculated as the middle value Line 579 The median is displayed Now that you have a program which will sort an a...

Page 147: ... 0 150 END and change line 57lil to 570 RETURN List the program to confirm that it is now 5 OPEN RAM SALEOA OO FOR INPUT AS 1 10 N 8 20 FOR W 1 TO 8 FOR 0 1 TO 5 30 INPUT I 1t R W O L10 NEXT 0 NEXT W 50 FOR 0 1 TO 5 FOR W 1 TO 8 80 S W R W O 70 NEXT W 80 GOSUB 500 80 M O MO 100 NEXT 0 110 PRINT TAB 10 MEDIAN SALES 120 PRINT MON TUE WED THU FRI 130 FOR 0 1 TO 5 PRINTTAB 0 1 7 M 0 1L10 NEXT 0 150 EN...

Page 148: ...the second week to S 2 and so on Line 78 The inner loop which transfers the six data values from the two dimensional array to the one dimensional array is terminated Line 88 This line contains a new statement GOSUB When this statement is executed the program jumps to line 500 Lines 500 through 570 sort and compute the median of the one dimensional arrays S The median is stored in the variable MD l...

Page 149: ... GOSUB statement Here are some rules governing the use of subroutines 1 Every subroutine must contain a RETURN statement It may contain more than one RETURN statement if there are several places in the subroutine from which you want to return 2 A program may contain several subroutines 3 A subroutine may call another subroutine 4 A subroutine may be placed anywhere in a program as long as it is ex...

Page 150: ......

Page 151: ...find in the following experiments You have already seen that printing CHR 7 will sound the bell character Try it now to recall the sound PRINT CHR 7 Another way to make the same sound is to use the BEEP statement Type BEEP CEH ml and you will hear the same sound To verify that the sounds are identical enter PRINT CHR 7 BEEP and you will hear two beeps in succession You might want to use sound as a...

Page 152: ...in the SOUND statement determines the frequency of the tone and must be an integer in the range of 0 to 16383 You can hear the full range of tones by entering the following program 1121 FOR I 121 TO 18383 STEP 1121121 20 SOUND 1 2 30 NEXT I Execute the program The sounds you hear are tones of approximately 40 milliseconds duration ranging from the highest frequency 0 to the lowest frequency 16383 ...

Page 153: ...N L 20 a0 GOTO 10 100 DATA a687 1 a687 1 a687 1 6268 1 110 DATA 5586 1 5586 1 6268 2 3728 1 120 DATA 3728 t1 a18a Ii a18a Ii a687 a 130 DATA 0 0 Execute the program and you will hear the familiar Old MacDonald s Farm melody Line 18 The note N and the length L are read from the DATA statements N is the frequency specifier for the note and L is the number of beats Line 28 A test for the end of the m...

Page 154: ... the NEW command and enter 1121 CLS 2121 FOR 1 12121 TO 158 3121 PRINT I CHR 1l17 j 4121 FOR J l TO GI2I NEXT J 5121 NEXT I Execute this program and watch the stick figure race across the display While this program added action it does not adequately simulate movement You can erase the trail behind the runner by printing a space in his previous position and simulate movement more realistically Cha...

Page 155: ...t 6 Generating Random Numbers Computers can be used to simulate random events This leads to many interesting and useful applications For example you can use simulation to create such seemingly diverse applications as interactive games and business decision making models What makes simulation possible on a computer is the ability to generate random numbers The RND function can be used to return a n...

Page 156: ...etween 0 and 5 between 5 and 1 Outcome Head Tail Since the probability of generating a number in the range 0 to 0 5 is equal to the probability of generating a number in the range 0 5 to 1 this scheme will generate heads and tails with equal probability Use the NEW command to clear memory and enter the following program 10 CLS 20 A RND l 30 IF A 5 THEN A HEAD ELSE A TAIL 110 PRINT A PRESS ENTER 50...

Page 157: ... GOTO 2121 Execute the program several times to verify that different sequences of outcomes are being generated each time Remember to use to terminate execution The RND function can be used with three types of arguments x RND x greater than 0 equal to 0 less than 0 generates next random number generates same random number generates a new sequence of random numbers dependent upon the value of x In ...

Page 158: ...achine Line 18 The time is used to initialize the sequence of random numbers Line 28 This statement clears the display Line 38 The outline of the slot machine is drawn as a box using the LINE statement Lines 40 60 The three windows are drawn as boxes using the LINE statement Line 78 A FOR NEXT loop is used to control the duration of the spinning of the slot machine wheels The upper limit of 30 was...

Page 159: ...word W I N is printed on the bottom of the slot machine Lines 228 238 This loop produces the siren sound by increasing the frequency in steps of 50 Line 248 The W I N message is erased so that it will appear to flash Line 258 A FOR NEXT loop is used to create a short delay Line 268 The NEXT J statement defines the end of the W I N loop At the end of the loop execution will transfer to line 170 whi...

Page 160: ......

Page 161: ...tate the use of frequently used operations However you can program any Function Key to perform any other operation or to input a string of characters Enter the following command KEYLIST to display the strings programmed into each of the eight function keys You should see hEYLIST F i liE Sa e If L i st Ok I Load Ii F L n 1F nL which indicates that the Function Keys are programmed in the following o...

Page 162: ...ish to enter the Edit mode If there is no program currently in working memory this command will have no effect Use the KEYLIST command to confirm that you have programmed fID and If you enter KEYLIST you should see hEYLIST Fi Ies Save U List EDIT Ok Load U Run PRINT TIME MenLI You can change any of the Function Keys including the factory programmed keys For example enter KEY 3 PRINT DATE CHR 13 an...

Page 163: ...tion Key interrupts work Clear memory with the NEW command and enter the following program 10 KEY ON 20 ON KEY GOSU6 100 200 300 30 PRINT I 1 1 1 GOTO 30 100 PRINT SU6ROUTINE 1 RETURN 200 PRINT SU6ROUTINE 2 RETURN 300 PRINT SU6ROUTINE 3 RETURN Execute this program and watch the display You should see a series of numbers starting from zero and increasing by one scrolling on the display Press CfI Yo...

Page 164: ...nction Keys will be ignored during program execution Line 38 A continuous loop prints the integers starting at zero and incrementing in steps of one These statements keep right on printing so long as a Function Key is not pressed Line lee This two statement interrupt subroutine is executed if the Function Key Ij is pressed The statement which is being executed when the Function Key is pressed is a...

Page 165: ...program This time however press the F1 function key before the 20 SUBROUTINE 2 messages finish printing You then should see the message SUBROUTINE 1 displayed once and the SUBROUTINE 2 message continue until all 20 repetitions are complete Finally execution returns to the main program where the numbers continue to be displayed Sometimes it is desirable to be able to interrupt an interrupt subrouti...

Page 166: ...play carefully you will see the message SUBROUTINE 1 display after the last SUBROUTINE 2 message is displayed This is because the KEY STOP statement in line 200 delays execution of the j interrupt until the current interrupt subroutine is finished Experiment 4 Checkwriter with Interrupts In this experiment you will simulate a payroll program which allows interruption from the keyboard This could b...

Page 167: ...1 83 DOLLARS If you let the program run for a few minutes you will see checks display in succession for each of the employees listed in the data statements As you can see it takes quite a bit of time to display each check This was intended to simulate the time it would take to print a check using a printer instead of the LCD display Execute the program again This time however press Cf1 before the ...

Page 168: ...ted in the upper left corner of the check Line 78 The date is printed in the upper right corner of the check Line 88 An empty box is drawn in the center of the check to make room for the name and amount of the check Line 98 The employee name is printed on the check after the message PAY TO Line 188 The salary is computed as the pay rate R I times the hours worked H I and printed on the check below...

Page 169: ...on of the interrupt subroutine Lines 3 3U These DATA statements contain the six names with their respective pay rate and hours worked This simple program suggests how interrupts can be used in a more elaborate payroll program Typically a practical payroll program will use a personnel file containing hundreds or perhaps thousands of characters of infomlation for each employee Conceivably you could ...

Page 170: ......

Page 171: ... in serial communications However some familiarity with the terminology and concepts would help tremendously The following discussion highlights some important concepts about serial communications Serial communications between a computer and an external device is done one character at a time A character can be uniquely represented as a series of data bits which can be thought of as a list of ones ...

Page 172: ...0 9 19200 5 1200 Note 300 and 1200 baud are common speeds for transmission of data over telephone lines using audio tones The Model 100 has a built in modem which allows a direct connection to the telephone lines for 300 baud communications However if you use the serial port rather than audio tones through the modem you can communicate with other serial devices at any of the baud rates listed abov...

Page 173: ...del 100 which YO l pi 0 use liter in your office SIcm i1Ic follo ing proa don will iIllow y 10 t fer DASIC gram l aoother ampuler Conne 1lhe 1 computtlS via on RS 232C cahle 26 441 l3 and a Noll Moo m A lapl r See figure below SCI communication parameter in lo offj sylUrn lhat tbe Model 100 can lell der l I yow y e W le manoal 01 d guide Load the progr m in ASCli fOrmal yoo widl 10 lnn f into the ...

Page 174: ...h refer to your system s owner s manual or reference guide 4 From the Model 100 Main Menu position the cursor on the word TELCOM and press The display then shows M7I1E 10 PPS Tel com Find Call Stat Term Menu D The first line reminds you of the current serial communications status The second line is the TELCOM prompt which lets you select one of the functions displayed on the last line of the scree...

Page 175: ... of TELCOM Function Key Bye lets you exit the Terminal Mode 7 Now that the computers are connected with matching communication parameters decide on a file with the extension 00 that you wish to send and press f3 the Upload Function Key The prompt File to Upload I will be displayed 8 Enter the name of the file to be transferred The prompt Width will appear Enter a number between 10 and 132 to forma...

Page 176: ... Ignore this message The data has been transferred 5 Since the program does not display as it is loaded you will probably want to list it to confirm that it was transferred properly If a few errors are found they can be corrected using the Editor After the file has been successfully transferred it can be saved in RAM in the usual way Experiment 4 Loading a File with TELCOM You can transfer any ASC...

Page 177: ... OPEN COM 3701D FOR OUTPUT AS 1 20 INPUT NAME N 30 PRINT 1 N 40 GO TO 20 Note The peripheral device connected to the RS 232C port should have the same configuration 3701D Before executing this program you should connect a peripheral device with an appropriate RS 232C cable to the M100 serial port and use the correct port status Once the peripheral device is connected and ready to receive execute t...

Page 178: ...om the COM device You can interrupt execution of a BASIC program from the serial port This can be very useful to allow communications with a peripheral device which transmits data at unpredictable times For example a lab instrument might send test results sporadically as they are completed Using the interrupt capability you could use the Model 100 to run a BASIC program yet still capture the data ...

Page 179: ...nerated and execution jumps to this line No interrupts can occur during an interrupt subroutine If a character is received during the interrupt subroutine it will be remembered and another interrupt will occur when the current one is completed This line will display the received character and then return to the main program The INPUT l l statement inputs one character from file number 1 In general...

Page 180: ...e PRINT statement in line 120 is necessary to print a line feed before returning to the main program A word of caution Since the receiving program is written in BASIC and the serial port buffer has a limited capacity you still cannot receive long flIes without missing some characters This is especially true at higher baud rates The procedure described above should therefore be used only with appli...

Page 181: ...ews weather data banks other computers or stock market information You can make use of this information in a variety of ways For example you may display it on the LCD print it on a printer save it in a file analyze the data using a BASIC program to graph it compute statistics make comparisons against previous values and more You can also transfer programs or data files to other computers located m...

Page 182: ...t line of the display The last line displays the definition of the Function Keys in TELCOM s Entry Mode For a complete discussion of the role of the Function Keys in the Entry Mode see Using the Function Keys in Entry Mode in the owner s manual p 79 When entering the Terminal Mode the display of the Function Keys will change to reveal their new uses Experiment 1 The Communication Parameters Before...

Page 183: ... Note The Model 100 uses 300 baud when the built in modem is in use If you use a number to set the baud rate even if that number is 3 for 300 baud the modem becomes disabled and instead the RS 232C interface is activated Therefore always select the letter M whenever the built in modem is to be used If the communication parameters of the Model 100 need to be changed to match those of the host simpl...

Page 184: ...o indicate it has entered the Terminal Mode Also the definitions of the Function Keys will change as the display shows Up Full Hue For a detailed discussion of the role of the Function Keys in the Terminal Mode consult your owner s manual Automatic Entry To enter the Terminal Mode automatically you must first store the host s telephone number in the ADRS DO file followed by the special symbols Thi...

Page 185: ...tion that you are authorized to access a host system Detailed instructions for complying with the log on procedure should be described in your user s guide Experiment 2 Automatic Log On The Model 100 gives you the option to combine the Entry and Terminal Modes to dial and log on to an information service automatically This is a practical time saving feature especially if you make regular use of an...

Page 186: ...s the log on sequence should look like this IS 123 4567 AM M U8768 453AM PTwo toneAM SNews M This is an explanation of how the above log on sequence was determined 1 Access the ADRS DO file and position the cursor over the symbol 2 Referring back to the log on sequence you must first send two carriage returns Type AM AM the symbol Ais obtained by pressing SHIFT CU 3 Next tell the Model 100 to anti...

Page 187: ...EW YORK NY 00100 DEF MICROWARE 5678 SCENIC DR COMPUVILLE CA 14567 MACRoSoFT 8876 WONDER WAY WETSVILLE WA 88734 To log off the system type BYE ENTER or press CfI A log off message such as THANK YOU FOR USING THE M100 USERS BULLETIN BOARD SYSTEM DISCONNECTING may be displayed Then TELCOM will display the prompt Disconnect Enter CTI to disconnect If you enter CI you will keep the telephone connected ...

Page 188: ...the hourly quotes in a data file for later analysis The following program segment will dial and log on to the hypothetical IS Information Service from the previous two experiments 100 0 123 45G7 WM U87GB 453 M PT lo tone h M SNewshM 110 M VARPTR O 120 D PEEKCM 1l PEEKCM 2l 25G 130 CALL 21200 CALL 21283 0 0 Line 166 The telephone number and log on sequence are stored in the string variable D Line 1...

Page 189: ...HR 13 180 CALL 21178 200 CLOSE Line 5 Since the program has two files open simultaneously it is necessary to use the MAXFILES statement to provide buffer space for them Line 146 The modem is opened to accept input using file number 1 Note that the status is included in the OPEN statement but the baud rate is not specified since it is assumed to be 300 baud through the modem Line 158 Received chara...

Page 190: ...1 PEEK M 2 256 130 CALL 21200 CALL 21283 0 0 140 OPEN MOM 7I10 FOR INPUT AS 1 150 IS INPUTS 1d PRINT IS 160 IF IS CHRS 26 GOTO 150 170 OPEN MOM 7I10 FOR OUTPUT AS 2 180 PRINT 2 BYE CHR 13 180 CALL 21178 200 CLOSE What you have learned You have learned how to use the built in modem to communicate with other systems over the telephone lines You have seen that it is possible to communicate in either ...

Page 191: ...lator This means that numbers may be added subtracted multiplied or divided as they are entered from the keyboard without having to include them as an expression in a PRINT statement Execute the program There will be no visual indication that anything has happened However if you type the following sequence 2 3 you will see that the result is immediately displayed 2 3 5 Notice that this is exactly ...

Page 192: ...185 IF C A THEN S l C GoTo 110 180 IF C THEN L L 1 R L 0 S L GOTO 110 200 IF C THEN PRINT R l L 0 GoTo 100 205 IF ASC C 13 THEN PRINT II CANCELLED L 0 GO TO 100 210 GoTo 110 500 REM SUBROUTINE GET CHARACTER 510 C INKEY IF C GoTo 510 520 PRINT C 530 RETURN 600 REM SUBROUTINE GET NUMBER 630 NU 0 635 IF C THEN DF l GoTo 675 640 NU 10 NU VAL C 650 GoSUB 500 855 IF C THEN DF l GoTo 875 860 IF ASC C 48 ...

Page 193: ...hen returns to line 110 to get the next character Line 2ee If an equals sign is typed then the answer which is the result at the current level is displayed The level is initialized to zero and execution jumps to line 100 to begin a new problem Line 265 If ENTER is pressed then the message CANCELED is displayed and a new problem is begun Line 218 If any other key is inadvertently typed it must be a...

Page 194: ......

Page 195: ...e it to the listing below to verify that it loaded correctly 100 CLS P RND VAL RIGHTS TIMESt2 110 PRINT Want Instructions Y yest N no i GOSUB 1000 120 IF A Y OR A y THEN GOSUB21l11l11l11l1 125 IF AS N AND AS n GOTO 100 13111 PRINT Len t of sequence L 1lI 9 GOSUB 1000 L VAL AS 132 IF L 0 GOTO 800 134 PRINT How many notes N 2 9 i GOSUB 111100 N VAUAS 136 IF N 1lI OR N l THEN CLS GOTO 134 142 NP 0 NC...

Page 196: ...ted with it 835 PRINT 280 Press ESC to be tin tame 8110 A INKEY IF A GO TO 8110 850 IF A l OR A 8 GOTO 100 880 SOUND 8000 ASC A 48 500 20 87121 GOTO 811121 1000 A INKE IF A 1 GOTO 1000 ELSE PRINT A RETURN 2000121 REM INSTRUCTIONS 20010 CLS PRINT MEMORY MASTER is a tame hich tests PRINT your ability to memorize a seCluence PRINT of tones 20020 GOSUB 30000 20030 PRINT Two different sKills are bein t...

Page 197: ...mand SAVE MEMO For convenience save the program on a separate cassette with the command CSAIJE MEMO Execute the program In answer to the prompt Want Instructions Y yes N no press CIJ to request instructions on the use of the program The instructions will be presented a few lines at a time Press any key to continue the instructions After all the instructions have been displayed you will again see t...

Page 198: ...he current time in seconds Lines IHt 125 The user may request instructions or proceed with the game A subroutine is used to wait for and return a single character from the keyboard The character is stored in the string variable A A subroutine is used to print out the instructions if requested Notice that the IF statements in lines 120 and 125 are testing for both upper and lower case characters Th...

Page 199: ... level change the difficulty level or stop the game Any other response will result in the prompt being redisplayed Line 740 Lines 808 879 This section of the program lets the user listen to the tones associated with the number keys 1 through 9 When any key other than a number key is pressed execution jumps back to the beginning of the program Line 1M This subroutine continuously scans the keyboard...

Page 200: ......

Page 201: ...nd compare it to the listing below to verify that it loaded correctly 1121121 DIM A 1121121 F 1121l 105 CLS 11121 INPUT RAM or CASSETTE FILE R or Cl r 12121 IF T R AND T C GOTO 11215 13121 INPUT FILE NAME N 14121 IF T R THEN N RAM N 15121 IF T C THEN N CAS N 16121 OPEN N FOR INPUT AS 1 165 N 1 17121 INPUT l A Nl 18121 IF EOF 1l GOTO 21121 18121 N N l 2121121 GOTa 17121 21121 CLOSE 22121 CLS 23121 ...

Page 202: ...ANDARD DEVIATION 630 SD SQR l J 640 REM CALCULATE THE MEDIAN 650 N1 INT N 1 2 N2 INT N 2 2 660 MD A N1 A N2 2 670 REM DISPLAY THE RESULTS 675 CLS 680 PRINT NUMBER OF VALUES TAB 20 N 682 PRINT MAX MIN IJALUES TAB 20 A N jA 1 68a PRINT MEAN TAB 20 M 686 PRINT MEDIAN TAB 20 MD 688 PRINT l JARIANCE TAB 20 IJ 700 PR I NT STANDARD DElJI AT I ON TAB 20 SO 702 PRINT INPUT OUTPUT RESULTS TO PRINTER Y or N ...

Page 203: ...0 CLS 1020 REM DRAW THE AXES 1030 LINE 13 0 13 60 LINE 238 60 10a0 Y2 60 X2 20 1050 FORI 1 TO NC 1060 X1 X2 Y1 60 50 F I MF 1070 X2 X1 212 NC 11218121 LINE X1 Yl X2 Y2 t1 BF 1080 NEXT I 11121121 IF T L GOTO 128121 1110 REM PRINT THE HISTOGRAM 1120 X Y 1130 FOR 1 30 TO 1 STEP 1 11a0 LPRINT HA6 10 1150 FOR J 1 TO NC 1160 H 30 F J MF 1170 IF H I THEN LPRINT X ELSE LPRINT Y 1180 NEXT J LPRINT 1180 NEX...

Page 204: ...t82 13 t28 74 tGG 91 t43 32 t55 4G 77 t31 8G t58 59 tGZ 43 71 38 tG9 Z3 t77 48 39t4Z 3Gt4S 30t37 43t47 41 Save the data as a RAM file by pressing CEID You will return to the Menu If you want to make any changes to your data file simply move the cursor over the file name DATA DO and press ENTERl Use the standard Editor commands to make your changes After your data file is created you can use the de...

Page 205: ...r the printer before proceeding The data is displayed and or printed in a single column as illustrated below 23 5 35 7 45 2 t t t 43 47 41 After the data is displayed or if no data display was requested you will see the message SORTING PLEASE WAIT After the data has been sorted the display will clear and you will be prompted with OUTPUT SORTED VALUES Y or N Enter rn for Yes if you want to output t...

Page 206: ...sploy cleu nfllh P l rreus ISTOCRAM IY or Nl Enter IT for V if you would like to see h togram graphic plO of Ill distribu oo of Ill dat Enter CIJ for No if you do nOl want I hiSl gf1lm If yoo reqt e l hi5l0gram yoo will be I fOIll ltd to nler the number of d NUI18ER OF CLASSES fS ltl The number of d i the number of interval of qual widlll to d ssify lle data into For ampl if J II ant to divid IIe ...

Page 207: ...1 2 3 4 5 6 7 8 9 10 12 18 8 27 8 35 7 43 6 51 5 59 4 67 8 75 2 88 1 CLASS TO 19 9 TO 27 8 TO 35 7 TO 43 6 TO 51 5 TO 58 4 TO 67 3 TO 75 2 TO 83 1 TO 81 FREQUENCY 3 3 7 10 8 4 3 4 3 2 Figure 3A 3 Listing of Class Intervals Explanation of the Program Line 188 The data values will be stored in the array A and the frequencies for the histogram will be stored in the array F The maximum number of data ...

Page 208: ...ts Lines 749 939 The user is asked if a histogram is desired If not execution ends If a histogram is desired it is necessary to input the number of classes NC and then to calculate the class length CL A FOR NEXT loop Lines 830 880 increments through all data values and counts the frequency of occurrence in each class The frequencies are stored in the F array A FOR NEXT loop Lines 910 930 is used t...

Page 209: ...Deleting 74 Download 169 182 EDIT 70 END 143 ENTER 3 4 Echo 169 Editing 7 Editor 69 end of file 70 203 Entry Mode 175 Error Message 3 FILES 16 FOR NEXT 88 90 91 FRE 115 File Extension 16 File Name 15 16 Files 3 Full Half Duplex 169 181 Function Keys 155 GOSUB 142 143 GOTO 6 Handshaking 166 IFITHEN 46 IFITHEN ELSE 50 52 INKEY 119 INPUT 35 38 INPUT 173 INPUT 125 INT 135 140 Infinite Loop 6 54 Insert...

Page 210: ...55 RIGHT 64 RND 149 RS 232C Interface 165 RUN 5 6 Random Numbers 149 Relational Operator 47 Reverse Video 82 SAVE 16 17 SAVE CAS filename 21 SAVE COM 167 SOUND 145 146 SOUND OFF 145 SQR 111 STEP 96 STOP 56 STR 63 STRING 61 SUBROUTINE 157 Select 82 83 Serial Port 165 Serial Communications 165 Sorting 136 137 Start Bit 165 Stop Bit 165 167 204 Subscripted Variables 87 93 Syntax Error 4 TAB 131 TAN 1...

Reviews: