Section 8 - Program Implementation
Section 8 - Program Implementation
INFORMATION TECHNOLOGY
Unit 1: Computer Unit 8: Program Implementation
Fundamentals
High-level languages
• These are languages that are machine independent.
• They are not specifically written for any one brand of computer.
• The program code written on a particular machine is not limited to execution on that machine only
but can also run on other similar machines.
• Examples of high-level languages are Pascal, BASIC, C, etc.
www.caribbeanonlineacademy.com
1
2/13/2025
www.caribbeanonlineacademy.com
2
2/13/2025
• A compiled object program is not executable by itself. It needs to be combined with other
system modules to form an executable image that can be loaded into memory.
• The process of linking the module is done by a link editor or link-loader.
• The resulting executable module is then loaded into memory where it can then be executed.
www.caribbeanonlineacademy.com
prematurely.
www.caribbeanonlineacademy.com
3
2/13/2025
www.caribbeanonlineacademy.com
Advantages
• It translates one instruction at a time, therefore it uses a minimum amount of the
computer’s memory
• It is also helpful in the debugging process, as the interpreter can relate error
Disadvantage
• The interpreter takes longer to run a program as time is spent interpreting the source code every
time the program needs to be run.
www.caribbeanonlineacademy.com
4
2/13/2025
Advantage
• It can be executed faster than when using an interpreter, as the object codes are saved and can
be run at any time
Disadvantage
• As the entire program is translated to object code, it uses much more of the computer’s
memory.
www.caribbeanonlineacademy.com
• Testing - a completed program must be tested for errors to prevent crashing or stalling.
• The programmer must make sure the program works for any correct input data that the
user gives it.
• The testing phase is to detect any problems in the program.
• Dry runs and computer testing could reduce the chance of error, before releasing the
program to its final users.
www.caribbeanonlineacademy.com
5
2/13/2025
www.caribbeanonlineacademy.com
Types of errors
During program development, three types of errors may be encountered as followed:
1. Logic errors
2. Syntax errors
3. Run-time errors
1. Logic errors – arise when the sequence of the instructions is not correct and there are flawed comparisons
and selection statements.
For example, let’s suppose we wanted to print the names of all girls who are under the age of 18 and we
wrote the following program:
If (gender = F) and (age <= 18) then
Writeln(name);
• This code would result in the printing of the names of girls who are 18 as well as those who are under 18.
• This is because in the if statement, we used <= instead of = .
• This is a common error in the logic that will give undesirable results.
www.caribbeanonlineacademy.com
6
2/13/2025
Types of errors
2. Syntax errors – occur when the source code has not been written in accordance with the rules of the
programming language.
• For example, if we omit to terminate an assignment statement with a semicolon.
• The following statement would result in a syntax error during compilation:
total:=total + X
or if we used a reserved word incorrectly, such as in: var := a + b;
• Syntax errors can be easily located and corrected as the compiler usually issue messages which identify
the location and cause of the errors.
www.caribbeanonlineacademy.com
Types of errors
3. Run-time errors – are generated during execution of the program.
• They result when the processor encounters an instruction that violates the processing rules.
• Number:=1;
• Number:= Number - 1;
• Answer := total/Number; {illegal}
• The last statement would generate a run-time error as an attempt is being made to divide by a value
of 0.
www.caribbeanonlineacademy.com
7
2/13/2025
Program
body End.
www.caribbeanonlineacademy.com
www.caribbeanonlineacademy.com
8
2/13/2025
www.caribbeanonlineacademy.com
www.caribbeanonlineacademy.com
9
2/13/2025
• Punctuation
• Every Pascal statement (except begin) is terminated by a semi-colon.
• The last statement in the program (that is the end statement) is terminated by a period (full stop).
www.caribbeanonlineacademy.com
www.caribbeanonlineacademy.com
10
2/13/2025
Precedence of operators
• Same as in Math; multiplication and division before addition and subtraction.
• When two operators have the same precedence evaluate from left to right unless specified
otherwise by brackets.
www.caribbeanonlineacademy.com
www.caribbeanonlineacademy.com
11
2/13/2025
www.caribbeanonlineacademy.com
• The computer expects that and integer would be entered first and a decimal number next.
• Read and readln differ in where the data pointer is place after a data item is read.
• The read command places the pointer in the space just after the data item whereas readln places
the data pointer on a new line.
• Therefore be careful how readln is used.
www.caribbeanonlineacademy.com
12
2/13/2025
www.caribbeanonlineacademy.com
www.caribbeanonlineacademy.com
13
2/13/2025
www.caribbeanonlineacademy.com
Loops
• The group of statements/instructions to be repeated is called a loop. There are two (2) types:
1. A finite loop – where the number of times a repetition is to be made is known.
2. An infinite loop – where the instructions are repeated an unspecified number of times.
www.caribbeanonlineacademy.com
14
2/13/2025
WHILE loop
• This construct is used when you do not know beforehand how many times a statement within a
block needs to be repeated.
• In this loop the computer executes the instruction to be repeated for as long as a given condition is
TRUE.
• It checks the conditions first and will loop while the condition is true and ends when it is false.
www.caribbeanonlineacademy.com
• Syntax:
While (<condition>) Do
Begin
<statement(s) to be carried out if condition is TRUE>;
End;
• Example
Program Read100Nums;
Uses wincrt;
Var number: integer;
Begin
Write(‘Enter a number’);
Read (number);
While( number<=100) Do
Begin
Write(‘Enter a number’);
Read (number);
End;
Write(‘Over the limit’);
www.caribbeanonlineacademy.com
End.
15
2/13/2025
www.caribbeanonlineacademy.com
Program hello5;
Uses wincrt;
Var Count: integer;
Begin
Count := 0;
While (count<5) Do
Begin
Writeln(‘Hello’);
Count:= Count +1;
End;
Readkey;
End.
www.caribbeanonlineacademy.com
16
2/13/2025
FOR < counter variable> :=<start value>To <end value or end variable> Do
<statement to be carried out if condition is TRUE>;
End;
• Example
FOR num := 1 To 5 Do
Writeln(‘Hello’);
End;
www.caribbeanonlineacademy.com
www.caribbeanonlineacademy.com
17
2/13/2025
FOR count := 1 To 5 Do
BEGIN
Sum := count + count;
Writeln(count, ‘ + ’, count, ‘ = ‘,sum;
END;
www.caribbeanonlineacademy.com
FOR < counter variable> :=<start value>DOWNTO <end value or end variable> Do
<statement to be carried out if condition is TRUE>;
End;
• Example
FOR count := 5 DOWNTO 1 Do
Writeln(count);
End;
www.caribbeanonlineacademy.com
18
2/13/2025
FOR <counter variable> :=<start value>To <end value or end variable> Step <increment
value>Do
<statement to be carried out if condition is TRUE>;
End;
• Example
FOR even_No := 2 To 20 STEP 2 Do
Write(even_No);
End;
www.caribbeanonlineacademy.com
19
2/13/2025
• Example:
Problem:
• Write a program to allow a user to enter numbers. When his total crosses 100 display “over the
limit”.
Program overTheLimit;
Uses wincrt;
Var number , Total: Integer;
Begin
Total:=0;
Repeat
Write(‘Enter a number ‘);
Readln( number);
Total := Total + number;
Until (Total >100);
Write(‘Over the limit’);
End.
www.caribbeanonlineacademy.com
Top-Down Design
Top-Down Design
• In TDD, the idea is to design a program by first identifying the major tasks of the program.
• For each task, break it down into smaller subtasks.
• Continue this process until it is clear how each task is to be accomplished.
• Each task that you have identified is a candidate to be a subprogram, with the main program
consisting mostly of calls to the top-level subtasks.
• This approach requires that you have the discipline to plan the structure of your program before
you write any code.
• If you can do it, the process of planning the program will help minimize the number of logical
errors in your program.
• Typically, you'll spend less time planning than you would have spent debugging the code you
didn't plan.
www.caribbeanonlineacademy.com
20
2/13/2025
for variables and recording what takes place after each instruction is executed.
• Computer testing: using the computer to run the program with suitable test data
(correct and incorrect) to deal with all possible kinds of conditions.
• The results generated by the computer are then compared with the expected
solutions.
• If the expected and actual results do not match, then the program has a logic error.
www.caribbeanonlineacademy.com
www.caribbeanonlineacademy.com
21
2/13/2025
www.caribbeanonlineacademy.com
There are dozens of indentation styles that you could adopt, and some general ideas are common to
most of them:
1. The style is applied consistently throughout the program.
2. Code within a block (e.g., inside a loop, or in the body of a subprogram) should be indented.
3. If a block is nested within another block the inner block's body should be indented relative to the
enclosing block.
4. Avoid excessive "stairstep" indentation (such as you often see with groups of nested IF statements)
because this will force you to attempt to squeeze code to fit on just the right half of the
screen/page.
5. If stairstepping becomes a problem, reduce the number of spaces per indentation (from 8 to 4, for
example) or switch to a vertical style temporarily.
www.caribbeanonlineacademy.com
22
2/13/2025
You should strive to give each object a name that gives the reader a strong hint as to the object's
purpose within the program. As with indentation, there are some principles that apply to naming:
1. Use good, meaningful names, but don't go overboard. If you have a variable in your program that
holds the number of hours an employee works in a week, you might call it HOURS, although that
name still leaves a lot of doubt as to the exact contents of the variable. A compromise such as
HOURS_PER_WEEK is a good solution.
2. Many languages now permit you to use underscores as part of names, as shown above. If you can't
use them, you can still improve name readability by mixing the case of the letters in the name. For
example, 'HoursPerWeek' is much easier to read than 'hoursperweek'.
www.caribbeanonlineacademy.com
www.caribbeanonlineacademy.com
23
2/13/2025
www.caribbeanonlineacademy.com
www.caribbeanonlineacademy.com
24
2/13/2025
www.caribbeanonlineacademy.com
www.caribbeanonlineacademy.com
25
2/13/2025
Declarations
const
var
:
Statements
begin
:
end.
www.caribbeanonlineacademy.com
www.caribbeanonlineacademy.com
26
2/13/2025
www.caribbeanonlineacademy.com
27