Program Implementation
Program Implementation
Implementation
Generations of programming languages
Translator programs
Programming errors
Information Technology
5th Form Handout
Contents
1. What is a program ……………………………………………………………………………………………………………………..3
2. Categories of programming language………………………………………………………………………………………….3
3. 1GL……………………………………………………………………………………………………………………………………………..4
4. 2GL……………………………………………………………………………………………………………………………………….…4-5
5. 3GL………………………………………………………………………………………………………………………………………….5-6
6. 4GL…………………………………………………………………………………………………………………………………………….6
7. 5GL…………………………………………………………………………………………………………………………………………….7
8. What are translator programs......................................................................................................8
9. What is a compiler?......................................................................................................................8
10. The steps of programming implementation.................................................................................9
11. Source code creation....................................................................................................................9
12. Compilation..................................................................................................................................9
13. Linking.........................................................................................................................................10
14. Execution....................................................................................................................................10
15. Maintenance..............................................................................................................................10
16. Illustration of a compiler............................................................................................................11
17. What is a “Programming Error”?...............................................................................................12
18. Types of Programming Errors.....................................................................................................12
19. The Syntax Error....................................................................................................................12-13
20. Logic Error..................................................................................................................................13
21. Runtime Error………………………………………………………………………………………………………………………….13
22. Error Finding and Recognition....................................................................................................14
23. Debugging……………………………………………………………………………………………………………………………….14
24. Testing…………………………………………………………………………………………………………………………………….15
25. Test Cases...................................................................................................................................15
26. Dry Run Testing..........................................................................................................................15
27. Activity.......................................................................................................................................16
28. Bibliography…………………………………………………………………………………………………………………………….17
2|Page
What is a program?
A computer program is a set of instructions that tell a computer what to do and how to perform a task.
Programming languages
Programming languages, like human languages, consist of a grammar and a set of rules that
govern how elements of the grammar combine to form instructions.
The set of rules is called the syntax and must be strictly followed for programming instructions
to be valid.
High-Level Language – These languages are machine independent. That is, programs written on
one computer can generally be used on another similar computer. They also use keywords
similar to English and are easier to write.
Example:
o Third generation language
o Fourth generation language
o Fifth generation language
3|Page
First Generation Languages (1GL)
First generation languages which is also called Machine Language, consists of strings made up of 1s
and 0s. Each machine language instruction is made up of two parts, the operation code and the
operand. The operation code is the operation to be performed such as addition or multiplication 2 and
the operand is the data or memory storage area on which the operation is to be performed.
Example:
11011101 1011011
01001100 1011100
11011100 1011011
Advantages of 1GL
Fastest to execute because it is already in the language that the computer understands.
Uses the processor and memory more efficiently
Disadvantages of 1GL
Difficult to decipher
Machine dependent
Time consuming/ tedious to write
4|Page
Advantages of 2GL
Disadvantages of 2GL
Machine dependent
Requires translation
Language Example
5|Page
Advantages of 3GL
It uses English words and symbols, and is therefore even easier to write.
It is machine independent.
Disadvantages of 3GL
Examples:
SQL code:
USE STOCKLIST
6|Page
Fifth Generation Programming Languages 5GL
A Fifth Generation Language is programming using a visual or graphical development interface to create
source languages that are usually compiled with a 4GL language compiler. 5GLs are designed to build
specific programs that help the computer solve specific problems. They are essentially 4GLs with a
knowledge base. 5GLs are often used in Artificial Intelligence (AI)
Examples:
7|Page
What is a Translator program?
A translator program is a software that converts source code into an object code.
Examples:
Assembler
Interpreter
Compiler
What is a “Compiler”?
A compiler is a translator program that translates high level programming languages to machine
language. The compiler converts the entire source code to an object code which is saved as a separate
copy from the source code. Compilers are used on languages such as C, C++ and Pascal.
What is an Interpreter?
An Interpreter is a translator program that converts source code to object line by line. The object code
created is not stored, hence the need for constant translation. Interpreters are used on languages such
as JavaScript and BASIC.
What is an Assembler?
An Assembler is a translator program that converts assembly language/code to an object code/machine
language.
8|Page
The Steps of Programming Implementation
There are several steps that must be completed before a program can be put in use by a user.
2. Compilation
3. Linking
4. Execution
After successful execution of a program, the user is able to use the program to complete the task(s) it
was created for. However, program implementation also has a last phase which takes place over the
lifetime use of the program. This phase is called:
5. Maintenance
Before a program can be ran or placed into production, it must be written or planned. The goal or
outcome of the program must be known and the written step by step procedures to achieve the goal
must be documented. This can be done by writing the steps on paper.
The procedures must then be converted into the syntax of a suitable programming language. This
“typed up” version of the code or procedures is known as the SOURCE CODE.
2. Compilation
In this phase, the compiler scans the source code for syntax errors. If there is no error, the code is either
made into an executable file. The end result of this phase is called object code.
The executable file is the source code converted to its machine language equivalent.
Note: Sometimes linking has to take place before the object code is created.
9|Page
3. Linking
Linking is a process that takes place when more than one object code is needed in order to create an
executable code.
The linker is responsible for this task. It creates a link among object codes after the completion of the
compilation phase.
4. Execution
In the execution phase, the program is seen in a console (e.g. DOS Window) or as an application.
Instructions written in the program are carried out by the operating system.
At this stage, errors such as logic and run time errors may be found.
Run Time Error: Fault within the program that may cause the program to crash (malfunction).
Logic Errors: Errors in the output received from the program due to errors in the sequence of
calculations or lines of code.
5. Maintenance
A program or application sometimes requires maintenance after it is placed into production (in use). In
this phase, sections (modules) in the program may be deleted, corrected or added in order to please the
users’ needs. This is a continuous process due to the fact that requirements change.
10 | P a g e
Illustration of a compiler
11 | P a g e
What is a “Programming Error”?
A programming error is a fault that occurs during program compilation and or execution. These errors
either cause programs to crash (stop) or produce the incorrect result(s).
Syntax Errors
Syntax, according to Dictionary.com, is “the grammatical rules and structural patterns governing the
ordered use of appropriate words and symbols for issuing commands, writing code, etc., in a particular
software application or programming language”
In shorter terms, syntax can be defined as the rules of a programming language which must be obeyed
in order to have a successfully ran program.
Syntax errors are the most common errors in programming and are mostly caused by simple mistakes.
In Pascal, failure to end each line of code with a semicolon will result in syntax errors.
Missing keywords
No declaration of variables
12 | P a g e
E.g.
1. The single quotation mark is missing from the on-screen prompt statement.
Logic Error
Logic errors occur when simple errors are made by a programmer; the flow or sequence of the program
leads to incorrect results.
Most logic errors occur in mathematical operations where incorrect symbols are used in calculations.
E.g. The following is a line from a Pascal program which is to calculate the sum of 3 numbers.
Sum := (num1*num2+num3);
Note: There is no syntax error in the line of code. However, the sum of three numbers is calculated by
adding each number. In the example above, the multiplication sign was used instead of the plus sign.
Runtime Error
As the name suggests, runtime errors occur while a program is being executed. These error s are
sometimes cause by the input received from the user, lack of memory space on the computer or a
popular calculation of trying to divide a number by zero. These errors are the most difficult errors to
trace because sometimes, the exact cause may not be visible.
E.g. Value:=30/0; OR
int age = “name” An integer variable can only store integer values and not data of other data-
types.
13 | P a g e
Error Finding and Recognition
There are two ways in which a programmer can locate errors within his or her programs.
1. Debugging Techniques
2. Testing Techniques
Debugging
2. Diagnosis
3. Correction
Detection deals with the process of finding where the errors are located within the source code of the
program; diagnosis tries to determine the cause of the error. After these two steps are completed,
correction can take place.
Several tools and techniques can be used to carry out the debugging process.
Variable Checks – Displays the value of variables at different points within the program.
Step Mode – The program is executed line by line until the error occurs.
14 | P a g e
Testing
Testing is the process of using data within a program to ascertain whether or not the correct result is
received.
This technique uses “test data” or “test cases” which are entered into the program while it is being
executed.
Test Cases
Test cases are documents that are used to store information such as the input data, expected results of
the program, the actual results received after entering the data and necessary comments.
Test case/ data must be written to test all the modules (sections) of a program to ensure that the
correct output is received at all times.
“Dry Run” is the term used to describe the checking of a program for errors without the use of a
computer or compiler.
Dry run testing is a technique used by many programmers. This technique involves the use of trace
tables, algorithms and pseudo-codes. The programmer “runs” through the program, jotting the results
down on paper. This is done before any coding starts (with a programming language).
NOTE:
The difference between testing and debugging is that testing uses test cases to find out if errors exist
while debugging tries to locate errors which exist and work on correcting such errors.
15 | P a g e
Activity
a. The following Pascal code contains errors. Circle all the errors found and place them in their
correct categories (syntax, logic or runtime errors) in the table below.
Program AreaOfSquare
Uses wincrt;
Begin
Num:= 0 ;
Readln (side);
Area := side+side/Num;
End
b. Given the test data below, what is the actual result and comment for the program above?
16 | P a g e
Bibliography
http://www.Dictionary.com
17 | P a g e