BASIC PROGRAMMING LANGUAGE
Subject:
Christian Religious Knowledge
Term:
First Term
Week:
Week 6
Class:
JSS 2 / BASIC 8
Previous lesson: Pupils have previous knowledge of
UNITS OF STORAGE IN THE COMPUTER
that was taught in their previous lesson
Topic:
UNITS OF STORAGE IN THE COMPUTER
Behavioural objectives: At the end of the lesson, the pupils should be able to
- define units of computer storage
- calculate the units of computer storage
Instructional Materials:
- Wall charts
- Pictures
- Related Online Video
- Flash Cards
Methods of Teaching:
- Class Discussion
- Group Discussion
- Asking Questions
- Explanation
- Role Modelling
- Role Delegation
Reference Materials:
- Scheme of Work
- Online Information
- Textbooks
- Workbooks
- 9 Year Basic Education Curriculum
- Workbooks
BASIC PROGRAMMING LANGUAGE
CONTENT
- The Meaning of BASIC
- Rules for BASIC Programming
- BASIC Character Set
- Variables
- Key BASIC Statements
The Meaning of BASIC
BASIC stands for Beginner All-purpose Symbolic Instruction Code. It is not only simple but also a very powerful high level programming language. The original BASIC was designed by John Kemeny and Thomas Kurtz in the mid 1960’s at Dartmouth College in New Hampshire, USA. It consists of statements written in English words and mathematical notation. It is written in English-like and mathematical notations.
Rules for BASIC Programming
(i) All expressions must be written in capital letters.
(ii) First character must be alphabet
(iii) BASIC statement or keyword must start with a line number.
(iv) Each line must contain only one BASIC program statement.
(v) There must not be full stop at the end of a statement.
(vi) The start/begin statement must be the first entry in a program. This does not mean that there is a statement called START.
(vii) The End statement must be the last entry in a program.
(viii) Spaces should be inserted to make the program more readable
BASIC Character Set
- Character Set: These are the acceptable characters in BASIC programming. e.g.
Numbers 0 – 9,
Alphabets A – Z, a – z,
Special characters or symbols +, -, *, /, <, &,:,; etc.
- Data Constants & Data Variables
(i) Data Constant (or constants)
These are data that do not change during the course of computation or program execution.
(ii) Data Variables (variables)
They are data that can change in constant numerals versus variable numerals.
Constant data | Variable data | |
10 A = 1 | 10 INPUT A | |
20 B = 2 | 20 INPUT B | |
30 Sum = A + B | 30 Sum = A + B | |
40 PRINT SUM | 40 PRINT SUM | |
50 END | 50 END | |
- Keyword: This is also referred to as a BASIC statement. It is an instruction which has special meaning to the computer or BASIC interpreter. Examples: REM, LET, INPUT, READ, PRINT, GOTO, FOR…., NEXT etc. these must not be used as a variable name during the course of writing any BASIC program.
What is a Variable? A variable is a symbol that can represent any value. Variables are used to represent values needed for processing during program executions. A Variable can be any alphabet or combination of alphabets.
Rules Guiding Variable Names:
- It begins with a letter
- It does not nave spaces
- It should not be the same name as a word already used by the BASIC language such as END, LET, and PRINT etc.
Types of Variables:
- Numeric Variable: these are used to hold numbers, integers, real numbers or exponential form. Examples are A1, T4, and G9 R2 etc.
- String Variable ($): String variables are used to hold inputs that are alphabetic. This kind of variable can be up to 255 characters in length but it must be enclosed in double quotes (“”). It is represented with the $ sign
Examples of Variables:
Numeric Variable | String Variable ($) | |
A | A$ | |
GREEN | GREEN$ | |
C1 | C1$ | |
DEBORAH | DEBORAH$ | |
ADA | ADA$ | |
L | L$ | |
Key BASIC Statements
Line Numbers:
In BASIC, we need a line number for each BASIC statement. Line Numbers must be positive whole numbers from 1 to 99,999. A line number is always in integer form and this is done to give room for correction when necessary. It is presented in the format below:
10 ……………………..
20 ……………………..
30 ……………………..
40 …………………….. Etc.
REM Statement (Remark or Remember)
REM statements stand for remark or Remember. The statement allows you to add comment and explanatory notes to your program. This may as well include date and what the program or segment of a program is all about. Computer does not execute REM hence, it is NOT necessary to use Line Number for REM. It is just a remark that aids the programmer or whoever reads the program to remember or understand certain things about the program.
Examples:
REM PROGRAM TO SAY HELLO
REM TO CALCULATE AREA OF A TRIANGLE
ASSIGNMENT Statement
1. When did you first learn BASIC programming language?
2. What do you think of BASIC programming?
3. How would you rate your BASIC programming skills?
4. Would you recommend learning BASIC to students who want to pursue a career in programming?
5. Did learning BASIC help prepare you for more advanced programming languages?
INPUT Statement
This allows you to type in data into a variable directly from the keyboard while the program is running. This program will be able to produce the required result with given data. The INPUT statement can be used in the following ways;
Example:
10 INPUT “WHAT IS YOUR FIRST NAME?”, A$
20 INPUT “WHAT IS YOUR SECOND NAME?”, B$
30 INPUT A
Note: if you want to a set of written note to display on your output screen exactly the way you have typed it in your program, you enclose the text with a double quote (“”).
Example:
PRINT “Hello”
LET Statement
The LET statement permits the programmer to assign numbers and formulas to a variable name.
Example:
10 LET FISAYO = ½ (b*h)
20 LET J$ = “How do you do?”
30 LET HEPHZIBAH = 50
DATA Statement
The statement (Read and Data) goes hand in hand. Data statement is used to enter data into a program before running the program or before program execution occurs. The data to be entered into the program is read from DATA statement.
A computer program is a set of instructions that tell a computer what to do. Programs are written in a particular language which the computer can understand. The most basic programs are called “programs” or “scripts.”
The DATA statement is used to write data to a computer file. It has the following syntax:
DATA variable1, variable2, …
The DATA statement can be used to write one or more variables to a computer file. The variables must be separated by commas. For example, the following statement would write the values of x and y to a computer file:
DATA x, y
The DATA statement is often used to write data
Example:
10 READ A, B, C, D
20 DATA 3, 5, 10, 15
Note: The way you arrange the values on DATA line is exactly how the values will go into the variables. So be mindful of it.
OUTPUT Statement (PRINT)
The result of the processed data is displayed by output statement. The PRINT statement brings out the processed data. The print statement has the general format.
In computer programming, the OUTPUT statement is a basic instruction that tells the computer to display or print something. The thing that is displayed or printed can be text, number, or other data.
1. Remember that the OUTPUT statement is used to print text on the screen.
2. The output statement can be used to print text in a single line or multiple lines.
3. You can use the output statement to print variables, constants, and expressions.
4. The output statement prints the values of variables and expressions left-to-right.
5. If you want to print a string in double quotes, you need to use two double quotes inside the string (like this: “I’m a string”).
The OUTPUT statement is usually one of the first instructions a programmer writes in a program because it allows the programmer to see if the program is working correctly. For example, if a programmer is writing a program to add two numbers, she or he can use the OUTPUT statement to print the sum of the numbers. This way, she or he can quickly see if the program is giving the correct answer.
The OUTPUT statement can also be used to display messages to the user of a computer system
Example:
20 PRINT D, E, C
25 PRINT A, $, C
30 PRINT “The answer is”, = ADA
Program Terminator (END)
END Statement: this always indicates the end of a BASIC program. When the computer comes across the end statement in a program, the computer automatically ends. End should always be the last statement in the program to indicate the physical end of the program.
END indicates when the logical executions of a program should cease.
Computer program terminator is a basic computer program that allows users to terminate or end a process or program. It is also known as an “end task” program. This type of program is often used by developers to test the functionality of their code. However, it can also be used by malicious individuals to terminate processes or programs that they do not want to run. Terminator is a popular computer program terminator among developers and computer enthusiasts. It is a free and open source program that is available for download from the internet. Terminator is written in the C programming language and is available for Windows, Linux, and OS X.
Computer program terminator is a basic computer program that allows users to terminate or end a process or program. It is also known as an “end task” program. This type of program is often used by developers to test the functionality of their code. However, it can also be used by malicious individuals to terminate processes or programs that they do not want to run. Terminator is a popular computer program terminator among developers and computer enthusiasts. It is a free and open-source program that is available for download from the internet. Terminator is written in the C programming language and is available for Windows, Linux, and OS X. computer program terminator is a basic computer program that allows users to terminate or end a process or program. It is also known as an “end task” program.
Example:
40 END
CLS
This means CLear Screen. Every BASIC program should begin with CLS to avoid getting unexpected display on the screen.
Simple BASIC Statements
Structure of BASIC Program
(i) One instruction or statement per line
(ii) Each line must begin with a line number
(iii) Line numbers are unsigned positive integers
(iv) Line number should increase in steps of 10 to allow for insertion of extra lines during program modification.
Example 1: Write a BASIC program to find the average of three numbers.
Solution:
5 REM FIND AVERAGE
10 READ A, B, C
20 DATA 5, 10, 15
25 LET SUM=A+B+C
30 LET AVE=SUM/3
35 PRINT AVE
40 END
Example 2: Write a BASIC program to calculate the volume of a box.
Solution:
10 REM FIND THE VOLUME OF A BOX
20 READ L, B, H
30 DATA 3,5,10
40 LET VOLUME =L*B*H
50 PRINT VOLUME
60 END
Conditional Statements
These are statements in BASIC programming that are dependent on some certain conditions and criteria before they can be obeyed. Example is IF…THEN…ELSE
IF…THEN…
This is a conditional statement. If the condition is true, the statement following the “THEN” is executed.
Example:
2 INPUT A
IF A > 500 THEN GOTO 50 ELSE GOTO 2
50 PRINT A
60 END
Sample Program
10 REM PROGRAM TO PRINT NAME AND ADDRESS
20 LET A$ = “Spidaworks High School”
30 LET B$ = “Uti Road off DSC Express Way, Warri, Delta State”
40 PRINT A$
50 PRINT B$
60 END
Presentation
Step 1:
The subject teacher introduces the new topic
Step 2.
He introduces the new topic
Step 3:
The class teacher allows the pupils to give their own examples and he corrects them when the needs arise
Conclusion
The class teacher wraps up or concludes the lesson by giving out a short note to summarize the topic that he or she has just taught.
The class teacher also goes round to make sure that the notes are well copied or well written by the pupils.
He or she makes the necessary corrections when and where the needs arise.
Evaluation
- Write a BASIC program to find the average of five numbers.
- Write short notes on the program terminator.
- Explain the following: Character set, constants and variables.