TOPIC 3: PROGRAMMING
TOOLS AND TECHNIQUES
Topic 3.1.
Problem-Solving Techniques
Computer languages may be classified as being
either low-level or high-level language:
LOW-LEVEL LANGUAGES
The characteristics of low-level languages are:
- They are machine oriented; an assembly language
program written for one machine will not work on any other machine using a
different processor chip or architecture.
- Each assembly language statement generally
translates into one machine code instruction. Hence, programming is a lengthy
and time-consuming business.
- Example is assembly language.
HIGH-LEVEL LANGUAGES
The characteristics of high-level languages are:
- They are not machine oriented; they are portable
which means that a program written for one machine can be re-compiled and run
on a different type of machine.
- They are problem oriented; many different
high-level languages have statements and data structures which make them well
suited to a particular class of problem, for example scientific or engineering
problems, business problems, computer-aided manufacture and robotics, etc.
- Statements in high-level language resemble
mathematical equations or English statements and tend to be easier to learn
and faster to code than assembly language programs.
- Each statement in a high-level language
generally translates into several machine code statements.
- Examples are PASCAL, BASIC, C, FORTRAN etc.
SELECTING A PROGRAMMING LANGUAGE
When a program or complete suite of programs needs
to be written for a particular problem, selection of the language may be based
on:
- which language has special facilities most
appropriate to the problem;
- whether a choice of a particular language would
substantially reduce development time;
- whether the programmers have the time or
expertise to master a new language;
- whether a suitable compiler exists for the
hardware the firm intends to use.
A PASCAL PROGRAM (TPW)
As a first example, consider a program that
calculates an electricity bill. The standing charge is £7.41 per quarter, and
the unit rate is 6.5 pence per unit. The number of units used this quarter is
1200.
|
program elec; {a program to
calculate electricity bills}
var
standing_charge : real; { the fixed quarterly charge }
unit_rate : real;
units_used :
integer;
total_bill :
real;
begin
standing_charge := 7.41;
unit_rate :=
0.065; {converted to £}
units_used
:= 1200;
total_bill
:= standing_charge + (unit_rate * units_used);
writeln('Total amoung payable', total_bill)
end. |
THE PARTS OF A PROGRAM
The Pascal program shown above consists of 3 parts:
STEP 1. the Program heading, consisting of the word
program and a program name of our choice.
STEP 2. A declaration of each item of data to be
used by the program.
STEP 3. A sequence of actions (statement) enclosed
between the words begin and end.
- Certain words in the program have been written
in boldface type to show that these are reserved words, or keywords.
- They are part of the Pascal language and can
only be used for the purpose defined by the rules of the language.
COMMENTS
The comment may occur anywhere in the program and
is enclosed in curly brackets { }, or alternatively (* *) may be used. Comments
are ignored by the compiler.
VARIABLE DECLARATION
- This section of the program is headed var
which stands for variable.
- All the data items used, read in or calculated
by the program must be declared in this section.
- Each data item has a name called an identifier.
THE STATEMENT OF THE PROGRAM
- The part of the program where the actual work is
done is enclosed between the keywords begin and end.
RESOURCE:
P M Heatcote, [A Level Computing, 3rd
Edition], Ashford Colour Press Ltd, 1996.