Section Three: Program Implementation
Section Three: Program Implementation
PROGRAM
IMPLEMENTATION task of writing and
modifying instructions
for the computer to
carry out
SECTION THREE
2
1
PROGRAM Summation
VAR
First, Last, Sum,
Temp: integer:
PROGRAMMING LANGUAGES
BEGIN
writeln(Type the first number);
Readln First;
FIRST GENERATION
writeln(Type the last number);
Readln Last;
sum:=0;
SECOND GENERATION (2GL)
IF First > last THEN
BEGIN THIRD GENERATION (3GL)
Temp:= Last;
Last:= First;
First:= Temp; FOURTH GENERATION (4GL)
END
While (Last>First) DO
BEGIN
FIFTH GENERATION (5GL)
Sum := Sum + First;
First:= First + 1;
END
Writeln(The sum is ,Sum);
3
END.
4
MACHINE CODE/
LANGUAGE
FIRST GENERATION A combination of 0s and 1s
that form the instructions for
the Control Unit of the CPU.
MACHINE CODE/ These 0s and 1s are seen as
LANGUAGE electrical signals (off and on).
Low-level Language only
understood by the computer.
5 6
1
ASSEMBLY LANGUAGE
SECOND GENERATION A program which uses symbols to
represent machine instructions.
For example
ASSEMBLY LANGUAGE LDN 25 means
to put the value 25 in the register
(memory) of the CPU.
7 8
9 10
THIRD GENERATION
LANGUAGE ALGORITHMN
12
11
2
Grade Assignment Algorithm
1. Read Homework, Tests, and Exam. SOURCE CODE
VAR
COMPILER
homework, tests, exam,
Average: real;
Grade: char; a program which changes
BEGIN
write(Enter homework, test and exam scores); the source code of high-
high-
readln(homework, tests, exam);
Average:=0.2*homework+0.5*tests+0.3*exams; level language to
IF Average >= 60 THEN
Grade := P
machine code so that the
ELSE
Grade := F;
computer can understand
writeln(Average = ,Average:5:1, Grade= ,Grade) it and execute it
END.
15 16
17 18
3
READ
PROGRAMMING
STATEMENTS This statement allows users
to enter data into the
computer or the program to
accept data from users
(eg) read
readln
19 20
WRITE IF -THEN
24
23
4
FOR LOOP
REPEATING STATEMENTS
These statements instruct the computer Instructs the computer to
to repeat specific actions while a repeat an action for a certain
condition is TRUE.
number of times.
The computer stops performing the
actions once the condition becomes (eg) FOR i:=1 TO 10 DO
FALSE.
These statements are also known as
writeln i:
LOOPS
(eg) FOR and WHILE statements 25
26
MATHEMATICAL
DATA TYPES
OPERATORS
- SUBTRACT Variables can be
+ ADDITION INTEGER (eg) 2, 23, 11
* MULTIPLICATION REAL real number (eg) 3.75
/ DIVISION CHAR character (eg) A, B
^ POWER BOOLEAN true or false
STRING group of text (eg)
williams
29 30
5
LOADING
PROGRAMMING The movement of a program
from disk to the computers
TERMS main memory.
31 32
OBJECT CODE
The code produced by a
SOURCE OBJECT
compiler from the source code, CODE COMPILER
CODE
usually in the form of machine
language that a computer can
execute directly, or sometimes
in assembly language.
33 34
EXECUTING INTERPRETING
The carrying out of the A program which converts a program
written in a high-level language to
instructions of a program by
machine language.
the computers CPU As each instruction is encountered, it
is converted to machine code and
executed at the same time.
35 36
6
COMPILING DRY RUN
A program which converts a program To execute a program by hand,
written in a high-level language to writing values of
machine language. variables and other data results on
The entire program is first paper, in order to check its operation
converted to machine code, then this or to track down a bug( an error
code is executed. found in the program).
37 38
39 40
41
7
A TRACE TABLE is a table of
values given to variables of a
TRACE TABLES
program where the changes on
each value is shown for each
line of the program code.
43 44
PROGRAM Summation
VAR
First, Last, Sum,
Temp: integer:
BEGIN
writeln(Type the first number);
Readln First;
writeln(Type the last number);
First, Last, Sum,
Readln Last;
sum:=0;
IF First > last THEN Temp: integer:
BEGIN
Temp:= Last;
Last:= First;
First:= Temp;
END
While (Last>First) DO
BEGIN
Sum := Sum + First;
First:= First + 1;
END
Writeln(The sum is ,Sum);
45 46
END.
PROGRAM Summation
VAR
First, Last, Sum,
Temp: integer:
BEGIN
First Last Sum Temp writeln(Type the first number);
Readln First;
writeln(Type the last number);
Readln Last;
sum:=0;
IF First > last THEN
BEGIN
Temp:= Last;
Last:= First;
First:= Temp;
END
While (Last>First) DO
BEGIN
Sum := Sum + First;
First:= First + 1;
END
Writeln(The sum is ,Sum);
48
47 END.
8
writeln(Type the first number); First Last Sum Temp
Readln First; 10 5 0
writeln(Type the last number);
Readln Last;
sum:=0;
49
50
PROGRAM Summation
VAR
First, Last, Sum,
Temp: integer:
BEGIN
writeln(Type the first number); IF First > last THEN
Readln First;
writeln(Type the last number); BEGIN
Readln Last;
sum:=0;
IF First > last THEN
Temp:= Last;
BEGIN
Temp:= Last;
Last:= First;
Last:= First;
First:= Temp;
First:= Temp;
END
While (Last>First) DO
BEGIN
Sum := Sum + First;
First:= First + 1;
END
Writeln(The sum is ,Sum);
51 52
END.
PROGRAM Summation
VAR
First, Last, Sum,
Temp: integer:
BEGIN
First Last Sum Temp writeln(Type the first number);
Readln First;
writeln(Type the last number);
10 5 0 Readln Last;
sum:=0;
IF First > last THEN
BEGIN
Temp:= Last;
Last:= First;
5 10 0 5 END
First:= Temp;
While (Last>First) DO
BEGIN
Sum := Sum + First;
First:= First + 1;
END
Writeln(The sum is ,Sum);
54
53 END.
9
First Last Sum Temp
10 5 0
While (Last>First) DO
5 10 0 5
BEGIN 6 10 5 5
Sum := Sum + First; 7 10 11 5
First:= First + 1; 8 10 18 5
END 9 10 26 5
10 10 35 5
55 11 10 45 5 56
PROGRAM Summation
VAR
First, Last, Sum,
Temp: integer:
BEGIN
writeln(Type the first number);
Readln First;
writeln(Type the last number);
Readln Last;
sum:=0;
IF First > last THEN
BEGIN
Temp:= Last;
Last:= First;
First:= Temp;
END
While (Last>First) DO
BEGIN
Sum := Sum + First;
First:= First + 1;
END
Writeln(The sum is ,Sum);
57
END.
10