Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Start

Enter 𝑥

𝑦 =7∗𝑥−3

Display 𝑦

Stop

TEACHING NOTES (KEY POINTS WITH EXAM QUESTIONS)

2nd Edition

BUUMBA, P. CONTACT: 0979633656

© 2023 All rights reserved.


INTRODUCTION.
COMPUTER MATHEMATICS is a component of computer science (programming). It should be noted
that as a topic in mathematics, we do not really go into details in looking at what pertains pseudo codes
and flowcharts as those who do programming. In connection with mathematics, there is literally nothing
much to solve but rather looks at the step by step procedures on how to solve some given problems. For
instance, if I ask you this question, “how do you multiply decimal fractions?” Here am not really asking
you to multiply decimal fractions but to tell me the procedure or steps that I may follow in order to
multiply decimal fractions from the start up to the final answer. This step by step procedure is what we
call ALGORITHM. An algorithm is presented using either a flowchart or pseudo code, hence,
ALGORITHM USING FLOWCHART AND PSEUDO CODE.

COMPUTERS
A computer is simply a device that can be programmed to carry out arithmetic or logical operations.
Basic elements of a computer include among others input and output devices. Input devices send data and
instructions to computers. The most common input devices are keyboard, mouse, scanner, joystick,
barcode reader etc. On the other hand output devices display or output work done by the computer in a
readable format to users. Output devices include the following monitor (screen), printer, speakers etc.
BASIC MATHEMATICAL OPERATIONS
There are four basic operations that are carried out with numbers. These are addition, subtraction,
multiplication and division. When dealing with programming, there is a special way of writing these
operation symbols and it is called computer language. The table below shows the expression of these
operation symbols in both mathematical and computer languages as well as some examples.
MATHEMATICAL LANGUAGE COMPUTER LANGUAGE
Addition (+) +
Subtraction ( − ) −
Multiplication ( × ) ∗
Division (÷ ) /
𝑥+𝑦 𝑥+𝑦
𝑥−𝑦 𝑥−𝑦
𝑥×𝑦 𝑥∗𝑦
𝑥÷𝑦 𝑥/𝑦
𝑥2 𝑥∗𝑥
(𝑥 + 𝑦)(𝑥 − 𝑦) (𝑥 + 𝑦) ∗ (𝑥 − 𝑦)
𝑎 + 𝑏 − 2𝑎𝑏𝑐 𝑎+𝑏−2∗𝑎∗𝑏∗𝑐

Note that addition and subtraction symbols remain the same, only multiplication and division symbols
change.
ALGORITHMS
An algorithm can simply be defined as a step by step procedure to solve a given problem.
WRITING AN ALGORITHM
We can write an algorithm by using either a flowchart or a pseudo code.

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 1


What is a flowchart?
A flow chart is a graphical or visual representation of an algorithm or process. Two ways to write an algorithm are:
Flowchart and Pseudo code.
What is a pseudo code?
A pseudo code is a compact and informal high level description of a program
.
EXERCISE 1
1. Define the following terms:
(a) Computer,
(b) Algorithm,
(c) Flowchart,
(d) Pseudo code.
2. Re-write the following formulas using computer language.
1 𝜃
(a) P = 2(𝑙 + 𝑤) (b) A = (𝑎 + 𝑏)ℎ (c) A = × 𝜋𝑟 2 (d) V = 𝜋𝑟 2 ℎ (e) V = 𝑙𝑏ℎ
2 360
1 𝜃
(f) V = 3
𝜋𝑟 2 ℎ (g) A = 𝜋𝑟𝑙 + 𝜋𝑟 2 (h) 𝑙 = 360
× 2𝜋𝑟 (i) C = 2𝜋𝑟 (j) A = 4𝜋𝑟 2

FLOWCHARTS

 Flowchart is a graphical or visual representation of an algorithm.


 Flowchart uses formally agreed standard symbols connected by lines with arrows to show the flow
of the algorithm.
 Due to its graphical nature, flowchart is easier to read and understand.

FLOWCHART SYMBOLS
There are six basic symbols that are commonly used in flowchart. These are:

SYMBOL USE
1. Terminal (for start/stop)
Indicates the starting or ending of the program. Sometimes we use the oval
shape

2. Parallelogram (for Input/output)

Used for input or output operations i.e. taking input and showing output

3. Rectangle (for Process)


Used to indicate any type of internal operations like initialisation,
calculations etc.

Have you ever wondered what happens when you punch say 99 + 798 or any other input on the calculator
before it gives you the answer?
Whatever happens before the answer is displayed is called the internal process or internal operation.

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 2


4. Diamond shape/ Rhombus (for Decision)

Indicates the selection or decision. It is used for asking questions that can
have either YES or NO (TRUE or FALSE) as an answer.

5. Connector
Used for connecting breaks in the in the flowchart.

Basic flowchart symbols are:


6. Arrows (for direction) Oval, parallelogram, Rhombus
Used to show direction of the flow. (Diamond), connector and
arrows.

FLOWCHART RULES
 Flowchart is generally drawn from top to bottom.
 All boxes (symbols) of the flowchart must be connected with an arrow.
 All flowcharts start with a Terminal. Flowcharts always have starting and ending points indicated by
the symbol (Terminal or oval).
 Decision symbol has two exit points, one for YES (TRUE) and another one for NO (FALSE).

Example 1
Given that the base of a triangle is 𝑏 and its perpendicular height ℎ. Draw a flow chart for a program
that calculates the area of a right angled triangle.
Solution.
1
The formula for the area of a triangle is given by: 𝐴 = 𝑏ℎ
2
Start
TIPS.
 A flowchart always starts with a terminal or oval
shape. Enter b, h
 The second step is to make entries. Here you only
enter variables which should be separated by a
comma always. 𝐴=1 2∗𝑏∗ℎ
 After entering, we expect the program to do the
processing. This is shown by the formula written
using computer language in a rectangle.
 After processing, the results are displayed. Display Area
 Then stop.
Stop

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 3


Example 2
Given the radius (r) and height (h), complete the flowchart below for calculating and displaying the
volume of the cylinder. [V = 𝜋𝑟 2 ℎ]

SOLUTION
Start
Start

Enter r, h

𝐴 =𝜋∗𝑟∗𝑟∗ℎ

Display Volume

Stop
Stop

EXERCISE 2
1. Name and draw the symbol which represents each of the following in the flowchart.
(a) Process (b) input (c) decision
2. Draw flowcharts for the programs that calculate the following: (tip: make sure you first identify
variables and constants in the formula.)
1 𝜃
(a) P = 2(𝑙 + 𝑤) (b) A = 2 (𝑎 + 𝑏)ℎ (c) A = 360 × 𝜋𝑟 2 (d) V = 𝜋𝑟 2 ℎ (e) V = 𝑙𝑏ℎ
1 𝜃
(f) V = 3 𝜋𝑟 2 ℎ (g) A = 𝜋𝑟𝑙 + 𝜋𝑟 2 (h) 𝑙 = 360
× 2𝜋𝑟 (i) C = 2𝜋𝑟 (j) A = 4𝜋𝑟 2
1 𝑎
(k) A= 2 𝑎𝑏𝑠𝑖𝑛𝐶 (l) 𝑆∞ = 1−𝑟 (m) 𝐴 = 𝑙𝑏 (n) 𝐴 = 2𝜋𝑟ℎ + 2𝜋𝑟 2

PSEUDO CODE

 A pseudo code is a compact and informal high level description of a program.


 Pseudo code is written in plain English.
 It resembles closely to programming language but is not a programming language.
 Pseudo code does not run on a computer.

GUIDELINES FOR OUTLINING A GOOD PSEUDO CODE.


 The statement must be short, clear and readable.
 The statement must not have more than one meaning i.e. should not be doubtful, unclear or puzzling.
 The pseudo code lines should be clearly outlined and indented.

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 4


 A pseudo code should show clearly the start and the stop of executable statements.
 The input, output and processing statements should be clearly stated using keywords such as PRINT,
DISPLAY, OUTPUT, ENTER, INPUT, COMPUTE, CALCULATE etc.
Example 3.
Write a pseudo code for a program that calculates and outputs the area of a circle.
Solution.
The formula for calculating the area of a circle is given by 𝐴 = 𝜋𝑟 2 .
Note that in the formula, the variable is 𝑟, so when entering we will only enter 𝑟.
Start
Enter r
𝑨=𝝅∗𝒓∗𝒓
Display Area
Stop

Example 4.
1
Write a pseudo code for a program that calculates and outputs the area of a triangle. [𝐴 = 2 𝑎𝑏𝑠𝑖𝑛𝐶]

Solution.
1
The formula is 𝐴 = 𝑎𝑏𝑠𝑖𝑛𝐶
2
Note that in the formula, the variables are 𝑎, 𝑏 𝑎𝑛𝑑 𝐶. 𝑇ℎ𝑖𝑠 is what we will enter.
Start
Enter 𝒂, 𝒃, 𝑪
𝑨 = 𝟏⁄𝟐 ∗ 𝒂 ∗ 𝒃 ∗ 𝒔𝒊𝒏 𝑪
Display Area
Stop

Example 5.
Study the flowchart below and write a pseudo code corresponding to it.
Start

Enter x Solution.
Start
𝑦 =7∗𝑥−3 Enter x
𝒚 = 𝟕∗𝒙−𝟑
Display y
Display y Stop

Stop

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 5


EXERCISE 3.
1. Write a pseudo code for the program that calculates and outputs each of the following.
1 𝜃
(b) P = 2(𝑙 + 𝑤) (b) A = 2 (𝑎 + 𝑏)ℎ (c) A = 360 × 𝜋𝑟 2 (d) V = 𝜋𝑟 2 ℎ (e) V = 𝑙𝑏ℎ
1 𝜃
(g) V = 𝜋𝑟 2 ℎ (g) A = 𝜋𝑟𝑙 + 𝜋𝑟 2 (h) 𝑙 = × 2𝜋𝑟 (i) C = 2𝜋𝑟 (j) A = 4𝜋𝑟 2
3 360
1 𝑎
(l) A= (𝑙𝑏)ℎ (l) 𝑆∞ = (m) 𝐴 = 𝑙𝑏 (n) 𝐴 = 2𝜋𝑟ℎ + 2𝜋𝑟 2
3 1−𝑟

2. Study the following flowcharts and write the corresponding pseudo codes for each one of them.

(a) (b) (c)

SELECTION CONTROL STRUCTURES IN A PROGRAM (DECISIONS)


Some programs involve making a decision to determine the next step. In such a case, we represent the
decision making with an IF statement in a pseudo code and a decision box (diamond or rhombus) in the
flowchart. In the decision box there is always a question which starts with the word “IS”.
IF statements
There are three forms of IF statements and these are:
(a) IF – THEN statement
(b) IF – THEN – ELSE statement
(c) IF – THEN – ELSE – IF statement.
However, we will only concentrate with the first two.

(a) The IF – THEN statement is used when only one option is available. Its structure is as shown
below.
Indicates the
start of the
IF < 𝒄𝒐𝒏𝒅𝒊𝒕𝒊𝒐𝒏 > THEN YES
selection Condition Program statement
structure
Statement (s)
(Decision)
NO
END IF
Indicates the end/termination of the selection.

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 6


A practical example of “only one option is available” could be, when you send someone with your
ZANACO visa ATM card to withdraw money from a ZANACO ATM machine. If this person finds
that the ZANACO system is down, you expect that person to come back without the money that you
sent them to withdraw, right? Here there is only one option.
But had you given that person another option to withdraw from any other Bank’s ATM machine in a
case where the ZANACO system was down since the card is visa, then the case would have been
different. Here there are two options.

Example 6.
The program below is given in form of a pseudo code which calculates a discount of 15% for
customers buying goods worth more than K500.
Start
Enter amount
IF amount > K500 THEN
Discount = 𝐴𝑚𝑜𝑢𝑛𝑡 ∗ 0.15
END IF
Display Discount
Stop.
Write a flowchart corresponding to the pseudo code above.
Solution.
Clearly from the program above, there is only one option when it comes to calculation of discount
which is buying goods worth more than K500.

Start

Enter Amount

Is
Amount > 𝐾500? NO

YES

Discount = Amount ∗ 0.15

Display Discount

Stop

Note that the word “IF” becomes “IS” in the decision box.

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 7


(b) The IF – THEN – ELSE statement is used if only two options are available. Its structure is as
shown below.

IF < 𝑐𝑜𝑛𝑑𝑖𝑡𝑖𝑜𝑛 > THEN Program NO YES Program


Condition
Statements (s) Statement Statement
ELSE
Statements (s)
END IF

Example 7
The program below is given in form of a pseudo code which calculates a discount of 15% for customers
buying goods worth more than K500 and 10% for those buying goods worth K500 and less.
(a) Write a flowchart that corresponds to the program below.
Solution
Start
Enter Amount
Start
IF Amount > K500 THEN
Discount = 𝐴𝑚𝑜𝑢𝑛𝑡 ∗ 0.15
ELSE
Enter Amount
Discount = 𝐴𝑚𝑜𝑢𝑛𝑡 ∗ 0.10
END IF
Display Discount
Stop Is
YES
Amount > K500? Disc= 𝐴𝑚𝑜𝑢𝑛𝑡 ∗ 0.15

NO

Disc= 𝐴𝑚𝑜𝑢𝑛𝑡 ∗ 0.10

Display Discount

Stop

(b) How much discount will a customer buying goods worth K800 get?
SOLUTION
Since K800 is greater than K500, then:
Discount = 𝐴𝑚𝑜𝑢𝑛𝑡 × 0.15
= K800 × 0.15
= 𝐊𝟏𝟐𝟎

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 8


Example 8
Study the flowchart below and write a pseudo code corresponding to the program.

Start

Enter a, b, c

𝐷 = 𝑏∗𝑏−4∗𝑎∗𝑐

Is D < 0? Print “No real solutions”

𝑥1 = (−𝑏 + √𝐷)/2 ∗ 𝑎

𝑥2 = (−𝑏 − √𝐷)/2 ∗ 𝑎

Print 𝑥1 , 𝑥2

Stop

SOLUTION
Start
Enter a, b, c
D=b∗b−4∗a∗c
IF D < 0 THEN
Print “No real solution”
ELSE

𝑥1 = (−𝑏 + √𝐷)/2 ∗ 𝑎

𝑥2 = (−𝑏 − √𝐷)/2 ∗ 𝑎

END IF
Print 𝑥1 , 𝑥2
Stop

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 9


REVISION EXERCISE 1 - ECZ GRADE 9 PAPER 2 (2015 TO 2022)
1. Given the length 𝑙 and breadth 𝑏 of a rectangle, write a simple program to calculate and output
the area, A, of a rectangle.
2. Given that the base of the triangle is b and its perpendicular height is h, complete the flow Chart
below, which is for calculating and displaying its area A.

3. Given three numbers x, y and z, complete the flow chart below to calculate the mean (M) of the
numbers.
START

STOP

4. Given the distance (D) covered by a car and the time (T) the car takes to cover this distance,
complete the flow chart below for calculating and displaying its average speed (S).

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 10


Start

Stop

5. Given that the base radius of a cylinder is r and its height is h, complete the flow chart below for
calculating and displaying its Volume V.

Start

Stop

6. Given the density (D) of a stone and its mass (M), complete the flow chart for calculating and
displaying the volume (V).
Start

Stop

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 11


7. Given the principal (P), the rate of interest per annum (R) and time (T), complete the flow chart
below for calculating and displaying simple interest (I).
Start

Stop

8. Construct a flow chart for a program that can determine whether a given number is positive or
negative.

9. Given the mass (M), and the volume (V) of an object, complete the flow chart below for
𝑀
calculating and displaying the density (D). 𝐷 =
𝑉

Start

Stop

10. Given the radius (r) and height (h), complete the flow chart below for calculating and displaying
the curved surface area (A) of a cylinder. [𝐴 = 2𝜋𝑟ℎ]

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 12


Start

Stop

11. Study the flow chart below to answer the question that follows.

Start

Enter x

𝑦 =7∗𝑥−3

Display y

Stop

Using the program above, complete the table below.

𝑥 𝑦
2
32

12. Given the height (h) of a triangle and its base (b), complete the steps below for calculating and
1
displaying its area (A). [𝐴 = 2 𝑏ℎ]

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 13


Start
Enter……………………..
A = ………………............
Display…………………..
Stop

13. Given the length (l) of a rectangle and its area (A), complete the steps below for calculating and
displaying the breadth (b).

Start
Enter …………………………..
b = ……………………………..
Display ………………………
Stop

REVISION EXERCISE 2 - ECZ GRADE 12 PAPER 2 (2016 TO 2022)


1. The programme below is given in the 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
1
Else Volume = 3 ∗ 𝜋 ∗ square radius ∗ height
End if
Display volume
Stop

Draw the corresponding flowchart for the information given above.

2. The program below is given in the form of a flow chart. Write a pseudo code corresponding to
the program.

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 14


Start

Enter a, r

Is
𝑟 < 0? No

Yes
𝑎
𝑆∞ =
1−𝑟

Display sum to infinity

Stop

3. Study the flow chart below.

Start

Enter r

Is Yes
r < 0? Error “r must be positive”

No
1
A = 2 ∗ 𝑟 ∗ 𝑟 ∗ sin 𝜃

Display Area
Write a pseudo code corresponding to the flow chart
program alongside.
Stop

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 15


4. Study the pseudo code below. 5. The programme below is given pseudo code.

Start Start
Enter a, r, n Enter x, y
R=1−𝑟 Let M = square root (x squared + y squared)
If R = 0 THEN IF M < 0
Print “the value of r is not valid” THEN display error message “M must be positive”
𝑛)
Else 𝑆𝑛 = 𝑎(1 − 𝑟 𝑅 ELSE
End if END IF
Print 𝑆𝑛 Display M
Stop Stop

Construct a flow chart corresponding to Draw the corresponding flow chart for the information
the pseudo code above. given above.

6. The flow chart below shows the steps in calculating the volume of a solid given the base area
(A) and the height (h). Write a pseudo code corresponding to the program.

Start

Enter A

Is A < 0? Yes “error message” A


must be positive.

No
Enter h

Yes “error message” h


Is h < 0?
must be positive.

No

V = A*h

Display V

Stop

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 16


7. The programme below is given in the form of a pseudo code.

Begin
Enter length
If length < 0
Then display “error message and re-enter positive length
Else enter height
If height < 0
Then display “error message” and re-enter positive height
1
Else volume = ∗ 𝑙 ∗ 𝑙 ∗ ℎ
3
End if
Display volume
End

Draw the corresponding flowchart for the information given above.

8. The programme below is given in the form of a pseudo code.

Start
Enter radius
If radius < 0
Then display “error message” and re-enter positive radius
Else enter slant height
If slant height < 0
Then display “error message” and re-enter positive slant height
Else Area = 𝜋 ∗ 𝑟 ∗ (𝑟 + 𝑠𝑙𝑎𝑛𝑡 ℎ𝑒𝑖𝑔ℎ𝑡)
End if
Display Area
Stop

Draw the corresponding flow chart for the information given above.

9. Study the flow chart below and write a pseudo code corresponding to it.

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 17


Start

Enter l

Is Yes
l < 0? Error” l must be positive”

No
Enter h

Is Yes
h < 0? Error” h must be positive”

No

Volume =1/3*l^2*h

Display volume

Stop

10. The programme below is given in the form of a pseudo code.

Start
Enter length
If length < 0 THEN
Display error message “length must be positive”
Else enter height
If height < 0 THEN
Display error message “height must be positive”
1
Else volume = 3 ∗ 𝑙𝑒𝑛𝑔𝑡ℎ ^3 ∗ ℎ𝑒𝑖𝑔ℎ𝑡
End if
Display volume
Stop

Draw a corresponding flowchart for this pseudo code.

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 18


11. Study the flowchart below.

Start

Enter 𝑥

Is
Yes Print error “𝑥 must
𝑥 < 0?
be positive”

No

𝑟 = 𝑅 ∗ cos 𝑥

Display r

Stop

Write a pseudo code corresponding to the flowchart programme.

12. Study the following pseudo code.

Start
Enter R, r, l
IF r > R THEN
Print “Error the value of r is not valid”
ELSE S = 𝜋 ∗ (𝑅 + 𝑟) ∗ 𝑙
END IF
Print S
Stop

Construct a flowchart corresponding to the pseudo code above.

COMPUTER MATHEMATICS BY BUUMBA, P - 0979633656 19

You might also like