Category : BASIC Source Code
Archive   : BASICCLS.ZIP
Filename : BASIC3W
.N:6
.R:
.H :PAGE $$$ BASIC LANGUAGE COURSE INFORMATION SHEET - (C) TRILOGY MICRO SYSTEMS 1989
.H :
.F :
.f : -------- TRILOGY MICRO SYSTEMS - TEL. (301) 764-0816 ---------
Definitions:
FLAG Data that is used to indicate a special condition. The flag
has a value that is different from the normal values for the
data. For example, -1 is often used to indicate end of data
where the data would not contain negative numbers.
PROGRAMMING
The READ and DATA statements go together. They are used to assign values to
variables. They are most useful when the program will be run only once, or when
a series of values to be used by the program are constants.
The DATA statement contains one or more constants separated by commas. String
constants do not have to be in quotes unless they contain blanks, commas or
semicolons. The same DATA statement can contain both string and numeric
constants.
The READ statement sets a variable equal to the next constant from the DATA
statement(s). Its format is READ list of variables where the variable names
are separated by commas. The variable name and the value of the constant must be
of the same type.
The RESTORE statement allows you to reset the line number of the DATA statement
that the next READ statement will access. Its format is RESTORE line number
where line number refers to a DATA statement. If line number is omitted, the
next READ statement will refer to the first constant in the first DATA
statement.
10 REM CALCULATE GRADE POINT AVERAGE
20 READ CREDITS, GRADE
30 IF CREDITS = -1 THEN 70
40 TOTCREDITS = TOTCREDITS + CREDITS
50 TOTINDEX = TOTINDEX + GRADE * CREDITS
60 GOTO 20
70 IF TOTCREDITS = 0 THEN END
80 GP = TOTINDEX / TOTCREDITS
90 PRINT "GRADE POINT AVERAGE" GP
100 DATA 3,2,4,3,2,4,3,3,1,2,3,1,4,2,4,3,2,4,1,2,-1,-1
Class Assignment:
Write a program which simulates a phone book. Use READ and DATA statements to
store names and phone numbers. Have a flag to indicate the end of the data. The
user will input a name. The program will compare it to the names in its phone
book. If it finds a match, it will print the phone number. Allow the possibility
of looking up more than one phone number.
Optional Lab Assignment:
Expand the phone book program to include address. Allow lookups based on name or
address.
Most programs must perform certain routines over and over. This is accomplished
with a loop. The program must have some way of stopping the loop. Otherwise it
will keep on looping and the machine will "hang" - there is no way to stop the
computer from continuing to do the looped instructions and do other useful work.
You can use GOTO statements in combination with IF for looping. However,
programs with many GOTOs quickly become difficult to follow. There are two
preferable methods.
The WHILE - WEND statements are used to perform statements in a loop while a
certain condition is true. The WHILE condition statement starts the loop and
the WEND statement ends it.
10 REM CALCULATE THE FACTORIAL OF A GIVEN NUMBER
20 INPUT "WHAT FACTORIAL";E
30 F = 1
40 A = 1
50 WHILE A <= E
60 F = F * A
70 A = A + 1
80 WEND
90 PRINT E "FACTORIAL IS" F
The FOR - NEXT statements are used to perform a loop until a variable reaches
a maximum value. The FOR statement sets the initial value of the variable, its
maximum and optionally the increment. The increment can be a negative number.
The format is FOR variable = x TO y STEP z. The NEXT variable statement ends
the loop.
10 REM CALCULATE THE FACTORIAL OF A GIVEN NUMBER
20 INPUT "WHAT FACTORIAL";E
30 F = 1
40 FOR A = 1 TO E 'Replaces lines 40 - 80 above
50 F = F * A
60 NEXT A
90 PRINT E "FACTORIAL IS" F
Lab Assignment #3
Modify the second lab assignment. The patient's height and weight and type of
conversion needed should be contained in DATA statements (make up your own
data). You can either program it to convert the data for 10 patients (using FOR
and NEXT) or until there is a flag in the DATA statements (using WHILE and
WEND).
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/