Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
88 views20 pages

Computer Pseudo Codes and Flow Charts Algorithm

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

Mulonga Mathematics Tuitions Online

Add WhatsApp 0955937864 For Lessons

LESSON 1 PAGE 1
COMPUTER PSEUDO CODES AND FLOW CHARTS
INTRODUCTION
Algorithm
An algorithm is a procedure or formula for solving a problem.
Often used for calculation, data processing and programming
Pseudo code
A pseudo code is an English like representation of
logical steps it takes to solve a problem (List of steps
written in English)
 Begins and ends with terminals (start and stop)
 Each step represents an activity (input, process, decision
and output)
 No punctuations at the end of the statements
 Statements are indented but terminals are lined
From here connect to page 2

1
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

LIKE INSTRUCTIONS FOR MAKING A CUP OF TEA PAGE 2


Must be in the right sequence e.g.
 Organize everything together
 Put water into the kettle
 Plug in kettle into AC socket
 Wait for water to boil
 Put tea a bag in the cup
 Pour water into the cup
 Remove the tea bag with spoon/fork
 Add milk/or sugar
 Stir using a spoon
 Serve
From here connect to page 3

SAMPLE PSEUDO CODE PAGE 3


 Task: add two numbers
 Pseudocode:
 Start
 Get two numbers
 Input numbers
 Add them
 Print the answer
 End
From here connect to page 4

2
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

FLOWCHART PAGE 4
 A flowchart is a graphical representation of an algorithm.
 It is a diagram made up of shapes connected by arrows.
 Each shape represents a step in the process, and the
arrows show the order in which they occur.
General Rules for flowcharting
a. All boxes of the flowchart are connected with Arrows. (Not
lines)
b. Flowchart symbols have an entry point on the top of the
symbol with no other entry points.
c. The exit point for all flowchart symbols is on the bottom
except for the Decision symbol.
d. The Decision symbol has two exit points; these can be on
the sides or the bottom and one side.
e. Generally a flowchart will flow from top to bottom.
From here connect to page 5
FLOW CHART SYMBOLS AND FUNCTIONS page 5

From here connect to page 6

3
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

FLOWCHART SYMBOL OVAL PAGE 6


 Also called Terminals
 START/END/STOP

 Used at the beginning and end of each flowchart.

FLOWCHART SYMBOL PARALLELOGRAM


 INPUT/OUTPUT

 Shows when information/data comes into a


program or is printed out.
 Uses other words like
 Show
 Display
 Write
From here connect to page 7

4
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

FLOWCHART SYMBOL RECTANGLE PAGE 7


 PROCESS

 Used to show calculations, storing of data in variables,


and other “processes” that take place within a program.
FLOWCHART SYMBOL RHOMBUS OR DIAMOND
 DECISION

 Used to show that the program must decide whether


something (usually a comparison between numbers) is
true or false. YES and NO (or T/F) branches are usually
shown.
FLOWCHART SYMBOL FLOW LINE

 It is used to connect from one stage to another


From here connect to page 8

5
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

EXAMPLE OF A FLOW CHART PAGE 8


The flow chart for the pseudo code page 4 would look like this
as a flowchart:

END OF LESSON 1

6
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

LESSON 2 PAGE 1
COMPUTER PSEUDO CODES AND FLOW CHARTS
Operations and meanings used in flow charts

From here connect to page 2

7
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

QUESTIONS PAGE 2
1. Write a pseudo code for calculating an average of three
numbers.
2. Write a flow chart for the pseudo code you wrote in
question 1
3. Write a pseudo code that inputs two numbers (a and b)
and output the largest number.
4. Write a flow chart for the pseudo code you wrote in
question 3
Copy the question above, scroll down for answers and listen to
possible audios following each answer page
SOLUTION 1 PAGE 3
TASK: FINDING AVERAGE OF THREE NUMBERS

 PSUEDO CODE
 Start
 Select numbers of X, Y, Z
 S=X+Y+Z
 A = S/3
 Write value of A
 Stop
From here connect to page 4

8
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

SOLUTION 2 PAGE 4

From here connect to page 5

SOLUTION 3 PAGE 5
TASK: TWO NUMBERS OUTPUTTING A LAGER NUMBER
Start
INPUT a
INPUT b
IF a < b THEN
OUTPUT b
ELSE
OUTPUT a
Stop
From here connect to page 6

9
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

SOLUTION 4 PAGE 6

END OF LESSON 2

10
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

LESSON 3 PAGE 1
COMPUTER PSEUDO CODES AND FLOW CHARTS
1. Given that a right angled triangle has height and base .
a. Come up with a pseudo code for calculating area of this
triangle.
b. Draw a complete flow chart for the calculation of area.
2. The tax threshold for government employees is K2, 000 for
the tax rate of 0.1%.
a. Create a pseudo code for this threshold.
b. Draw a complete flow chart for this threshold.
c. Calculate the tax for
i. Income of K1, 850
ii. Income of K2, 700
Copy the question above, scroll down for answers and listen to
possible audios following each answer page

11
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

SOLUTION 1 a. PAGE 2
TASK: CACULATING AREA OF A RIGHT ANGLED TRIANGLE
 Pseudo code

o Start

o Input b, h

o Calculate area

o Output area

o End

From here connect to page 3

SOLUTION 1 b. PAGE 3

From here connect to page 4

12
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

SOLUTION 2 a PAGE 4
TASK: CALCULATE TAX THRESHOLD
 Pseudo code

o Start

o Input Income

o IF Income 2000 THEN

TAX 0

ELSE

CALCULATE TAX

o Print tax

o End

From here connect to page 5

13
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

SOLUTION 2 b. PAGE 5

From here connect to page 6

14
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

SOLUTION 2 c. i. PAGE 6
Income = 1 850
In this case, yes income is less than 2000

SOLUTION 2 c. ii
Income = 2700

Subtract inside brackets

Multiply on the right

End of lesson 3

15
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

LESSON 4 PAGE 1
COMPUTER PSEUDO CODES AND FLOW CHARTS
1. Write a pseudo code to calculate age, if older than 50 years
print old.

2. Draw a flow chart for the pseudo code in question 1.

3. Write a pseudo code that inputs two letters (F and P) and


output F for fail IF marks are less than 35 other wise print P
for pass.

4. Draw a flow chart for the pseudo code in question 3.


Copy the question above, scroll down for answers and listen to
possible audios following each answer page

16
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

SOLUTION 1 PAGE 2
TASK: CALCULATING AGE
 Pseudo code

o Start

o Get year born

o Calculate age

o Print age

o If age > 50 print OLD

o End

From here connect to page 3

17
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

SOLUTION 2 PAGE 3
 PSEUDO CODE

From here connect to page 4

18
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

SOLUTION 3 PAGE 4
TASK: DETERMINING FAIL AND PASS
 Pseudo code

o Start

o Input marks x

o If x < 35 THEN

Output F

ELSE

Output P

o End

From here connect to page 5

19
Mulonga Mathematics Tuitions Online
Add WhatsApp 0955937864 For Lessons

SOLUTION 4 PAGE 5
 PSEUDO CODE

END OF LESSON 4

20

You might also like