Thursday, March 14, 2013

High Level Programming

High Level Programming

High Level Programming


1 Programming examples in this unit are in three different languages.

(a) BASIC-chosen because most candidates know it. The examples should be accepted by most school microcomputers. However, BASIC does not have many of the programming facilities which some syllabuses require.

(b) COMAL-recommended by some examining boards. It allows good program structure.

Most of the BASIC examples given here will run in COMAL with very little alteration.

(c) Pascal-used mainly where COMAL and BASIC are inadequate.

2 The examples should be clear enough even where you are not familiar with the language. If you are not familiar with it, try to write the equivalent piece of program in the language you do know.


Statement A program statement is a single instruction.

Line In some languages, such as BASIC and COMAL, a program is divided up into numbered lines. Each line has a line number and contains one or more statements.

Variable A variable is a quantity named in a program and whose value can change.

Constant A constant is a value that does not change. In a program it mayor may not be given a name.

Identifier An identifier is a name invented by the programmer for some data. An identifier can be a name for a variable, a constant, a file, an array, etc.

Reserved words A reserved word is a name which has some special significance to the compiler or interpreter. The programmer can only use it for its special purpose and cannot use it as an identifier.

Expression An expression is a set of variables, constants and operators (such as +,-,etc.) which is to be evaluated by the computer. An example is set out below.

The following is a line of a BASIC program:


In this line:

100 is a line number.

INPUT NUM is a statement because it is a single instruction.

PRINT 3.1*NUM*NUM + 5 is also a statement.

PRINT and INPUT are reserved words and cannot be used as identifiers.

NUM is a variable because it can have any value which is a number.

NUM is also an identifier as it was chosen by the programmer.

3.1 and 5 are constants.

3.1*NUM*NUM + 5 is an expression which the computer has to work out before the result can be printed.

Assignment An assignment statement is one which gives a variable a value. Usually an expression on the right hand side of the statement is worked out and the result is assigned to a variable on the left of the statement. For example:

1 In BASIC: 100 LET Area = Width· Length

or just: 100 Area = Width* Length

In COMAL: 100 Area: = Width * Length

In Pascal: Area: = Width * Length;


(a) In BASIC the LET is usually optional-you don't have to use it.

(b) Pascal and COMAL use := in assignments, using = on its own only in other situations.

(c) statements in Pascal end with a semi-colon (except the last END statement, which ends with a full stop).


100 Name$ = Forenames$ + Surname$

110 HeightCms= 2.54*(Feet*12+ Inches)