Skip to content

Example of Basic Programming Language – JSS2 Computer Studies Lesson Note (Second Term)

Download this term · ₦1,000

Lesson 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.

Advertisement

Behavioural objectives

By the end of the lesson, students should be able to:

  1. write a BASIC program that enters and prints a name, city, country and age;
  2. write BASIC programs to find the area of a rectangle, a triangle, a circle and a square;
  3. write a BASIC program to find the circumference of a circle;
  4. write a BASIC program to find the square and cube of a number;
  5. 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
PRINT 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.

Advertisement
  1. Start with CLS to clear the screen.
  2. Use Input to take each value from the user and store it in a variable.
  3. Use Let to calculate the answer from the stored values.
  4. Use Print to display the answer with a short message.
  5. 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

Advertisement
  • 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.

Advertisement

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

  1. Write a program to enter your name and print it.
  2. Which statement in Example 3 calculates the area of the rectangle?
  3. Write the statement used in Example 5 to calculate the area of a circle.
  4. Write a program to find the square and cube of a number.

Assignment

  1. Write a program to enter your name, class and age and print them.
  2. 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

  1. Programming Language and Basic Language
  2. Example of Basic Programming Language
  3. Graphics Packages and Features
  4. Graphics Packages: Paint Environment
  5. ICT as a Transformation Tool
  6. Benefit of ICT Gadget
Downloads

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

Advertisement

Lesson Notes for Other Classes

Print it or edit it in Word

Every note is free to read online. A PDF or Word copy of one subject costs ₦1,000 for one term, or ₦2,000 for all three terms.

Continue with GoogleContinue with Facebook

Sign in first, then choose your class and subject at checkout.