CIT 302 COMPUTER PROGRAMMING
CIT 302 COMPUTER PROGRAMMING
Structured programming gives room for well-thought-out program logic and provides an
attempt to keep programs as simple and straight forward as possible. Also structured
programming
i. increases programmer productivity
ii. increases program clarity by reducing complexity
iii. reduces program testing time
iv. reduces program maintenance time and effort.
i. Sequence Structure: In sequential structure or what you can also call sequential logic,
the steps are executed one after another as serial operations. This can be illustrated by the
following flowchart:
Process A
Process B
Process C
Looking at the above flowchart, there are two arrows, one at the at the bottom the last process
box. They respectively represent the ENTRY and EXIT points of the program segment. It is
good to state basic guideline of structured programming is that each module should have only
one entry point and one exit point. For this reason, a program that has only one entry and one
exit is called a proper program.
1
i. Multiple Alternation.
Condition True
Process
False
In the above flowchart, if the condition is satisfied, then the instruction(s) in the Process box
(or what is also called ACTION BLOCK) is/are executed. If the condition is not satisfied, the
control transfers to the next instruction following the checking of the condition.
Double Alternation:
The structure is illustrated below:
False True
Condition
ELSE THEN
process process
Exercise 1:
Construct the pseudocode for the above structure.
Answer
IF condition THEN
Action — block – 1
ELSE
Action block — 2
ENDIF
2
Where action block 1 constitutes the THEN process and action-block-2 represents the ELSE
process.
Multiple Alternation:
The structure is seen in the following flowchart using three conditions:
True THEN
Condition - 1 PROCESS - 1
False
True THEN
Condition - 2
PROCESS - 2
False
True THEN
Condition - 3
PROCESS - 3
False
THEN
Condition - 4
PROCESS - 4
False
ELSE Process
Looking at the above flowchart, you will see that if none of the four conditions is satisfied,
then the process in the ELSE box will be executed.
3
in a single file. The variables and functions in a module are usually related to one another in
some way. Examples of modular programming languages are object-oriented programming
languages like Java, C++, etc.
While defensive programming is an approach in which the programming assumes that there
may be undetected faults or inconsistencies in a code. In defensive programming, it is
recommended that plausibility checks must be carried out (defensive programming). The
methods for defensive programming include data control, (type, field limits, plausibility checks
etc).
3. keep your code as simply as possible because complexity breeds bugs. Functions should
be viewed as a contract between the user and the coder. The coder guarantees that the function
will execute only a specific task and if it cannot do that task (divide by zero), it can notify the
calling function that error has occurred.
4.0 Object Orientation re-visited, Java IDE (Creating, Saving and Opening of
Program Files)