Programming Introto Logic
Programming Introto Logic
3.6. PROGRAMMING
3.6.1. Introduction
A program is a set of instructions that furnishes the computer with methods of how to carry out processing.
These programs are an explicit expression of how a computer should execute processing. Programming is
the act of developing the program code. It also involves the depiction, or expression of a problem for
subsequent translation into a computer language. A precise expression of that which is meant to be
executed by a computer in a given context. A logical expression of a problem is usually presented before
stipulation of the solution. Methods have been devised to communicate the various expressions of program
logic. Examples being pseudocode, algorithms, decision trees, decision tables, decision sequences, data
flow diagrams and decision flow diagrams.
These are diagrammatic expressions of the operations or steps in a program. They visually depict the logic,
sequence and flow of programs.
Symbols used
Input/output
Processing /computer
Process flow
On page connectors
Decision
Pre-defined process
2
Begin
‘Input Data’
NO
Condition
met?
YES
Perform Calculation
Display
Results
End
Start
Input details
?
Calculated
labour
Costs
Output labour
Costs
Stop
Sequence
3
Selections
NO YES
?
?
Case condition, action
Repetition
? WHILE
Condition action
END WHILE
These are tabular representation of decision logic. For any given situation a decision table lists all the
conditions (the ‘ifs’) that are possible in making a decision. It also lists the alternative actions (the ‘thens’).
Each unique relationship (if then this condition then take this action) is referred to as a decision rule.
4
Stub Entry
Condition rule
Condition 1 2 3 4 5 6
(Specific Condition)
Action Rule
Action
(Specific action) 1 2 3 4 5 6
a B c d
Credit approved N Y Y Y
Order ≤ stocks available - N Y Y
Order > 500 units - - N Y
Reject Order X
Back –Order X
Fill- Order X X
Give 20% discount X
These depict the actions to be taken amongst given alternatives. They show the path of subsequent
decisions taken to depict the logic of flow of a program or system that has conditional events.
Conditions Actions
Order ≥10,000
Order
Placed
Card balance Commit trans
Sufficient
3.6.6. Algorithms
Algorithms are the textual description of program logic. They are designed to enable conversion into actual
program code easy and understandable. A good algorithm is easy to follow but brief.
2. Calculate
T1 + T 2 + T 3
Total test = × ( 0 .2 )
3
3. Calculate
Q1 + Q 2 + Q3
Total Quiz = × ( 0 .2 )
3
4. Calculate
Exam total = Exam x 0.6
5. Calculate
Final Result = Exam Total + Total Quiz + Total Test
6. IF Final Result >49
Assign Comment = ‘Pass’
ELSE
Assign Comment = ‘fail’
7. Display {Print result to screen}
Final Result, Comment!
8. Stop
[Input : Service charge, unit cost, number of installations, yards of cables used.
Purpose : Algorithm to calculate the revenue generated by the installation of a certain number of
yards of cable at a number of locations. For each installation there is a fixed basic service
charge and an additional charge for each foot of cable.
4 Display Revenue
5 Stop.
6
1. A publisher produces short books on topics in computing. These are published in two page sizes,
A4 and A5; they are also available in paperback or hardback. The selling price will depend on
these two factors and the expected sale. The A4 size books cost K5, 000 more than the
corresponding A5 book. The hardback copy costs K7, 000 more than a paperback copy. The
selling price of the paperback A5 copies is K25, 000 per copy if the expected sale is greater than
200 and K32, 000 otherwise.
Construct a decision table for this pricing scheme. Show that the table is complete and eliminate
any redundancy.
2. Design and write an Algorithm for a program that determines the selling price of a book in
question 1 above. It should be able to request for suitable input from the user.
3. Write a decision tree for the process of deciding the progression criteria or path of a second year
student in the school of business. You will have to consider most of the possibilities or alternatives
that lead to a student either progressing to third year or otherwise.
4. Design and draw a flowchart for a program that find the roots of a quadratic equation ax2+bx+c=0
where a, b and c are real numbers that are supplied by the user.
5. Design and write an Algorithm for the program in question (4) above.