Program coding is the step, which translates the logic of the program
based on the pseudo-code (algorithm) or flowcharts into a higher
level programming language using the syntax and semantics of the
specific language. The steps includes:
1.
Determine the appropriate programming langauge to use.
2.
Code the program into the specific programming language
decided on.
Program Testing consists of desk checking, debugging and running
real data to make sure that the works. Desk checking is just
reading through or checking the program manually to ensure it is
free from errors and logic works. Debugging means detecting,
locating and removing errors in computer program. Errors may be
syntax errors and logic errors.
Syntax errors can be
typographical error or incorrect format of the statement used.
Logical error are caused by incorrect use of control structures.
3.
FLOWCHART SYMBOLS
TYPES OF FLOWCHARTS
1.
System flowchart indicates a flowchart for targeted system as a
whole
2.
Program flowchart - used to describe processing based on detailed
analysis.
FLOWCHART DEVELOPMENT
The steps that comprise a flowchart must be organized in an orderly,
understandable and clear manner so that the program that
implements this flowchart is similarly in an orderly, understandable
and clear manner.
An orderly, understandable and clear solution is called Structured
Flowchart. Structured flowchart are designed using the three most
basic methods of control. The basic methods will produces correct
structured flowchart necessary to prepare a correct program.
1. SEQUENTIAL steps are performed in a strictly sequential manner,
each step being executed exactly once. This is the simplest method
of control. Easy to develop and understand.
ALGORITHM SUM
SUM = 0
INPUT A, B
SUM = A + B
OUTPUT SUM
END SUM
ALGORITHM PRODUCT
PRODUCT
0
INPUT A, B, C
PRODUCT
A*B*C
OUTPUT PRODUCT
END PRODUCT
ALGORITHM POS_NEG
INPUT N
IF N < 0 THEN
OUTPUT NEGATIVE
END IF
IF N = 0 THEN
OUTPUT INVALID
ELSE
OUTPUT POSITIVE
END IF
END POS_NEG
ALGORITHM PASS_FAIL
INPUT AVE
IF AVE <75 THEN
OUTPUT FAILING
ELSE
OUTPUT PASSING
END IF
END PASS_FAIL
Figure 1-11 Algorithm that will print Odd numbers from 0-10
ALGORITHM ODD
N
0
OD
0
REPEAT
N
N+1
OD N Mod 2
IF OD = 1 THEN
PRINT OD
END IF
UNTIL N=10
END ODD
Characteristics of Algorithm
An algorithm is precise. Each step of an algorithm must
specify exactly what is to be taken. Theres no room for
vagueness. Whats more each step has to be given
explicitly. Steps developed are clear. None can be
understood or assumed.
An algorithm is effective. No instruction may be impossible
to carry-out for the person or machine executing the
algorithms.
An algorithm must terminate. It must reach a point where
the task is complete and no more instructions remain to be
executed. The execution of an algorithm must not go on
indefinitely.
An algorithm must be correct. Note that while the three
characteristics just given are necessary for an algorithm to
live up to its guarantee, they are not sufficient. An incorrect
algorithm must possess the first three characteristics, yet
still contain erroneous instructions that prevent it from
accomplishing the task for which it is designed.
Flowcharting problems
Make
Make
CONSTANT
illegal character ,
illegal character blank space
illegal character -
The following are not valid real constant for the reasons stated:
20 either a decimal point or an exponent must be present
61,456.8 illegal character ,
Variables
Example:
Several variables are shown below:
S
Sum sum
Total2
a5
Variable name are not case sensitive, that is upper
and lower case letters are not differentiated.
The following are not valid variable names for the
reason stated:
NO STUD
NO _STUDE
8CTR
CTR1_
MA__LE
Types of Variables
Numeric Variable is a variable that can
contain data or hold numeric constants (or
value) only.
Types of Numeric Variables
Integer Numeric Variable holds only
integer constant
Real Numeric variable holds real constant.
Character Variable is a variable that can
contain character constant.
String Variable is a variable that can contain
or hold string constants (or values) only.
Operator
Purpose
Addition
Subtraction
Multiplication
Division or div
operator
Modulus division
Examples:
10 %
98 %
3
%
1
%
3
10
100
2
=
=
=
=
1
8
3
1
Examples:
Real and integer will yield real value
2.0 +
1
=
3.0
2.0 1
=
1.0
2.0 /
1
=
1.0
2.0 *
1
=
2.0
Division will yield real value.
2.0 /
1.0
=
2.0
2.0 /
1
=
2.0
Integer Division (It truncates the remainder part of the
quotient)
2
/
2
=
1
5
/
2
=
2
a.
b.
c.
6 + 2/2
6 + 1.0
7.0
(3 + 4) * 10 = a.
=
b.
=
c.
(3 + 4) * 10
7 * 10
70
10 * 4 * 2.0 = a.
=
b.
=
c.
10 * 4 * 2.0
40 * 2.0
80.0
Examples of evaluation:
1. 20 / 4 * 9 % 3
=
=
=
=
a.
b.
c.
d.
20 / 4 * 9 % 3
5*9%3
45 % 3
0
2. 5 * 3 / 5 * 10 20 *2
=
=
=
=
=
=
a.
b.
c.
d.
e.
f.
5 * 3 / 5 * 10 20 *2
15 / 5 * 10 20 * 2
3 * 10 20 * 2
30 20 * 2
30 40
-10
3. (15 - 8) + 10 * (11 + 6)
=
a.
=
b.
=
c.
=
d.
-7 + 10 * (11 + 6)
-7 + 10 * 17
-7 + 170
163
Examples of conversion:
1.
2X + XY
= ((2 * X) +( X*Y)) / (3 * X * Y)
3XY
2.
(3 + 4) (8 + 9)
(3 + 4) * (8 + 9)
Boolean Expressions
A Boolean expression is either a relational expression or
logical expression, which yields either a TRUE or FALSE
value. (Since this module is Algorithm based on C
programming language, the equivalent of TRUE is 1 and
FALSE is 0)
Relational Expressions
A relational expression is a Boolean expression consisting
of numeric or string expressions, numeric of string
variables and numeric or string constants, separated by a
relational operator.
Both
Meaning
Greater than
Greater than or equal to
Less than
Less than or equal to
Equal to (in C, equal is ==)
Not equal to (in C, equal is!=)
TRUE
TRUE
FALSE
FALSE
FALSE
FALSE
Logical Expressions
A logical expression is an expression consisting of
one or more relational expressions separated by the
logical operator that yields either TRUE or FALSE.
The general format of a logical expression is as
follows:
The relational expression before the logical operator
is optional only if the logical operator NOT is used.
NOT
AND
OR
To evaluate a logical expression, the so-called truth
table must be noted. Each logical operator has
operator has a corresponding truth table and are as
follows:
=
TRUE
TRUE
FALSE
FALSE
FALSE
OR truth table
True OR True
True OR False
False OR True
False OR False
=
=
=
=
FALSE
TRUE
TRUE
TRUE
FALSE
OR (IT = 2)
OR FALSE
FALSE
TRUE
3. NOT (NAME=JOHN)
NOT FALSE
=
4. NOT
NOT
TRUE
TRUE
Examples of evaluation:
Consider the following variables and its value:
A=1
NAME = "JOANA
CCMIT = 100
1. (A = 1)
OR
(A = 2)
OR
(A = 3)
TRUE
OR
FALSE
OR
False =
TRUE
((A>=50)
(A<=150))
= TRUE
AND NOT((FALSE
AND
= TRUE
AND NOT
(FALSE)
= TRUE
AND TRUE
=
AND
TRUE))
TRUE