Processing and Logic
Processing and Logic
1.1.1 Base-10
Base-10 is known as Decimal. When we count as follows 1, 2, 3, 4, 5, 6, 7, 8, 9 we have no more
numbers to represent the next value once we reach the number 9. We need to set it back to 0
and add 1 to the tens digit, giving us 10. This process continues until we get 99. There is no way
to represent a larger number than 99 with two digits, so we add another digit, giving us 100.
• There are 2 groups of a thousand. 1000 = 10*10*10 which can also be written as 103.
• Finally, there are 7 groups of one, and 1 = 100. (Any number to the power of 0 equals 1.)
So, the number 2347 can be written as 2*103 + 3*102 + 4*101 + 7*100
892 = 8*102+9*101+2*100
1147 = 1*103+1*102+4*101+7*100
53 = 5*101+3*100
Any base has the same number of digits as its base. So base-5 has five digits (0-4), base-7 has
seven digits (0-6), etc. We always use base-10, and it comes naturally to us. If we understand the
patterns behind base-10, we can understand the other bases better.
1.1.2 Base-2
Base-2 is known as binary. Binary is made up of 1’s and 0’s limiting us to two digits. It is important
to know that mathematically binary is no different to any other number system. Like the base-10
number system after we get to 1, we run out of numbers for any higher value. We then need to
change the 1 to 0 and add another digit, leaving us with 10. This can become confusing as 10 in
base-10 is not the same as 10 in base-2. We use subscripts to represent the different number
systems.
1010 = 1010
1.1.3 Base-8
Base-8 is known as Octal. Octal limits us to only 8 digits. 0, 1, 2, 3, 4, 5, 6, 7. There is no such
thing as 8 or 9 in this number system. Like the base-10 number system, after we get to 7, we run
out of numbers to represent any higher values. We then need to change the 7 to 0 and add
another digit. 8 in base-8 is 10 or 108. This can become confusing when read. When working in
number systems other than decimals we tend to read these numbers differently. 10 will be
pronounced “one-zero”. This should help you differentiate 10 (“one-zero”) in decimal being ten
and 10 (“one-zero”) in Octal being 8.
810 = 108
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
A 10
B 11
C 12
D 13
E 14
F 15
• Step 1:
Divide the decimal number to be converted by the value of the new base. (To convert to binary,
divide by two)
2 26
13
• Step 2:
Record the remainder from Step 1 as the right most digit of the new base number.
2 26 0
13 0
2 26 0
13 0
6 1
• Step 4:
Record the remainder from Step 3 as the next digit (to the left of the number recorded in step 2)
2 26 10
13 0
6 1
Steps 3 and 4 must be repeated, until you get an answer of zero in Step 3.
2 26 010
13 0
6 1
3 0
2 26 1010
13 0
6 1
3 0
2 1
2 26 11010
13 0
6 1
3 0
1 1
0 1
Therefore 2610=110102
• Step 1:
Divide the decimal number to be converted by the value of the new base. (To convert to octal,
divide by eight)
8 416
52
• Step 2:
Record the remainder from Step 1 as the right most digit of the new base number.
8 416 0
52 0
• Step 3:
8 416 0
52 0
6 4
Record the remainder from Step 3 as the next digit (to the left of the number recorded in step 2)
8 416 40
52 0
6 4
Steps 3 and 4 must be repeated, until you get an answer of zero in Step 3.
8 416 640
52 0
6 4
0 6
• Step 1:
Divide the decimal number to be converted by the value of the new base. (To convert to
hexadecimal, divide by 16.) Convert the remainder to its hexadecimal value.
16 941
58 13 = D
• Step 2:
Record the remainder from Step 1 as the right most digit of the new base number.
16 941 D
58 13 = D
• Step 3:
16 941 D
58 13 = D
3 10 = A
Record the remainder from Step 3 as the next digit (to the left of the number recorded in step 2)
16 941 AD
58 13 = D
3 10 = A
Steps 3 and 4 must be repeated, until you get an answer of zero in Step 3.
16 941 3AD
58 13 = D
3 10 = A
0 3
94110 = 3AD16
© PIHE PLC 10 | P a g e
1.3 Converting to base 10
Next, we will look at how we can convert from the other number systems to the Decimal number
system.
• Step 1:
Split the number up into columns with one digit in each column. Label columns from right to left
starting at 0.
4 3 2 1 0
1 0 1 1 0
• Step 2:
Use the label of each column and set it to the power of the base the number is in. The Binary
base is used in the example below.
24 23 22 21 20
1 0 1 1 0
• Step 3:
Multiply the value in the column to the base and its power calculated in Step 2
24 23 22 21 20
1 0 1 1 0
24 * 1 = 16 23 * 0 = 0 22 * 1 = 4 21 * 1 = 2 20 * 0 = 0
© PIHE PLC 11 | P a g e
• Step 4:
16 + 0 + 4 + 2 + 0 = 22
• Step 1:
Split the number up into columns with one digit in each column. Label columns from right to left
starting at 0.
2 1 0
2 5 7
• Step 2:
Use the label of each column and set it to the power of the base the number is in. The Octal base
is used in the example below.
82 81 80
2 5 7
• Step 3:
Multiply the value in the column to the base and its power calculated in Step 2
82 81 80
2 5 7
82 * 2 = 128 81 * 5 = 40 80 * 7 = 7
© PIHE PLC 12 | P a g e
• Step 4:
128 + 40 + 7 = 175
• Step 1
Split the number up into columns with one digit in each column. Label columns from right to left
starting at 0.
3 2 1 0
2 B 3 C
• Step 2
3 2 1 0
2 B = 11 3 C = 12
• Step 3
Use the label of each column and set it to the power of the base the number is in. The
Hexadecimal base is used in the example below.
2 B = 11 3 C = 12
• Step 4:
Multiply the value in the column to the base and its power calculated in Step 3
© PIHE PLC 13 | P a g e
163 162 161 160
2 B = 11 3 C = 12
• Step 5:
It is very useful to have a shortcut notation for binary numbers when printing out the contents of
memory. If the contents of memory were to be printed in binary, several pages of zeros and ones
would be required. This form is very difficult to use for a memory dump, because of the length of
the output and the narrow choice of characters.
To reduce the volume and print time of the memory dump and to show memory content with a
greater variety of symbols, either the octal or hexadecimal number system is used as a shortcut
notation. The selection of the shortcut notation is determined by the memory organization of the
machine, any computer will always use either octal or hexadecimal, but not both.
In octal notation we learn how to convert from binary to octal and from octal to binary.
Binary to Octal
• Step 1:
© PIHE PLC 14 | P a g e
Divide the binary digits into groups of 3 starting from right to left. You can add zeros to the front
should your binary number not be able to split into groups of 3
110 011
• Step 2:
Convert each group into 1 digit of octal (Refer back to the binary to decimal conversion section if
below is confusing)
110 011
4+2+0 0+2+1
6 3
Octal to Binary
• Step 1:
2 4 6
• Step 2:
© PIHE PLC 15 | P a g e
Therefore 2468 = 0101001102
Binary to Hexadecimal
• Step 1:
Divide the binary digits into groups of 4 starting from right to left. You can add zeros to the front
should your binary number not be able to split into groups of 4
1101 0111
Step 2:
Convert each group into 1 digit of hexadecimal. Remember to write your answers of 10 – 15 as A
– F.
1101 0111
8+4+0+1 0+4+2+1
13 = D 7
Hexadecimal to Binary
• Step 1:
© PIHE PLC 16 | P a g e
2 A = 10 9
• Step 2:
001010101001
1.5 Arithmetic
An arithmetic logic unit (ALU) represents the fundamental building block of the central processing
unit of a computer. An ALU is a digital circuit used to perform arithmetic and logic operations.
Examples of arithmetic operations are addition, subtraction, multiplication, and division.
Remember that all information in a computer is stored and manipulated in the form of binary
numbers. These numbers can be converted to any other base.
1.5.1 Addition
The steps required to add two numbers are the same in all number systems. Addition always
begins by adding the rightmost column. If the column total is equal to or greater than the value of
the base, a 'carry-over' will occur. Whenever a 1 is carried to the next column, the value being
carried is equal to the value of the base. If the column total from Step 1 is equal to or greater than
the base, subtract the value of the base from the column total and carry a 1 to the next column. If
the column total is still equal to or greater than the base, repeat Step 2.
© PIHE PLC 17 | P a g e
Example adding the decimal numbers 937 to 129:
Carry 1 1
9 3 7
+ 1 2 9
Answer 1 0 6 6
Adding Binary
Carry 1
1 0 1 0
+ 0 0 1 1
Answer 1 1 0 1
Adding Octal
Carry 1 1
1 6 7
+ 7 6 5
Answer 1 1 5 4
© PIHE PLC 18 | P a g e
Adding Hexadecimal
Carry 1 1
8 A = 10 5 C = 12
+ F = 15 3 9 A = 10
Answer 1 7 D F 6
Remember to write 10 – 15 as A – F.
1.5.2 Subtraction
The principles of subtraction using decimal numbers can be applied to subtraction of other bases
as well. Subtraction always begins by subtracting the rightmost column. If the number, we are
subtracting from is less than the number it is being subtracted by it is necessary to borrow from
the column to the left. The value borrowed is always equal to the base of the number system
being subtracted. The second step is to subtract the lower value from the top value.
Subtracting decimal
9 32 7 + 10
- 1 2 9
Answer 8 0 8
Subtracting Binary
© PIHE PLC 19 | P a g e
Example subtracting the binary number 1101 from 0011:
1 10 0+2 1
- 0 0 1 1
Answer 1 0 1 0
Subtracting Octal
43 5+8 6
- 1 7 3
Answer 2 6 3
Subtracting Hexadecimal
BA 7 6 + 16 8 +16
- 8 A B
Answer 2 C D
Remember to write 10 – 15 as A – F.
© PIHE PLC 20 | P a g e
1.6 Complement arithmetic
Most computer manufacturers distinguish between positive and negative numbers by designating
the leftmost bit in a binary number as an indicator of whether a number is positive or negative. If
this sign bit is a zero, the number is positive, and the remaining bits represent the value of the
number. If the leftmost sign bit is a one, the number is considered negative and the remaining bits
represent the value of the negative number.
Computer hardware was built to recognize positive and negative numbers. This method meant
installing complex hardware circuits. This method was soon abandoned in favour of what is called
complement arithmetic.
Examples:
Examples:
© PIHE PLC 21 | P a g e
1.7 Overflow
Overflow occurs when the number of bits resulting from an arithmetic operation exceeds the
maximum number of bits that the computer can handle.
Let’s look at what is going on mathematically, when adding 27 and 16 in a computer that can only
handle a maximum of 6 bits.
Two positive numbers have been added and produced a negative binary number. It is negative
because the leftmost sign bit is 1. This is problematic because adding two positive numbers
cannot have a negative result. When two positive binary numbers are added to give a negative
binary number, it is called a size error.
© PIHE PLC 22 | P a g e
Processing and Logic Concepts
UNIT 2 Computer Logic
2.1 Introduction to computer logic concepts
Computer logic involves operations on data that works according to mathematical logic rules.
Basic computers developed ways to deal with numbers and logical states. These computers used
electronic gates, vacuum tubes and transistors, that were able to apply specific operations that
lead to precise results. Binary logic forms the basis of all computer operations. This logic has
evolved by adapting the principles of reasoning (where a statement can either be true or false) to
the nature of the electronic components that make up computers.
A bistable device can be in one of two possible states – never in both at the same time. For
example, a lamp is either on or off. Electrical current either flows or there is no current. Similarly,
computers use a binary system of logic in which variables can have only one of two possible
values, 0 or 1. A variable is an element or a factor that is subject to change. The bistable nature
of electronic components is at the heart of binary logic, which effectively models a computer's
operations. In computers, logic operations are incorporated into electronic circuits in the form of
logic gates. These operations will be discussed further in this section.
The concept of logical operators is simple. Logic operators allows a program to make a decision,
based on conditions. Each variable is considered a condition that can be evaluated to a true/on/1
or false/off/0 value. The value of the conditions is used to determine the overall value.
Logic diagrams exist in many formats. Logic gates, truth tables and Venn diagrams are all
examples of logic diagrams. Logic diagrams are used to visually represent logic reasoning. Binary
logic uses three basic logic operations, AND, OR and NOT. The table below illustrates the
difference between these operations and is visually represented using Logic diagrams.
Functio
Operator Logic gate Truth Table Venn Diagram
n
AND A B A.B=C
The result
0 0 0
C= A.B
is true only
if both or 0 1 0
variables
C = AB
1 0 0
are true.
1 1 1
A B A+B=
C
OR
The result
0 0 0
is true if
C=A+B
either 0 1 1
variable is
1 0 1
true.
1 1 1
The state
indicator A A'
changes
A = A' 0 1
true to
false and 1 0
false to
true.
3. The input to OR gate 3 is the result of gate 1 (XY) and gate 2 (ST), giving the output
expression:
XY + ST.
The aim of a truth table is to prove that the left-hand side (LHS) of an equation is equal to the
right-hand side (RHS), for each combination of variables. For example:
A+B=B+A
To prove that the expressions above is in fact equal, we draw a truth table. How do we do this?
Well let’s go through it together.
Before we start, we must remember that every character in the expression is a binary variable
and it represents the number 1 or 0. For example in the expression A + B both A OR B can be
either 1 or 0.
When starting with the construction of our table we first need to look at what makes up the
columns. Below is a list of rules you can use to help you identify the column headings:
• Each variable in the expression will be a new column e.g. A + B will have two columns.
One for A and the second one B.
• Each inverted variable will be a new column e.g. A’ + B will have three columns. One for
A, one for B and one for A’. If you are wondering why we are including A even though it
• Each unique grouping of terms in brackets e.g. (A + B)C will have four columns. One for
A, one for B, one for C and one for the brackets (A + B)
• Each unique grouping of terms ANDed together e.g. A + BC will have four columns. One
for A, one for B, one for C and one for BC
• The last two columns will always be the LHS of the expression and the RHS of the
expression.
Now that we have an idea of how to identify our columns, we should look at what determines the
number of rows in our table.
The number of rows can easily be determined from the number of unique variables in our given
expression. The expression A + B has two unique variables. To determine the number of rows
we will need to consider how much numbers the variable can represent. Because we are working
in binary, the variable can only represent one of two values, being 1 or 0. We then use the
calculation 2n = c with n being the number of variables in the expression and c being the maximum
number of combinations. For example: The expression A + B + C has three unique variables. The
calculation to determine the maximum amount of combinations will be 23 = 8.
Now that we know how to determine our table headings and how to calculate all the possible
combinations, we can start constructing our truth table.
Example 1
A+B=B+A
First let’s start by determining the number of columns. There are two unique variables A and B.
There are no inverted variables, no brackets and no terms ANDed together. We therefore have a
total of four columns. Two for our unique variables and two indicating our LHS and RHS.
Next, let’s determine the number of rows. Since we have two unique variables, we will use the
formula 22 = 4.
Now that we have identified our columns and rows we can go ahead and construct our first truth
table.
A B A+B B+A
1 1 1 1
1 0 1 1
0 1 1 1
0 0 0 0
We need to ensure that we always write down our conclusion which is LHS = RHS.
Should you find that your LHS does not match your RHS you made a mistake somewhere and
you will need to check each 0 and 1 for that row to identify the mistake.
Example 2
Next, we will look at drawing a Truth table for a bigger expression which will allow us to practice
identifying more columns and rows.
Again, we will start by determining the number of columns. There are three unique variables A,
B and C. There is one inverted variable B’, one unique bracket (B+C) and four unique terms
ANDed together B’C, AB, AC and A(B + C). We therefore have a total of eleven columns. The
nine we just mentioned and the two indicating our LHS and RHS.
Now let’s determine the number of rows. Since we have three unique variables, we will use the
formula 23 = 8.
Now that we have identified our columns and rows we can go ahead and construct our second
Truth table.
1 1 1 0 1 0 1 1 1 1 1
1 1 0 0 1 0 1 0 1 1 1
1 0 1 1 1 1 0 1 1 1 1
1 0 0 1 0 0 0 0 0 0 0
0 1 1 0 1 0 0 0 0 0 0
0 1 0 0 1 0 0 0 0 0 0
0 0 1 1 1 1 0 0 0 1 1
0 0 0 1 0 0 0 0 0 0 0
Although Boolean algebra has its own set of laws and theorems, it is also governed by the laws
of arithmetic algebra.
Using algebra
Before you evaluate an algebraic equation, you need to simplify it. Here are the basic steps to
follow when simplifying an algebraic expression:
5(2 + x) + 3(5x + 4)
When simplifying an expression, the first thing to look for is whether you can clear any
parentheses. Often, you can use the distributive property to clear parentheses, by multiplying the
factors with the terms inside the parentheses. In this expression, we can use the distributive
property to get rid of the first two sets of parentheses.
= 10 + 5x + 15x + 12
The next step in simplifying is to look for like terms and combine them. The terms 5x and 15x are
like terms, because they have the same variable. We can combine these two terms to get 20x.
= 10 + 20x + 12
Finally, we look for any constants that we can combine. Here, we have the constants 10 and 12.
We can combine them to get 22.
= 22 + 20x
Involution (A')' = A
Commutative A+B=B+A
A.B = B.A
Associative (A + B) + C = A + (B + C)
A.(B.C) = (A.B).C
A + B.C = (A + B).( A + C)
Absorption A + A.B = A
3.2.3.1 AND
AND LAWS
x.0 = 0
x.1 = x
x.x = x
x.x’ = 0
xy = yx
(xy)z = x(yz)
x + yz = (x + y)(x + z)
x(x + y) = x
(xy)’ = x’ + y’
OR LAWS
x+0=x
x+1=1
x+x=x
x + x’ = 1
x+y=y+x
(x + y) + z = x + (y + z)
x (y + z) = xy + xz
x + xy = x
(x + y)’ = x’.y’
3.2.3.3 NOT
In some instances, a condition may be negated more than once. It may have a double negation,
a triple negation, or more. If there is an even number of vincula over the variable, it can be reduced
to equal the variable itself. (No vincula). If there is an odd number of vincula over the variable the
value is equal to the inverse of the variable (1 vinculum)
De Morgan's theorem may be thought of as breaking 'the bar'. When the bar is broken, the
operation directly underneath changes from addition (OR) to multiplication (AND), or multiplication
(AND) to addition (OR), and the remaining bar piece stays over the individual variables.
F = A'B'(A' + B)(1)
A'A'B' + A'BB'
A'B' + A'(0)
A'B' + 0
A'B'
A + B + CD + (AB)'
= A + B + CD + A' + B' De Morgan’s
= A + A' + B + B' + CD Commutative
= 1 + 1 + CD Uniqueness
=1
A decision table is a tool that systems analyst can give to a programmer to help them understand
the system they need to develop better. This tool allows for a more effective form of
communication than a written or verbal explanation. Look at an example of a decision table below
and see if you can understand it before reading the explanation.
1 2 3 4 5 6 7 8
C Bill >= Y Y N N Y Y N N
2 R1000
C Rewards Y N Y N Y N Y N
3 card
A 5% cash X
2 back
A No rewards X X X X
3
Above is an example of a cash back rewards system that rewards a customer with a small amount
of money back based on the total of their bill. On checkout the system will check whether the
customer qualified for a reward.
• Should they have a card and their total is equal to or more than R500 but less than R1
000 the person will get 2% cash back.
• If they have a card and their total is equal to or more than R1 000 the person will get 5%
cash back.
• Should the person not have a card, or their total is less than R500 they do not qualify for
a reward.
• There are also two columns in our table (shown in red) which we say is impossible as it
indicates that the bill is both less than or equal to R500 and more than R1 000 at the same
time. If you draw your decision table on paper, you can draw a vertical line through the
column.
I hope we agree that the diagram presents the needs of the system clearer to the programmer.
The systems analyst will draw up these diagrams after an information gathering session with the
client. Your goal in this unit will be to learn how to draw and read a decision table.
Now let us break down the various elements of a decision table so we can better understand what
each part represents.
• Title (an identifying description of the system/table as a whole). In our first example, the
title of the table is 'Cash back rewards System'.
• Conditions (factors the computer must test to make a decision). A condition statement is
a choice that our system needs to make based on a particular scenario. A possible
outcome based on the combination of the conditions is indicated with either Y (yes) or N
(no). In our decision tables we will only cover three and four conditions but know that this
number can be much higher depending on the complexity of the system you are
developing.
• Actions (actions to be taken as a result of existing conditions). An action can either take
place (represented by X) or not take place (blank square). In our first example we used
the X to indicate what type of reward (if any) the customer qualified for.
• Rules. The number of rules for our decision table is determined by the unique number of
conditions we have. Since we are working with two outcomes ‘Yes’ or ‘No’ for each
condition, we can use the same formula (2n = c) as we did when determining our number
of combinations in the Truth Table section. n represents the number of unique conditions
and c the maximum number of rules.
• Impossibilities. These are rules where the combination of ‘Y’ and ‘N’ do not make logical
sense or has been indicated by the client as something that the system should not allow.
These rules can be marked as impossible by either using the colour red or drawing a line
through the rule if you are drawing it out on paper. Here are a few examples:
• Numeric values can’t be higher and lower than the exact same number at the same
time e.g. you can’t be younger than 21 but also older than 35 at the same time
• If a bank indicates that anyone who is unemployed cannot qualify for a loan, then
all rules indicating that this is possible should be marked as impossible.
Now that we have a better understanding of what a decision table is, it is time we learn how to
draw our own.
Example
Rainbow nation bank would like an instant loan application system that will provide loans to a
client at an ATM machine based on their profile. We have been provided with the following rules
the system must adhere to:
• Should the person not be credit worthy the system should not indicate the loan option
• If the person earns up to R10 000 they will qualify for a loan of up to R5 000
• If the person earns up to R15 000 they will qualify for a loan of up to R7 500
• If the person earns more than R20 000 the system should in addition to the first two
amounts also provide a call me option to request a consultant to call the client regarding
a loan
Let’s look at a step by step approach we can follow to construct our Decision table:
Step 1:
Collect all information needed on the problem to be solved by the table. In this case, it’s the
above information. Identify a title for your system e.g. Loan System
Step 2:
Identify all the conditions (factors the computer must test to make a decision) to be included in
the table.
In the third step, actions are identified. These actions are to be taken as a result of the existing
conditions.
Step 4:
Determine the number of rules to be included in your table. The number of rules equals two to
the power of the number of conditions. Since our scenario have four conditions, we will have 24
= 16 Rules e.g.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
C1 Credit
worthy?
C2 Earn >
10000?
C3 Earn >
15000?
C4 Earn >
20000?
Fill in the Y (yes) and N (no) for your conditions. We can use the following pattern to make it
easier:
Next, identify any impossible columns based on the conditions. See below for example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
C1 Credit Y Y Y Y Y Y Y Y N N N N N N N N
worthy?
C2 Earn > Y Y Y Y N N N N Y Y Y Y N N N N
10000?
C3 Earn > Y Y N N Y Y N N Y Y N N Y Y N N
15000?
C4 Earn > Y N Y N Y N Y N Y N Y N Y N Y N
20000?
Rule 3, 5, 6, 7, 11, 13, 14 and 15 is impossible as the salary can’t be lower than a low amount
and higher than a high amount at the same time e.g. client earns less than 10 000 but more than
20 000 at the same time.
Action entries must be filled in. An action can either take place (represented by an X) or not take
place (blank square)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
C1 Credit Y Y Y Y Y Y Y Y N N N N N N N N
worthy?
C2 Earn > Y Y Y Y N N N N Y Y Y Y N N N N
10000?
C3 Earn > Y Y N N Y Y N N Y Y N N Y Y N N
15000?
C4 Earn > Y N Y N Y N Y N Y N Y N Y N Y N
20000?
A1 No Loan X X X X X
option
A2 Qualify for X X X
5000
A3 Qualify for X X
7500
Step 7:
The Table size indicator must be added. For the above scenario we used 4C, 3A, 16R, 8I (four
conditions, four actions, sixteen rules and eight impossible columns).
In conclusion
Each program on a system flowchart is referenced by a name such as Program 1. The steps in
the computer programs and the logic required for each is not shown on the system flowchart.
These appear on the program flowchart. (See Unit 6 -Program Flowcharts)
A system flowchart is a convenient way to design the logic for systems. It is less costly to
determine, arrange and rearrange complex logic on a flowchart than to correct logic errors in an
implemented system. The flowchart becomes an integral part of the system documentation. A
system flowchart is vital if the system is to be maintained easily and efficiently or if modifications
are necessary.
The information technology industry has developed an international set of standardised system
flowchart symbols and symbol definitions. These allow system flowcharts to be easily understood
to anyone working in the industry anywhere in the world. The table below shows the most common
system flowchart symbols and their function.
Terminator
Disk Storage
Document
Output Display
Manual Input
Merge
External/Offline storage
Now that we know what symbols we can use to draw a system flowchart, let us look at an
example of one.
A school would like to store their Grade 12 results and compare it with the results of the
previous year. The school starts by entering the current Grade 12 results into a program. This
information is then stored on a disk and a copy of the disk is made for storage. Once the copy is
• We will not be writing the logic of the process/program symbol. We only need to label the
process with the action it must perform e.g. make copy, sort date etc. We do not have to
write the logic of how the copy is made or sorting takes place.
• Anything input at the keyboard, using the manual input symbol, is entered into a program.
• When making a backup or copy of a file on disk, input the file into a backup or copy
program and output a new file on disk (called Backup file or Copy file)
The system begins with three source documents, which are loaded onto one disk called
INVOICE DISK.
The INVOICE DISK is manually checked, and any incorrect records are processed again and
rechecked.
Once the records on the INVOICE DISK are all correct, the INVOICE DISK are merged onto
one DISK called COLLATED INVOICES. The COLLATED INVOICES file is used as input to
three programs.
PROGRAM 4 uses the INCOME DISK to produce REPORT 2. The date is entered at the
keyboard for REPORT 2.
A Program Flowchart is a tool we use to illustrate the logic of our program in an easily understood
format. Developers will use the flowchart to develop the system in a program language suitable
for developing the software. It is less costly to create a program flowchart to find a solution to a
complex logic problem than to solve it during program development. A program flowchart is vital
if the program is to be maintained easily and efficiently or if modifications are necessary.
Program flowcharts are constructed with a set of standardised symbols that make it easier for
persons other than the original programmer to read and maintain the program. A flowchart allows
developers who code in different programming languages and communicate in different
languages to understand the same program logic. Below are the symbols we use to construct a
program flowchart.
Terminator
Input / Output
Process
Decision
Connector
Off-page connector
6.3 Variables
• A variable name should be short, simple, descriptive, and meaningful and the same name
should be used throughout the program. The variable names num, number, nums will all
represent a different variable name to the program.
• Some computer languages are case-sensitive and so the variable name should be in the
same case throughout the program. The variable Num and num will therefore be treated
as two different variables.
• Variable names should begin with a small letter. When joining two words, the first letter of
the second word should be capitalised. For example, totStud could be used to represent
the total number of students. The standard is to be used when drawing program
flowcharts.
6.4 Calculations
The result of a calculation must always be recorded in a variable. If we do not record this value,
we are unable to use the result in another calculation or output the result to the user.
• Percentages must be converted to decimal before you can work with them.
For example, if the tax is 10% of the gross salary the calculation would be worked out as
follows:
tax = grossPay * 0.1
Please take note of the following important calculations that must be understood for the examples
in this course:
• Percentage – Calculation showing your result for an exam result out of 100.
• avgMark = totalMark / 6
• Modulus (MOD) - Returns the remainder of two numbers that have been divided.
• e.g. 8 MOD 6 = 2. The number 6 goes into 8 once. 8 - (6*1) = 2 which is our answer.
• e.g. 16 MOD 5 = 1. The number 5 goes into 16 three times. 16 - (5*3) = 1 which is
our answer.
• e.g. 10 MOD 2 = 0. The number 2 goes into 10 five times. 10 - (2*5) = 0 which is
our answer.
Let’s have a look at our first program flowchart. Below is a flowchart for a program that will do the
following:
Input the number of kilometres on a car odometer when the car is filled with petrol, the number of
kilometres on the odometer when the car was previously filled, and the number of litres of petrol
used to fill the car's tank.
Calculate the kilometres per litre by subtracting the previous odometer reading from the current
odometer reading and then dividing by the number of litres used to fill the car.
Flowchart loops are used when a process may be performed one or more times. Used, for
example, when more than one record from a file is to be processed by the computer program. In
this case, the computer will read in the next record after processing the current record. However,
the program must be able to stop when all the records have been processed. To make this
possible, an end-of-file (EOF) check is used. Every computer input device uses a special record
called an end-of-file, or EOF record. The EOF record is the last record in a file.
When using loops in your programs, an EOF check should be used, unless specific instructions
are given, such as, process until the number zero is input. Use a decision symbol to represent an
EOF check.
• An EOF check determines whether the record is the last record in the file. If the EOF
condition is true (‘Y’), the program stops. Otherwise (‘N’), the program will continue to
process the records.
• The gross pay is calculated by multiplying the hours by the rate. The net pay is calculated
by subtracting the deductions from the gross pay. A payslip is then printed and the next
record on the file is read and processed.
When supplying the information to be included in a program, it is vital to remember two important
facts about computers:
1. Computers can determine and act on only 'Yes' and 'No' decisions.
2. You must supply every decision the computer is to make and every resulting action for
each decision (refer to Decision Table section for more information on this)
These factors require the programmer to pay a great deal of attention to the logic of the program.
The following special symbols are frequently used in flowcharts to indicate relationships:
> Greater than
< Less than
≥ Greater than or equal to
≤ Less than or equal to
= Equal
<> or != Not equal
Below is an example where decisions are being used to determine the message the person
receives depending on the mark entered. If the mark is less than 60 the message Fail is displayed.
If the person gets a mark from 60 to 79, they see the message Pass. Lastly, should the person
get 80 or higher the message Distinction is displayed.
The word accumulate means to add together. In programming terms when we say that we are
accumulating the student's marks, we mean that we are adding all the marks of the student
together. We will show this in a process symbol like this:
The word increment means to count. In programming terms when we say that we are incrementing
the number of votes, we mean that we are counting the total number of votes made. We will show
this in a process symbol like this:
© PIHE PLC 10 | P a g e
There are three rules to remember when accumulating or incrementing totals:
2. Totals that have been initialised must be accumulated or incremented within the main
processing loop e.g.
3. Totals that have been accumulated or incremented must be printed at the end of the
program after the end-of-file condition has been met.
Now let’s look at how accumulation and incrementation is shown in a program flowchart.
© PIHE PLC 11 | P a g e
Using the above example, suppose the first record contained the following data:
The net pay is equal to the gross pay minus tax, which would give us 1 800. totNetPay has been
initialised to zero and will become 1 800 with John Smith's net pay added to it. If the net pay for
the next record is 1 200, totNetPay will become 3 000.
© PIHE PLC 12 | P a g e
The program will continue adding the net pay for each record to totNetPay. After all the records
have been processed, totNetPay will be printed.
© PIHE PLC 13 | P a g e
6.8 Printed output
Most programs that we create as programmers produce some form of output that the user of the
program can use. We must use the print keyword followed by the value or variable that we wish
to output. Below are a few examples where output takes place.
The following output symbol will display Hello World to the screen. Note that the quotes are not
printed.
© PIHE PLC 14 | P a g e
In the next example we use two symbols to display Welcome to Pearson. In the process symbol
we assign the variable greeting a value. This will not print anything yet. In the output symbol the
value of the variable greeting is printed on the screen. This method is very handy when you wish
to assign different values to a variable depending on certain decisions and output the value once
at the end.
Please note that the keyword print does not print on a piece of paper, but rather outputs the values
on the computer screen for the user to see.
© PIHE PLC 15 | P a g e
Below is a sample output of what could be displayed by the program:
: : : : :
© PIHE PLC 16 | P a g e
6.8.2 Printed output – Example 2
In the flowchart below the name and percentage of a student is read into the program. If it is not
the end-of-file, the percentage is checked and the msg variable is assigned the value of either
Pass or Fail. The name, percentage and the value of the msg variable is printed. The next record
is then read.
© PIHE PLC 17 | P a g e
Below is a sample output of what could be displayed by the program:
Steven 40 Fail
Themba 75 Pass
: : :
Earlier in the unit we learnt that computers can determine and act only on 'yes' and 'no' conditions,
and that the programmer must supply every decision the computer is to make and every resulting
action for each decision. It is extremely important that the program should be able to recover from
incorrect input from the user. This is done through the use of error messages. If error checking is
not used in a program, the program will crash when unexpected information is input.
Up until now we have not factored in that the user could provide incorrect values for our program.
Let’s look at how we can validate user input with some examples.
© PIHE PLC 18 | P a g e
Below is a sample output of what could be displayed by the program if the value 1, 2, and 3 where
used as input:
1 Beetle
2 BMW
: : :
© PIHE PLC 19 | P a g e
Processing and Logic Concepts
A trace table is a useful tool in the development of program flowcharts because it is like running
a program on paper. It forces the programmer to be consistent and check the program line-by-
line or box-by-box, without taking shortcuts. A trace table serves the following functions:
• It allows the programmer to see the output before coding and debugging on computer.
• It serves as a teaching and learning tool for concepts like variables and values.
• It allows for the detection of logic errors and helps identify ways of correcting the problem.
Constructing a trace table is as simple as drawing columns on a ruled page. The first column is
used for referencing the line number (for program code) or box number (for flowcharts). Next are
columns for each unique variable – each variable must have its own column. These are followed
by columns for control structures, i.e. the conditions/decisions including the one for the loop. The
last column is used for output or print statements. The order of the columns from left to right is
not important.
Example 1
Note that the numbered boxes on the flowchart represents the first column (Box no columns)
values in the trace table below.
A B
8 6
15 3
20 8
12 4
7 2
Example 2
The first example showed us a trace table of a program flowchart that was correct. It is however
possible that we could make a mistake in our program flowchart and we will then be able to see
this mistake in our trace table. See if you can spot the error in the flowchart below.
85
75
50
Box No perc EOF? perc < 60? perc < 80? Output
1 85
2 No
3 No
6 Fail
1 75
2 No
3 No
6 Fail
1 50
2 No
3 Yes
4 Yes
7 Pass
1
2 Yes
From the trace table we can see that there is an error in our program. Our program is currently
printing Fail for the results 85 and 75 but Pass for the result 50. We can fix this error by switching
the ‘Yes’ and ‘No’ around for the decision perc < 60.
Pseudocode is a method of displaying the logical flow and structure of a program. If structured
correctly, the logic makes a program easier to follow and coding becomes a straightforward
process.
There are two parts to writing a program – designing and writing the code. Once the logic of the
design has been checked and corrected, the design is ready to be translated into code. Much
time can be wasted in trying to find logical errors in a program that has been coded without a
properly checked design. Just as a builder should never build a house without a properly drawn-
up plan, one should never code a program without a proper design.
We learned about program flowcharts as a means of describing the flow of logic in a program.
Although a program flowchart is a useful tool for describing what a program must do, it has
definite shortcomings:
Pseudocode is ideal for designing a program plan because it shows the step-by-step logic in a
format that is easy to read and translate into a specific computer language. Pseudocode can
easily be tested to ensure that program output meets the requirements. Finding and correcting
errors at this stage is far easier and less costly than after the coding has been completed.
There are literally thousands of programming languages worldwide. Some of them, like C or C++,
are used for engineering applications or in games development, while programs such as C# and
Java are used in commercial and web development. Most of them use commands based on
English.
Programming languages are described as either low level or high level. The closer the language
is to machine code, the lower the level. Low-level languages use ones and zeroes, and
communicate directly with the computer’s processor, whereas the high-level languages are more
English-based and need to be converted to zeroes and ones that can be interpreted by the
processor. The languages mentioned in the preceding paragraph are all examples of high-level
languages.
Start begin
Stop end
Initialisation total = 0
total = total + 1
endIf
endIf
read num
print num
read num
endWhile
end
In this section we will look at how we can write pseudocode from a program flowchart.
Example 1
A program is required to calculate the annual cost of running a motor car. Costs include monthly
instalments, annual fuel cost and insurance. The annual insurance rate is 3% of the car's value.
On the left is the flowchart for the scenario given above and on the right the pseudocode.
begin
annCost = monthlyInstallment * 12
end
Take note of the tab spacing(indentation) used. The begin and end is underneath each other but
the rest of the code is to the right. The reason for this is to make it easier for us to see where a
block of code starts and ends. We use the same spacing when working with decisions such as
the if and while statement. Some programming languages, like Python, makes use of the spacing
to show the start and end of a decision. Failure to create the spacing correctly will result in an
error in Python.
A school wants to know the average exam mark for a group of students and the total number of
students that got a distinction (mark equal to or greater than 80). The input for the program will
be the name of the student, student mark and the maximum mark of the exam. The output for
each student should be the student name and percentage. The program should stop when a
student name of ZZZ is entered.
totStud = 0
totPerc = 0
totDistinct = 0
input name
while name != “ZZZ” # this can also be written as: while name <> “ZZZ”
totDistinct = totDistinct + 1
endIf
totStud = totStud + 1
input name
endWhile
end