Example of Basic Programming Language – JSS2 Computer Studies Lesson Note (Second Term)
Download this term · ₦1,000Lesson note at a glance
- Subject
- Computer Studies
- Class
- JSS2
- Term
- Second Term
- Topic
- Example of Basic Programming Language
- Order
- Topic 2 of 6 this term
- Reading time
- 5 min
BASIC (Beginner’s All-purpose Symbolic Instruction Code) is a programming language in which a program is written as a list of instructions, such as Cls, Input, Let, Print and End.
Behavioural objectives
By the end of the lesson, students should be able to:
- write a BASIC program that enters and prints a name, city, country and age;
- write BASIC programs to find the area of a rectangle, a triangle, a circle and a square;
- write a BASIC program to find the circumference of a circle;
- write a BASIC program to find the square and cube of a number;
- use the Input, Let and Print statements correctly in a program.
What are the common BASIC statements?
A BASIC statement is a single instruction that tells the computer what to do.
| Statement | Use | Example |
|---|---|---|
| CLS | Clears the screen before the program runs. | CLS |
| INPUT | Shows a message and takes a value from the user. | Input “Enter the radius “; R |
| LET | Gives a value or the result of a calculation to a variable. | Let A = l * b |
| Displays a message or a value on the screen. | Print “The area is “; A | |
| END | Marks the end of the program. | End |
What is a variable in BASIC?
A variable is a named place in the computer’s memory where a value is stored.
- String variable: stores words or text and its name ends with a dollar sign, as in N$ for a name.
- Numeric variable: stores numbers and its name has no dollar sign, as in A for an age or l for a length.
What are the arithmetic operators in BASIC?
Arithmetic operators are the symbols used to do calculations in a BASIC program.
| Symbol | Operation | Example |
|---|---|---|
| + | Addition | Let S = a + b |
| – | Subtraction | Let D = a – b |
| * | Multiplication | Let A = l * b |
| / | Division | Let H = 1/2 * b * h |
| ^ | Power (index) | Let square = n^2 |
What are the steps for writing a BASIC program?
A simple BASIC program follows the same order every time.
- Start with CLS to clear the screen.
- Use Input to take each value from the user and store it in a variable.
- Use Let to calculate the answer from the stored values.
- Use Print to display the answer with a short message.
- Finish with End.
How do you write BASIC programs that enter and print data?
To enter and print data, use Input to store the value in a variable and Print to display it.
Example 1: Enter a name and print it
Write a program to enter your name and print it.
CLS
Input “Enter your name”; n$
Print “The name is”; n$
End
- Input line: shows the message and stores the typed name in n$.
- Print line: displays the message, then the name stored in n$.
Example 2: Enter a name, city, country and age
Write a program to enter your name, city, country and age and print them.
CLS
Input “Enter the name “; N$
Input “Enter the city”; C$
Input “Enter the country”; CO$
Input “Enter the age”; A
Print “The name is “; N$
Print “The city is “; C$
Print “The country is “; CO$
Print “The age is “; A
End
- N$, C$ and CO$: string variables, because a name, city and country are text.
- A: a numeric variable, because age is a number.
- Sample input: Ade, Lagos, Nigeria and 12 are printed back in the same order.
How do you write BASIC programs to find area and circumference?
To find an area or circumference, take the measurements with Input, calculate with Let and show the answer with Print.
Example 3: Area of a rectangle
Write a program to find the area of a rectangle.
Cls
Input “Enter the length “; l
Input “Enter the breadth “; b
Let A = l * b
Print “The area of rectangle=”; A
End
- Formula: area = length × breadth.
- Calculating statement: Let A = l * b.
- Sample run: length 5 and breadth 4 give an area of 20.
Example 4: Area of a triangle
Write a program to find the area of a triangle.
Cls
Input “Enter the base”; b
Input “Enter the height”; h
Let T = 1/2 * b * h
Print “The area of triangle=”; T
End
- Formula: area = ½ × base × height.
- Calculating statement: Let T = 1/2 * b * h.
- Sample run: base 6 and height 4 give an area of 12.
Example 5: Area of a circle
Write a program to find the area of a circle.
Cls
Input “Enter the radius “; R
Let C = 22/7 * R^2
Print “The area of circle =”; C
End
- Formula: area = πr², with π taken as 22/7.
- Calculating statement: Let C = 22/7 * R^2.
- Sample run: radius 7 gives an area of 154.
Example 6: Circumference of a circle
Write a program to find the circumference of a circle.
Cls
Input “Enter the radius “; R
Let Circumference = 22/7 * R * 2
Print “The circumference of circle =”; Circumference
End
- Formula: circumference = 2πr, with π taken as 22/7.
- Calculating statement: Let Circumference = 22/7 * R * 2.
- Sample run: radius 7 gives a circumference of 44.
Example 7: Area of a square
Write a program to find the area of a square.
Cls
Input “Enter the number”; n
Let square = n^2
Print “The area of square=”; square
End
- Formula: area = side × side, written as n^2.
- Input: the number entered is the length of one side.
- Sample run: a side of 5 gives an area of 25.
Example 8: Area of a square and volume of a cube
Write a program to find the area of a square and the volume of a cube.
Cls
Input “Enter the number”; n
Let square = n^2
Let Cube = n^3
Print “The area of square=”; square
Print “The volume of cube=”; Cube
End
- Square: n^2 means n multiplied by itself.
- Cube: n^3 means n multiplied by itself three times.
- Sample run: n = 3 gives a square of 9 and a cube of 27.
What are the formulas used in the examples?
Each program turns a mathematical formula into a Let statement.
| Shape | Formula | BASIC statement |
|---|---|---|
| Rectangle | l × b | Let A = l * b |
| Triangle | ½ × b × h | Let T = 1/2 * b * h |
| Circle (area) | πr² | Let C = 22/7 * R^2 |
| Circle (circumference) | 2πr | Let Circumference = 22/7 * R * 2 |
| Square | n² | Let square = n^2 |
| Cube (volume) | n³ | Let Cube = n^3 |
Evaluation
- Write a program to enter your name and print it.
- Which statement in Example 3 calculates the area of the rectangle?
- Write the statement used in Example 5 to calculate the area of a circle.
- Write a program to find the square and cube of a number.
Assignment
- Write a program to enter your name, class and age and print them.
- Write a program to enter the radius of a circle and print its area and its circumference.
This term's Computer Studies topics
JSS2 Second Term · 6 topics
Get Computer Studies as PDF and Word
Every week of JSS2 Computer Studies, Second Term, formatted and ready to print. Ad-free, and the copy lock comes off.
Get this term Card, bank transfer, USSD or OPay

