Explain the following commands
(i) DEF FNA(x)
(ii) DIM A (3, 3)
(iii) RESTORE
Answers
Explanation:
PRINT Statements
The PRINT statement allows several quantities, including quoted strings, separated by commas (,) or semicolons (;). If by commas, BASIC moves to the start of the next zone. Zones are 15 characters in width. If by semicolons, BASIC does not move but starts the next item at the next space.
Numerical values are printed with either a leading space or a minus sign, and with a trailing space. Thus, numerical values in a PRINT statement with semicolons as separators will have at least one space between values. Furthermore, numeric values will always produce a number of characters that is a multiple of three. Thus,
PRINT 12; 34; 56
will produce
12 34 56
While there is no string data type, quoted strings are allowed in PRINT statements. If a quoted string and a numeric value are separated by a semicolon in the PRINT statement, the semicolon may be omitted.
If the material on the printed line exceeds 75 characters, an end-of-line is automatically introduced. We sometimes say that the MARGIN is 75.
Defined Functions
The user may define up to 26 new functions, giving them names from FNA to FNZ. Each such function is introduced by the DEF keyword. There must be exactly be one argument. The variable name used as an argument is distinct from the variable with the same name in the rest of the program. The function definition must be a single line with the following form:
DEF FNX(X) = <expression>
The expression should contain an X unless the function value does not depend upon an argument; the expression may contain other variables from the program.
DEF statement may appear anywhere in the program before the END statement.
Example Programs
100 REM PLOT A NORMAL DISTRIBUTION CURVE
110
120 DEF FNN(X) = EXP(-(X^2/2))/SQR(2*3.14159265)
130
140 FOR X = -2 TO 2 STEP .1
150 LET Y = FNN(X)
160 LET Y = INT(100*Y)
170 FOR Z = 1 TO Y
180 PRINT " ";
190 NEXT Z
200 PRINT "*"
210 NEXT X
220 END
100 REM GUESSING GAME
110
120 PRINT "GUESS THE NUMBER BETWEEN 1 AND 100."
130
140 LET X = INT(100*RND(0)+1)
150 LET N = 0
160 PRINT "YOUR GUESS";
170 INPUT G
180 LET N = N+1
190 IF G = X THEN 300
200 IF G < X THEN 250
210 PRINT "TOO LARGE, GUESS AGAIN"
220 GOTO 160
230
250 PRINT "TOO SMALL, GUESS AGAIN"
260 GOTO 160
270
300 PRINT "YOU GUESSED IT, IN"; N; "TRIES"
310 PRINT "ANOTHER GAME (YES = 1, NO = 0)";
320 INPUT A
330 IF A = 1 THEN 140
340 PRINT "THANKS FOR PLAYING"
350 END
Commands
Although not part of BASIC, the commands of the operating system include the following:
HELLO Start a new session, enter your user number
NEW Start a new program
OLD Retrieve a program from storage
SAVE Save the current program to storage
REPLACE Save the current program to storage, overwriting older version
RENAME Rename the current program
CAT List the names of your saved programs (short for CATALOG)
LIST List the current program
RUN Run the current program
STOP Stop the current run of the program (in case an infinite loop)
UNSAVE Unsave the current program program
SYSTEM Name the system -- limited to either BASIC (default) or ALGOL
BYE End the session
GOODBYE Same as BYE