0% found this document useful (0 votes)
3 views8 pages

Ict wk4

This document provides an overview of one-dimensional arrays in BASIC programming, including their definition, advantages, and operations. It explains how to declare arrays using the DIM statement and provides examples of simple BASIC programs that utilize one-dimensional arrays. The document emphasizes the logical grouping of data and the reduction of program coding through the use of arrays.

Uploaded by

geogrjonathan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

Ict wk4

This document provides an overview of one-dimensional arrays in BASIC programming, including their definition, advantages, and operations. It explains how to declare arrays using the DIM statement and provides examples of simple BASIC programs that utilize one-dimensional arrays. The document emphasizes the logical grouping of data and the reduction of program coding through the use of arrays.

Uploaded by

geogrjonathan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

ICT

TOPIC:
BASIC PROGRAMMING III
(ONE DIMENSIONAL ARRAY)
PERFORMANCE OBJECTIVES
At the end of this lesson, students should be able to:
• Definition of Array
• Operations on Array
• Simple BASIC program on one-dimensional array.
DEFINITION
ARRAYS
▪ An array is used to store multiple values in a single variable. To create an array,
use the DIM [Dimension] statement.

▪ The term table is also known as an array. An array variable is a data structure
consisting of an ordered set of elements of the same data type. One advantage of
arrays is that they allow for the logical grouping of data of the same type.
ADVANTAGE OF STORING DATA IN TABLES
• Each item of data does not have a unique variable name.

• Program coding is reduced.

• Direct access to a single item of data is possible.

• The homogeneous nature of data can be classified under one name.


ONE DIMENSIONAL ARRAY
• The smallest component of an array is called a cell or element and contains either
a string literal or a number.

540 50 40 150
The cells are grouped together to form a one –dimensional table.
Cell 3
Cell 1 Cell 4
Cell 2

Each cell is given an address called a subscript, that defines the


position of a cell within the table.The content of each cell is
Contents of cells 40 30 50
accessed by the name given to the table.
Subscript 1 2 3
Thus A(1) = 40;A(2) = 30 etc.
• The declaration of the name and size of the table is made using a DIM statement.

• The declaration of array A is: 10 DIM A (3).


• Where A is the name of the table (3) is the maximum number of cells.

DIM Statement

• Arrays are defined in a DIM statement and the total number of elements of an array
is given in parenthesis. An element of an array is specified by its subscript value.

• DIMension Statement Format: The DIMension statement is used to describe


subscripted variables and to define the length of strings.

• DIMension Statement Form:


• Line Number Statement Parameters
10 DIM A (1)
SIMPLE BASIC PROGRAMS ON ONE – DIMENSIONAL ARRAY

• REM “Create and access array of five strings”


• CLS
• DIM ws$(5)
• LET ws$(1) = “Red Sox”
• LET ws$(2) = “Giants”
• LET ws$(3) = “White Sox”
• LET ws$(4) = “Cubs”
• LET ws$(5) = “Boxes”
• INPUT “Enter a number from 1 to 5: ‘ n
• PRIINT “The “; ws(n) = 5; “won world series number”; n
• END
A program to store names of six football clubs in a table using the
READ and DATA statement
Manchester United Chelsea Arsenal Manchester City Swansea

Solution:
10 REM “Declaring the names of football clubs”
11 DIM QS (5)
12 FOR Y = 1 to 5
13 READ Qs (Y)
14 NEXT Y
15 PRINT DS (Y)
16 DATA “Manchester United”; “Chelsea”; “Arsenal”;
17 DATA “Manchester City”; “Swansea”
18 END

You might also like