Chapter 5: PROGRAMMING
Chapter 5: PROGRAMMING
4. People can talk to computers and the voice recognition systems cam
convert spoken sounds into written words, but these systems do not
understand what they are writing; they simply take dictation.
5. Prolog and Mercury are the best known fifth generation languages.
5 Form 5 Lesson Notes Part 1 Program & Programming
STRUCTURED PROGRAMMING
1. Structured programming often uses a top-down design model where
developers map out the overall program structure into separate subsections
from top to bottom.
OBJECT-ORIENTED PROGRAMMING
1. The object-oriented approach refers to a special type of programming
approach that combines data with functions to create objects.
ASSEMBLER
1. An assembler is a computer program for translating assembly language –
essentially, a mnemonic representation of machine language – into
machine language that can be executed by the computer.
2. For example, in Intel 80836, the assembly language for the ‘no operation’
command is NOP and its machine code representation is 10010000.
3. Example of assemblers are MACRO-80 Assembler and Microsoft MASM.
INTERPRETER
1. Interpreter is a program designed to interpret and execute program directly
from its source codes without compiling it first.
2. The source code of an interpreted language is interpreted and executed in
real time when the user executes it.
3. The interpreter will read each code converts it to machine code and
executes it line by line until the end of the program.
4. Examples of interpreter-based language are BASIC, Logo and Smalltalk.
8 Form 5 Lesson Notes Part 1 Program & Programming
COMPILER
1. Compiler is a computer program that translates source code text which is
written in a high level programming language into a lower level language
(e.g. assembly language or machine language) and will create an executed
file.
2. The source code (in text format) will be converted into machine code
which is a file consisting of binary machine code that can be executed on a
computer.
3. If the compiler encounters any errors, it records them in the programming-
listing file.
4. When a user wants to run the program, the object program is loaded into
the memory of the computer and the program instructions begin executing.
5. A compiled code generally runs faster than programs based on interpreted
language.
6. Several programming languages like C++, Pascal and COBOL use
compilers as their translators.
9 Form 5 Lesson Notes Part 1 Program & Programming
1. Microsoft Visual Basic 6.0 was designed to be easy to learn and use.
2. The language not only allows programmers to easily create simple GUI
applications, but also has the flexibility to develop fairly complex
applications as well.
3. Programming in Microsoft Visual Basic 6.0 is a combination of visually
arranging components or controls on a form.
4. Hence a simple program can be created without the programmer having to
write many lines of code.
7. Drag and drop user interface allows you to instantly create an interactive
user interface for your software without dozens of codes.
8. Data access features allow your application to access information from a
database such as a telephone book program.
9. ActiveX technologies allow you to make use of the functionality provided
by other applications.
10. Internet capabilities allow your program to interactively utilize the
Internet.
CONSTANT
1. Constant is a data container that stores information.
2. The value will never change (remain constant) at any time during the
course of a program.
3. Declare is the official term used in programming to announce to the
program the condition of statement in programming.
Const number = 12.5
VARIABLES
1. Variable is a data container that stores information.
2. The value inside may change at any time during the course of a program.
3. Declaring variables :
Dim marks As Integer
Marks = 25
DATA TYPES
O
P ERA
T ORS
CONTROL STRUCTURES
Control structures allow the programmer to control the flow of a program.
13 Form 5 Lesson Notes Part 1 Program & Programming
1. The renter has to pay the rental of RM26 each month. This is the fixed
value. So we call it a constant value.
2. The values that may change are total calls and service tax. They are called
variables.
Constants Variables
BOOLEAN
6. Boolean type consists either a True or False value. Programmers usually
use it to store status.
7. This is how we declare a Boolean type constant in Visual Basic statement:
Const Input_Status = true
3. This is how we declare a Boolean type variable in Visual Basic statement:
Dim Input_Status As Boolean
Input_Status = true
15 Form 5 Lesson Notes Part 1 Program & Programming
MATHEMATICAL OPERATOR
1. Plus : + 2. Minus : –
3. Multiply : * 4. Divide : /
RELATIONAL OPERATOR
1. Equal to : = 2. Greater than : > 3. Less than : <
4. Greater than or equal to : >= 5. Less than or equal to : <=
LOGICAL OPERATOR
1. AND 2. OR
3. NOT
Example :
AND operator
The diagram shows a truth table of AND
operator.
Notice that truth value of X AND Y is True (1)
if only both X and Y are True (1), Else it is
false (0)
OR operator
The diagram shows a truth table of OR
operator.
Notice that truth value of X OR Y is True (1) if
either X or Y are True (1) or both X and Y are
true (1). Else it is false (0).
NOT operator
The diagram shows the truth table of
NOT operator.
NOT X is the negation of X. It is
essentially the 1’s complement
operation.
Notice that truth value of NOT X is
True (1) when X is False (0) and vice versa.
Logical operators perform logical operations such as checking the condition of
two Boolean values.
18 Form 5 Lesson Notes Part 1 Program & Programming
1. Pseudo code is text only sentences that describe the logic and program
flow of a computer program.
2. Pseudo code resembles plain English.
3. It usually does not have any specific programming language syntax and
grammar.
4. Pseudo code is directly linked to the computer codes because each pseudo
code statement can often be converted into the programming language
virtually line by line.
5. There are no set rules for writing pseudo code.
6. A programmer can have his or her personalized pseudo code.
7. He or she must use consistent language and syntax in the pseudo code, so
that he or she can understand it at a later stage.
8. Below is a complete pseudo code from BEGIN to END that illustrates the
following program.
20 Form 5 Lesson Notes Part 1 Program & Programming
1. Control structure is a
structure of
statements in
programming that
allows the
programmer to
control the flow of a
program.
2. Control structure can
be divided into :
(i) sequence control structures
(ii) selection control structures
(iii) repetition control structures
3. We will concentrate on the sequence control structure and selection control
structure.
SEQUENCE CONTROL
In sequence control, the statements
are executed one by one in
consecutive order.
Example :
This program on the left
diagram will request the user’s
24 Form 5 Lesson Notes Part 1 Program & Programming
date of birth and then request today’s date, calculate the age and finally will
print the user’s age.
For example, today’s date is 1-
Jan-2006, then the results will be
shown as follows:
SELECTION CONTROL
There are times when you want your
program to make a decision based on
the situation given.
A program that stores student’s marks
may respond differently to different
marks.
For example, a simple mathematical
program will display its result as odd or
even based on the result.
BEGIN
Request condition
If condition is true Then
give positive response
Else
give negative response
End If
End
Let’s see a pseudo code example for the “If……Then……..Else” statement for
a program that will print “You are too heavy to ride the toy car” if the student’s
weight is more than or equal to 50. Otherwise it will print “you can ride the toy
car”.
BEGIN
Request student’s weight
If student’s weight is more than of equal to 50 kg Then
26 Form 5 Lesson Notes Part 1 Program & Programming
CODING
o Once the flow chart is confirmed, the programmer will perform coding.
DOCUMENTATION PHASE
o After this, the programmer will complete the documentation for the
program; this includes the user manual, a clear layout of the input and
output records and a program listing.
29 Form 5 Lesson Notes Part 1 Program & Programming
1. In this study, the programmer reviews and defines the problems faced by
the school administrators : The school enrolment has increased so much
that it has become very difficult for them to perform student registration
without the help of a computer program or system.
2. The programmer must indicate the purpose of the program before
continuing to the next task : In this case, the purpose of the school
registration program is to computerize the registration of new students.
3. In this situation, the programmer identifies the data input, process and
output for the program :
o First step : The programmer identifiers the data input, for example
student’s name, student’s NRIC, gender, telephone number, date of
birth, parents’ name and address.
o Second step : The programmer identifies the process for the program.
Any new student who enrolls in the school should have all his or her
data keyed into the school’s registration program.
o Third step : The programmer identifies the output for the program. For
example, the student who has been registered will be notified of his or
her class in the coming academic year or term.
LESSON FIFTEEN : PROGRAM DESIGN PHASE
30 Form 5 Lesson Notes Part 1 Program & Programming
model consists of three modules, namely input module, process module and
output module.
Then the programmer writes the pseudo code
for the program based on the top-down design
model.
Next, the programmer draws the flow chart that shows the data flow of the
program.
31 Form 5 Lesson Notes Part 1 Program & Programming
32 Form 5 Lesson Notes Part 1 Program & Programming
programmer will type the programming language code into the computer.
7. There are many different programming languages in the market. Examples
of the popular programming language used in Malaysian secondary school
are Visual Basic and C language.
8. Each of these programming languages has its own particulars syntax.
9. A programming language’s syntax is a set of rules specifying a style of
writing instructions for a solution.
33 Form 5 Lesson Notes Part 1 Program & Programming
SYNTAX ERROR
o A syntax error is caused by wrong spelling in command and declaration.
Other syntax errors include case sensitive, punctuation and wrong word
command.
40 Form 5 Lesson Notes Part 1 Program & Programming
o They either show up as you type the program code, or if you have turned
off the automatic syntax error check, the syntax errors show up when you
try to run or compile the program.
oW
hen
LOGIC ERROR
o If the expected output and actual output do not match for any set of data,
the program has a logic error.
o A logic error is an error in the design that causes inaccurate outputs.
o We can use desk check technique to test logic errors. There are 3 steps to
perform desk checking.
a. First, create a set of test data that includes input and output data.
b. Second, use the test data to test the coding and record the result.
c. Lastly, compare the manual results with the computer generated
results.
42 Form 5 Lesson Notes Part 1 Program & Programming
RUN-TIME ERROR
o Run-time error is an error that occurs while the program is running or
executing.
o A run-time error may cause the program to stop running.
DEBUGING
o The process of locating and correcting of syntax and logic errors in a
program is known as debugging the program.
o The program errors themselves are called bugs. Thus removing the errors
is called debugging.
43 Form 5 Lesson Notes Part 1 Program & Programming
o A project is a set of activities with a fixed start date and end date.
o Some examples of projects are the construction of your school building
and the setting up of your school library.
o Program development is also a project.
o A successful program development project will result in one or more
programs that are error-free, affordable, relevant to the needs of users and
delivered on time.
o All the software that you find so helpful, educational and enjoyable today
is the outcome of successful program development projects.
o For a program development project to succeed, the people involved must
possess the appropriate set of communication, management and technical
skills.
Click Check
55 Form 5 Lesson Notes Part 1 Program & Programming
NATURAL LANGUAGE
o Natural Language programming aims to use natural language such as
English to write a program.
o Instead of using a specific programming language syntax, natural language
programming will use normal English as the input to program software.
56 Form 5 Lesson Notes Part 1 Program & Programming
3D / 2D
57 Form 5 Lesson Notes Part 1 Program & Programming