Beruflich Dokumente
Kultur Dokumente
EASTERN PROVINCE
ON
BY
MR PHIRI G.W
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 1
Algorithms And Flowcharts 12thAPRIL, 2018
A. COMPUTER
WHAT IS A COMPUTER
Computer
Monitor Keyboard
case
CD ROM
MOUSE
HARD DISK DRIVE
Used to locate text used to store data or information. Used to output data to disc
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 2
Algorithms And Flowcharts 12thAPRIL, 2018
STORAGE DEVICES
These are devices that are used to store information that has been produced by the computer, for
example Hard Disc Drive, Magnetic tape ( cassette tape) flash or memory stick, compact Disc
(CD) or Digital Vase tail Disc(DVD).
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 3
Algorithms And Flowcharts 12thAPRIL, 2018
ELEMENTS OF A FLOWCHART
Various geometrical shaped boxes represent the steps of a solution.
The boxes are connected by directional arrows to show the flow of a solution.
FLOW CHART SYMBOLS
NAME SHAPE PURPOSE
OVAL Terminator
Used to start/stop
Or Begin /end a program
Elongated rectangle
Terminator
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 4
Algorithms And Flowcharts 12thAPRIL, 2018
ARITHMETIC EXPRESSIONS
+ Addition
- Subtraction
∗ Multiplication (× is not used as it can be confused with X)
/ Division (÷ is not used in computer programming)
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 5
Algorithms And Flowcharts 12thAPRIL, 2018
Example 1.
Draw a flow chart to compute the volume of cuboid given length ‘𝑙’ breadth ‘b’ and height
‘h’.
Solution
EXAMPLE 2
Draw a flow chart to calculate the total surface area of a cylinder given radius ‘r’ and height ‘h’.
Solution
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 6
Algorithms And Flowcharts 12thAPRIL, 2018
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 7
Algorithms And Flowcharts 12thAPRIL, 2018
3. The flow chart below shows how a company calculate agent’s commission based on monthly
sales. Mrs Nkhata an agent of this company, made sales of K 4, 780.00 in one month.
= K478
𝟏
ii) 𝑪𝒐𝒎𝒎𝒊𝒔𝒔𝒊𝒐𝒏 = 𝑲 𝟖𝟖𝟎𝟎 × 𝟓
= K 1,760
NOTE
The key part of flow chart construction is to identify the formula of the concept being
examined in the question that has to be put in the processing box.
Identify the domain (variables) of the formula to be entered in the input box.
Then identify all stages taken in the identified problem solving.
Display or print the result in the output box after the processing has been done.
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 8
Algorithms And Flowcharts 12thAPRIL, 2018
EXERCISE
1. Given that the base of a triangle is ‘b’ and its perpendicular height is ‘h’. Complete the
flow chart below, which is for calculating and displaying its area.
2. Given three numbers a , b and c , complete the flow chart below to calculate the mean (𝑋̅)
of the numbers.
3. With the use of flow charts find the inverse of the function 𝑓(𝑥) = 3𝑥 − 4.
4. Draw a flow chart on how to calculate the length of the hypotenuse side in a right angled
triangle, and then write the program in BASIC.
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 9
Algorithms And Flowcharts 12thAPRIL, 2018
5. The diagram below shows a flow chart for a program to calculate tax on an income.
INCOME TAX
K 3, 700
K 2, 400
K 8,000
3. Write an algorithm in pseudo code to calculate the volume of a given cylinder with radius
“r” and height “h”.
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 10
Algorithms And Flowcharts 12thAPRIL, 2018
PSEUDO CODES
A pseudo code is an artificial and informal language that helps programmers develops
algorithms. A pseudo code may be English or any other spoken language or a combination of
the two.
EXAMPLE 1
Write down an algorithm to calculate the average of five numbers; 13,88,37,19 and 18
SOLUTION;
PSEUDO CODE
Begin
Input; 13,88,37,19,18.
𝐴𝑣𝑒𝑟𝑎𝑔𝑒 = ( 13 + 88 + 37 + 19 + 18)/5
Print; average,
End program
EXAMPLE 2
Write an algorithm to calculate the volume of a given cuboid with length ‘L’ breadth ‘b’ and
height ‘h’.
SOLUTION
Start
Enter, 𝑙
Enter, 𝑏
Enter, ℎ
𝑉𝑜𝑙𝑢𝑚𝑒 = 𝑙 ∗ 𝑏 ∗ ℎ
Print; volume
Stop
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 11
Algorithms And Flowcharts 12thAPRIL, 2018
EXAMPLE 3.
Write an algorithm to calculate the volume of a given cylinder with radius ‘r’ and ‘height ‘h’.
Pseudo code.
Begin program
Input; 𝑟,
Input; ℎ
const; 𝜋.
𝑉𝑜𝑙𝑢𝑚𝑒 = 𝜋 ∗ 𝑟 ∗ 𝑟 ∗ ℎ
Print; volume
End program.
ARITHMETIC OPERATORS
Following table shows all the arithmetic operators supported by Pascal. Assume variable A
holds 10 and variable B holds 20, then:
Table 1.
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 12
Algorithms And Flowcharts 12thAPRIL, 2018
Table 2.
Statement Description
if - then statement An If - then statement consists of a Boolean expression
followed by one or more statements.
If-then-else statement An if - then statement can be followed by an optional else
statement, which executes when the Boolean expression is
false.
nested if statements You can use one if or else if statement inside another if or
else if statement(s).
case statement A case statement allows a variable to be tested for equality
against a list of values.
case - else statement It is similar to the if-then-else statement. Here, an else term
follows the case statement.
nested case statements You can use one case statement inside another case
statement(s).
The IF statement
IF-THEN statement
The IF…THEN statement is used when only one option is available, the simplest form of
control statement, frequently used in decision making and changing the control flow of the
program execution. Its structure is as shown below.
Statement(s)
ENDIF
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 13
Algorithms And Flowcharts 12thAPRIL, 2018
EXAMPLE.
Write a pseudo code and draw a flow chart for a program that determines if a person is allowed
to vote or not, given that a person can only vote if he or she is over 18 years of age.
Pseudo code.
Start
Enter; age
If age >18 then,
Print; vote
Else
Stop
Draw a flow chart diagram for the information above.
SOLUTION
Figure 2
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 14
Algorithms And Flowcharts 12thAPRIL, 2018
1. IF-THEN-ELSE STATEMENT
An IF…THEN statement can be followed by an optional ELSE statement, is used if only two
options are available. It’s a structure is as follows;
Statement(s)
ELSE
Statement(s)
ENDIF
EXAMPLE 2
Start
Enter radius
Else
Enter height
Else
1
Volume = 3 ∗π∗square radius ∗height.
End if
Display Volume
Stop.
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 15
Algorithms And Flowcharts 12thAPRIL, 2018
SOLUTION
EXAMPLE 3.
Start
Enter radius
Else
Enter height,
Else
Endif
Stop
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 16
Algorithms And Flowcharts 12thAPRIL, 2018
SOLUTION
The NESTED IF statement is used if more than two options are available. It is always legal in
Pascal programming to nest if-else statements, which means you can use one if or else if
statement inside another if or else if statement(s). Pascal allows nesting to any level, however, if
depends on Pascal implementation on a particular system. The structure of the NESTED IF
statement is shown below. The format of the flow chart for a NESTED IF statement is as shown
below; n
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 17
Algorithms And Flowcharts 12thAPRIL, 2018
Statements
ELSE
Statements
ELSE
IF <condition> THEN
Statements
ENDIF
ENDIF
ENDIF
EXAMPLE 3
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 18
Algorithms And Flowcharts 12thAPRIL, 2018
SOLUTION
a) PSEUDO CODE
Start
Enter; mark x
IF x≥ 80, then
Remark= distinction
ELSE
IF 60≤ 𝑥 ≤ 79, then
Remark=meritorious
ELSE
IF 40≤ 𝑥 ≤ 59, then
Remark= credit
ELSE
Remark =poor
ENDIF
ENDIF
ENDIF
Stop.
b) Flow chart
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 19
Algorithms And Flowcharts 12thAPRIL, 2018
EXERCISE
1. Study the program below and answer the questions that follow.
Start
Enter value base
If base < 0, THEN
Display “error message “and re-enter positive base.
Else, enter height
If height < 0, THEN
Display “error message” and re-enter positive height
Else,
1
Area= 2 *base*height
End if
Display area
Stop.
2. The program below is given in form of a pseudo code.
Start
Enter, radius
If radius < 0, THEN
Display “error message” and re-enter positive radius
Else,
Enter, height
If height < 0, THEN
Display “error message” and re-enter positive height.
Else,
𝑣 = 𝑏𝑎𝑠𝑒 𝑎𝑟𝑒𝑎 × ℎ𝑒𝑖𝑔ℎ𝑡
End if
Display volume.
Stop.
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 20
Algorithms And Flowcharts 12thAPRIL, 2018
3. Draw a flow chart to represent the equation 𝑦 = 4(2𝑥 + 5). Use the flow chart to find the
value of y when 𝑥 = 7. [4]
4. You are given the following criteria to award a grade in an examination. If a mark is;
“Greater than or equal to 80” distinction
“60 to 70”, credit.
“40 to 59” pass
“Less than 40”, failure.
5. Draw a flow chart and write a program to calculate the average, height of four pupils in
your class with data: 1.5m, 1.69 m, 1.6m, 1.72m. [3]
6. Draw a flow chart and write a program, to calculate volume of a sphere given radius as
data.
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 21
Algorithms And Flowcharts 12thAPRIL, 2018
EXAMPLE 1
SOLUTION
Start
Enter 𝑎, 𝑟
If |r |< 0, THEN
𝑎
𝑆∞ = 1−𝑟
End if
Display Sum to infinity
Stop.
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 22
Algorithms And Flowcharts 12thAPRIL, 2018
EXAMPLE 2
SOLUTION
Start
Enter r
If r < 0, THEN
display error message r must be positive
Else
1
𝐴𝑟𝑒𝑎 = ∗ 𝑟 ∗ 𝑟 ∗ 𝑠𝑖𝑛 𝜃
2
Endif
Display area
Stop.
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 23
Algorithms And Flowcharts 12thAPRIL, 2018
Write down a pseudo code program corresponding to the flow chart program above.
SOLUTION
Start
Sum =0
Count =0
Repeat
Enter number
Count = count +1
Endif
Display mean
Stop
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 24
Algorithms And Flowcharts 12thAPRIL, 2018
EXERCISE
Write down a pseudo code program for the flow chart on how to calculate profit or Loss.
Write down the pseudo code program corresponding to the flow chart program above.
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 25
Algorithms And Flowcharts 12thAPRIL, 2018
Write down a pseudo code progarm corresponding to the flow chart program above.
Mr. Phiri G .W- HOD Mathematics, Chizongwe Technical Secondary School Page 26