3rd Term Notes
3rd Term Notes
BASIC PROGRAMMING
• BASIC CHARACTER SET
• BASIC STATEMENTS
• BASIC ARITHMETIC OPERATORS
BASIC CHARACTER SET
A defined list of symbols or characters recognised by the computer hardware and
software is a character set. BASIC character set refers to all symbols and other
characters that are recognised when writing a BASIC program.
There are three types of characters used in BASIC. These are: alphabetic,
numeric, and special characters.
• ALPHABETIC CHARACTERS: The alphabetic characters used in BASIC are the
standard English alphabet, A through Z.
• NUMERIC CHARACTERS: The numeric characters used in BASIC are the digits 0
through 9.
• SPECIAL CHARACTERS: The following are special characters used in BASIC:
@#$%^&*()_+/-\.;:=‘,><
• OTHER SPECIAL CHARACTERS.—Some special characters are combined to
form other elements in BASIC. The following list shows these combinations:
> = greater than or equal
< = less than or equal <> not equal
** exponentiation
BASIC STATEMENTS
The complete defined instructions which are usually
preceded by line numbers are called BASIC Statements.
BASIC statements include the following: LET, READ, INPUT,
DATA, END, PRINT, GOTO and others. Each of them denotes
special actions to be performed as recognised by a
computer. These words are therefore referred to as
“reserved words”.
• REM—short for REMARK. It is used to give a remark
or comment to a program. It is not executed by the
translator
• LET— called an assignment statement. It is used to
assign a value to a variable.
• PRINT—it is output statement used to print out the
results of programs.
BASIC STATEMENTS
• READ and DATA— These two statements are used together
when several data are required to run a program. The READ
statement states the variables while the DATA statement assigns
values to these variables.
• GO TO—changes the sequence order of a program.
• INPUT—tells the computer that information is needed to be
typed into the terminal for interaction with the program.
• CLS— an abbreviation for Clear Screen. It is used to clear the
computer screen or monitor.
• END—used to terminate or end a BASIC program.
STATEMENT NUMBER: (Referred to as Line number). This number
has two vital functions: (1) to identify the statement itself and
(2) to indicate to the BASIC (interpreter) where you want this
statement placed in the program sequence.
BASIC OPERATORS
An operator shows the types of operation to be carried out on a
number or an expression. They are symbols used in carrying out
operations in any program in a programming language. BASIC
operators are:
• Arithmetic operators: +,-,/,*,**, %
• String operator: The “+” sign
• Relational operators: <,>,=,<=,>=,<>
• Logical operators: AND, OR, NOT
Arithmetic operators
They are mathematical symbols used in BASIC programming
language to indicate the particular arithmetic operation to be
performed on any numbers that exist in an arithmetic
expression. The symbols with their operations are as follows:
Kinds of Operators
A unary operator has one operand.
A binary operator has two operands.
A ternary operator has three operands.
BASIC NOTATIONS FOR ARITHMETIC EXPRESSIONS
An arithmetic expression is an expression that results
in a numeric value. It consists of operators, operands,
parentheses. It is an expression that can be formed by
connecting literals and variables with one of the
arithmetic operators.
Precedence Rule
The operator precedence rules for expression
evaluation define the order in which “adjacent”
operators of different precedence levels are evaluated.
Here is the order:
Hierarchy Rules
Parentheses (...) This is handled first from the innermost
parentheses outward from left to right.
Exponentiation This is perform next, from left to right.
(^)
Mult & Div (* , /) These are performed next in the order they
appear from left to right. They are of equal
standing.
Add & Sub (+ , -) They are performed in the order they appear
from left to right.
Assignment (=) This is the last to be performed in which values
are assigned from right to left.
Convert the following arithmetic expressions to BASIC
equivalents.
Expressions BASIC Equivalent
a) v = u + at V = U + A*T
b) a A = (22/7)*R^2
c) h A= 1/2 *B*H
d) X= (-B-SQR(B^2-4*A*C))/(2*A)
Built-in Functions
A function is a structure that simplifies a complex operation into a
single step. They accept some input value or values and process that
input in a defined manner to produce or “return” an output value.
Operations on array
The following can be performed on array:
• Input on array
• Output on array
• Arithmetic on array
Array programs
DIM a(5)
INPUT "Enter the length of the array"; num
FOR i = 1 TO num
INPUT "Type again"; a(1)
sum = sum + a(1)
NEXT i
PRINT sum
END
Dim NumArray(100)
for i = 1 to 100
NumArray(i) = int(rnd(1)*10) + 1
print NumArray(i);
PRINT " ";
SUM=SUM+NumArray(i)
next i
print SUM
END
Programming Errors
There are basically three types of errors that you must contend with when writing computer
programs: Syntax Error, Runtime Error and Logic Error.
1. Syntax error
A Syntax error is an error resulting from violation of grammatical rules of a language. Examples:
• Misspelt variable and function names
• Missing semicolons
• Improperly matches of parentheses, square brackets, and curly braces
• Incorrect format in selection and loop statements
2. Runtime errors
Runtime errors occur when a program with no syntax errors asks the computer to do something
that the computer is unable to reliably do. Common examples are:
• Trying to divide by a variable that contains a value of zero
• Trying to open a file that doesn't exist
There is no way for the compiler to know about these kinds of errors when the program is
compiled.
3. Logic errors
Logic errors occur when there is a design flaw in your program. Common examples are:
• Multiplying when you should be dividing
• Adding when you should be subtracting
• Opening and using data from the wrong file
• Displaying the wrong message
COMPUTER DATA CONVERSION
Registers are used to quickly accept, store, and transfer data and instructions that
are being used immediately by the CPU, there are various types of Registers that
are used for various purposes.
The following are the various data that are commonly used in
computer data processing. Computer data are necessarily translated
into machine-readable form of binary digits (0,1) before they can be
processed.
Data types are:
• Alphabetic data: this includes labels, letters of the alphabet A-Z, e.g.
Ngozi, Seun. They cannot be used for calculations.
• Numeric data: it consists of numbers or figures 0-9, e.g. 250. They
are used for calculations.
• Alpha-numeric data: this includes the combination of numbers and
alphabets. E.g. A1001, 20km. They cannot be used for calculations.
Others are:
• Audio data:
• Graphic data:
• Visual data
FILE ORGANISATION
Master File:These are files of a fairly permanent nature e.g. customer ledger,
payroll, inventory, etc. A feature to note is the regular updating of these files
to show a current position.
Movement File: Also called transaction file, is made up of various
transactions created from the source documents. This file is used to update
the master file. As soon as it has been used for this purpose it is no longer
required. It therefore have a very short life. E.g. payroll file and sale invoicing
file.
Reference File: A file with a reasonable amount of permanency . Examples of
data used for reference purposes are of price lists, names and addresses.
Criteria for classifying files
The criteria for classifying files include the following:
Nature of content
Organisation method
Storage medium used
1. Nature of content: if there is a regular updating and retrieval,
this will demand a random access such as disk. If the content is
static or rarely changes such as a price list, a sequential
organisation is adequate.
2. Organisation method: if a file is organised such that the files
can be accessed randomly and not sequentially, then it means,
disk media will be used and the file can be classified as a
random file.
3. Storage medium: if the storage medium is tape, the files stored
therein may be organised and retrieved sequentially. If it is a
disk storage, the organisation of storage and retrieval may be
classified as random.
Computer File Handling
The most basic operations that programs can perform on a file are
as follows:
File creation: this is creating the structure of a file and
populating with contents.
Updating: this is when the master record is changed to reflect a
current position.
File copying: duplicating the content of the file and saving it
away from the present filename as a backup.
File viewing: looking up the content of a file without necessarily
retrieving and printing the file.
Opening a file: calling up a file to computer memory for
manipulation, editing, updating and printing.
Closing a file: this is to terminate the association between it and
the program.
File deletion: purging the file and its content when it is no longer
needed from the storage medium.
Creating a sequential file
Recall that a sequential file is one in which the
records are stored in sorted order of one or
more key fields. It provides a straightforward
way to read and write files. The drawback to
sequential files is, not surprisingly, that you only
have sequential access to your data. You access
one line at a time, starting with the first line.
This means if you want to get to the last line in a
sequential file of 23,000 lines, you will have to
read the preceding 22,999 lines.
Steps to creating a sequential file
• Open the file in sequential output mode. To create a file in BASIC, you
must use the OPEN statement. Sequential files have two options to
prepare a file for output:
(i) OUTPUT: If a file does not exist, a new file is created. If a file already
exists, its contents are erased, and the file is then treated as a new file.
(ii) APPEND: If a file does not exist, a new file is created. If a file already
exists, BASIC appends (adds) data at the end of that file.
• Output data to a file. Use WRITE# or PRINT# to write data to a sequential
file.
• Close the file. The CLOSE statement closes a file after the program has
completed all I/O operations.
FILE INSECURITY
File insecurity is a concept that a file is always vulnerable and is
prone to be lost or missing in the computer. Files used in
applications are vital to the running of a system. Any loss or
corruption of data will have serious or fatal implications for the
performance of the application. Delays, loss of business and
possible legal action may result.
File security is a feature of your file system which controls what
users can access which files, and places limitations to what users
can do to various files in the computer.
Effects of file insecurity
• Loss of data
• Overwriting
• File theft
Methods of file security
• Regular backup of files
• Ensure proper file labeling
• Install firewalls and anti-virus software, scan and ensure a
regular update
• Install stabilizer and UPS to avoid hard disk crash
• Entry to the computer room must be physically and
electronically locked with biometric authentication systems
• Use strong password
• Encrypt your files in case someone bypasses your password
protection.
DIFFERENCES BETWEEN COMPUTER FILE AND MANUAL FILE
Computer files are the type of files which are made on computer and are
stored in the form of softcopy while manual files refer to files that are
created and organised by humans in hardcopy using file cabinets, folders.
Computer files are difficult to destroy Manual files can wear out and can be
and can last for a long time. depleted easily by hand.
End of notes
End of term
End of session