BASIC PROGRAMMING FOR JSS2

BASIC PROGRAMMING FOR JSS2
Origin of and Features of BASIC
BASIC stands for Beginner’s All-purposed Symbolic Instruction Code. It was developed in 1960 by John Kemeny and Thomas Kurtz to teach students at Dartmouth College. It has undergone series of historical development, which has resulted in several forms of the language.
BASIC is now in form of VB.NET (Visual Basic.Net). The majority of BASIC languages use program translators called interpreters to allow the computer understand and obey the BASIC statements in the computer program. Examples of such interpreters are:
1. BASICA
2. GwBASIC
3. Turbo BASIC
4. Quick BASIC
BASIC Character Set
1. Alphabetic Characters – A to Z
2. Numeric Character – 0 to 9
3. Special Characters – 0 + % ^ # = ( ) etc.
BASIC Arithmetic Expressions
BASIC symbols used to perform arithmetic operations are:
Operation BASIC Symbol
Addition +
Subtraction –
Multiplication *
Division /
Exponentiation ^
Every arithmetic expression must appear on a single line. There is no superscript in BASIC as we find in algebra.
Key Statement of BASIC
Assignment Statement (LET, INPUT and READ-DATA)
1. LET Statement
The let statement is used to assign a numeric or string value to a variable. The assignment statement must consist a variable, an equal to sign and an expression.
Example
LET X = 12
LET B$ = “Deborah”
LET AREA = L*B
2. INPUT Statement
The INPUT statement is uses to enter data into the computer during program execution.
Example
INPUT A, B, C
INPUT N$, M$, Factor
3. READ-DATA statement
READ and Data are two statement concerned with each other which are used to put data in a line of the program and to read the data when it is needed.
Example
READ A, B, C
DATA 5, 6, 7
LET SUM = A+B+C
PRINT SUM
END
4. REM (Remark) Statement
The REM statement is used to insert comments or remarks into a BASIC program. The use of remark statements improves the readability of the program. It has no effect on the program execution.
Example
REM program to add six numbers
5. PRINT statement
This statement is used to transmit data from the computer memory to the output device.
Examples
PRINT A, B, C
PRINT “I Like Writing Program”
Program Terminator (END and STOP)
6. STOP and END statement
The STOP statement is used to terminate the execution of a program at any point in the program. The END statement indicates the actual end of a program. The STOP statement may appear many times and anywhere, whereas an END statement can only appear at the end of a program and only once.
Example
REM END statement
PRINT “Good morning”
END
7. GO TO statement
This statement transfers program control from the line number that contains the statement to the specific number after GOTO statement.
Example
REM GO TO statement
GOTO 40
PRINT “Good morning”
END
In the case above the program’s control is transferred from line 20 to line 40. This means that the program would end when the execution gets to line 20.
Simple Program
Example 1: Program to find the average of six numbers
10 REM Programs to find the average of six numbers
20 REM Numbers given
30 INPUT “Type in the first number”;A
40 INPUT “Type in the Second number”; B
50 INPUT “Type in the third number”; C
60 INPUT “Type in the forth number”; D
70 INPUT “Type in the fifth number”; E
80 INPUT “Type in the sixth number”; F
40 LET SUM = A+B+C+D+E+F
50 LET AVERAGE = SUM/6
60 PRINT AVERAGE
70 END
Example 2 Program to calculate the perimeter and Area of a Rectangle
REM program to calculate the perimeter and Area of a Rectangle
INPUT “Input the length” L
INPUT “Input the breath” B
LET PERIMETER = 2 * (L + B)
LET AREA = L*B
PRINT “the perimeter is” PERIMETER
PRINT “the area is” AREA
END