Mada za sehemu hiiDesigning of computer programsMada 3
- Demonstrating application tools and environment used in programming
- Constructing pseudo-code and flow charts
- Implementing basic computer programming
Constructing Pseudo-code and Flow Charts
Pseudo-code and flow charts are tools used in computer program design. They help us describe the solution to a problem using ordinary human language instead of a programming language. Before writing actual code, programmers first plan their logic using these tools because they are easy to understand and can be shared with anyone, even without programming knowledge.
Definition
Pseudo-code is a set of logical instructions written in plain language to solve a specific problem. It serves as an entry point to computer programming. A good pseudo-code must be self-explanatory—clear enough that someone else can read and understand the steps even without the writer present.
Structure of Pseudo-code
Every pseudo-code follows a specific structure with six main parts:
- Start – Marks the beginning of the program and states the program's objective
- Declaration of Variables – Lists all input and output variables that will be used
- Variable Initialization – Assigns or receives values for input variables
- Processing – Performs calculations, conditions, and manipulations to get the result
- Display – Shows or prints the output
- Stop – Ends the program
Worked Example 1: Summation of Two Integers
Write pseudo-code to compute and print the sum of two integers (with given values).
Start (summation)
Declaration of integer variables:
Inputs: num1, num2
Output: sum
Initialization of variables: num1 = 5; num2 = 7;
Processing: sum = num1 + num2;
Display: sum;
Stop;
Worked Example 2: Summation with User Input
Write pseudo-code to read two numbers from a user, compute and print their sum.
Start (summation)
Declaration of integer variables:
Inputs: num1, num2
Output: sum
Initialization of variables: Read num1; Read num2;
Processing: sum = num1 + num2;
Display: sum;
Stop;
Definition
A flow chart is a pictorial (visual) representation of pseudo-code. It uses shapes called symbols to show each step of the program, making it easy to follow the flow of logic from start to finish.
Basic Flow Chart Symbols

| Symbol | Name | Purpose |
|---|---|---|
| ○ | Terminal (Oval) | Shows the start or end of a program |
| ▭ | Process (Rectangle) | Shows a processing step or calculation |
| ◊ | Input/Output (Parallelogram) | Shows input (reading data) or output (displaying results) |
| ◇ | Decision (Diamond) | Shows a condition that leads to a yes/no or true/false branch |
| ○ | Connector | Connects different parts of the flowchart |
| ▭ with double lines | Predefined Process | Shows a previously defined process or subroutine |
Worked Example 1: Area of a Circle

Draw a flow chart to calculate the area of a circle (Area = 3.14 × r × r).
Start
◊ Read rad (input)
▭ Area = 3.14 * rad * rad (process)
◊ Print Area (output)
Stop
Worked Example 2: Fahrenheit to Celsius Conversion
Draw a flow chart to convert temperature from Fahrenheit to Celsius.
Formula: C=95×(F−32)
Start
◊ Read F (input)
▭ C = (5/9) * (F - 32) (process)
◊ Print C (output)
Stop
Control structures determine the flow of program execution. There are two main types: condition statements and loop structures.
Condition Statements
Condition statements execute different actions based on whether a condition is true or false.
Single-Choice If Statement
Syntax:
if (Condition) then:
[Expression A]
Else:
[Expression B]
End if;
Worked Example: Check User Gender
Write pseudo-code to accept user input and display the user's gender.
Start
Declaration of variables:
Input: Gender
Initialization:
Read Gender
Processing:
if (Gender == 'Male') then:
Print: "Your gender is Male"
Else:
Print: "Your gender is Female"
End if
Stop
Finding the Greatest of Two Numbers
Start
Declaration of variables:
Num1, Num2 as numbers
Initialization:
Read Num1, Num2
Processing:
if (Num1 > Num2) then:
Print: Num1
Else:
Print: Num2
End if
Stop
Multiple-Choice If Statement (If-Else-If)
When there are more than two options, use this structure:
if (Condition A) then:
[Expression A]
Else if (Condition B) then:
[Expression B]
Else if (Condition N) then:
[Expression C]
Else:
[Expression D]
End If
Switch Case Statement
The switch case is an alternative to multiple if-else statements. It checks one variable against multiple values.
Syntax:
Switch (expression) {
case value-1:
Block-1;
Break;
case value-2:
Block-2;
Break;
case value-n:
Block-n;
Break;
default:
Default-block;
Break;
}
Worked Example: Print Number Description
Write pseudo-code to accept a number and print its description.
Start
Declaration of variables:
Num as number
Initialization:
Read Num
Switch (Num) {
case 7:
Print: "Seven"
Break;
case 8:
Print: "Eight"
Break;
case 9:
Print: "Nine"
Break;
default:
Print: "Out of range"
Break;
}
Stop
Scenario 1: Bakery Order System
A bakery sells pastries at different prices. Write pseudo-code to calculate the total price for customer orders.
Start (Bakery Order System)
Declaration of variables:
PastryType as string
Quantity as integer
Price as number
Total as number
Initialization:
Read PastryType
Read Quantity
Processing:
if (PastryType == 'Mandazi') then:
Price = 500
else if (PastryType == 'Samosa') then:
Price = 1000
else if (PastryType == 'Bread') then:
Price = 3000
else:
Price = 0
End if
Total = Price * Quantity
Display:
Print Total
Stop
Scenario 2: Calculate Average of Three Numbers
Write pseudo-code to calculate the average of three numbers.
Start (Calculate Average)
Declaration of variables:
Num1, Num2, Num3 as numbers
Average as number
Initialization:
Read Num1
Read Num2
Read Num3
Processing:
Average = (Num1 + Num2 + Num3) / 3
Display:
Print Average
Stop
Scenario 3: User Login Verification
Write pseudo-code to verify user credentials before granting website access.
Start (Login Verification)
Declaration of variables:
Username as string
Password as string
CorrectUser as string
CorrectPass as string
Initialization:
Read Username
Read Password
CorrectUser = "admin"
CorrectPass = "1234"
Processing:
if (Username == CorrectUser AND Password == CorrectPass) then:
Print: "True - Access Granted"
Else:
Print: "False - Credentials Incorrect"
End if
Stop
Scenario 4: Running Sum Game
Write pseudo-code for a game where users enter numbers that keep adding up. When a negative number is entered, the game stops and displays the total sum.
Start (Running Sum Game)
Declaration of variables:
Number as number
Sum as number
Initialization:
Sum = 0
Processing:
Repeat:
Read Number
if (Number >= 0) then:
Sum = Sum + Number
End if
Until (Number < 0)
Display:
Print Sum
Stop
In Tanzania, pseudo-code and flow charts are used by small business owners and market vendors to plan how to calculate customer orders and manage daily sales. For example, a shop owner at Kariakoo Market in Dar es Salaam can use pseudo-code logic to design a simple system that adds up prices of items a customer buys, applies a discount if the total exceeds TSh 50,000, and prints the final amount—helping the shopkeeper serve customers faster and avoid calculation mistakes.
Jinsi utakavyotathminiwaTathmini ya mchakato · Tathmini ya matokeo · Tathmini ya maarifa
Tathmini ya mchakato
The student should be able to:
- Understand problem statements and decompose them intological steps.
- Write clear and logically correct pseudo-code.
- Design accurate and readable flowcharts representing program logic.
- Use appropriate symbols and conventions for flowcharts.
Tathmini ya matokeo
Pseudo-code and flow that provides a clear and logical representation of program are constructed.
Tathmini ya maarifa
Methods used: The trainee should explain how to:
- Break down a problem into logical steps for pseudo-code and flowchart construction.
- Use standard flowchart symbols and structures.
- Ensure consistency between pseudocode and flowcharts.
Principles: The student should explain the principle of:
- Problem-solving techniques in programming.
- Logical sequencing and decision-making in program design
Theories: The trainee should explain: The trainee should explain:
- The role of pseudo-code and flowcharts in planning and debugging programs.
- How clear visual representation aids in understanding and communication of program logic.
Detailed knowledge about:
- Common errors in pseudo-code and flowchart design and how to avoid them.
- Best practices for aligning pseudocode with standard programming syntax.
- Tools and resources available for creating and sharing flowcharts.
Swali
Which of the following represents the correct order of the six parts in a pseudo-code structure?
Ingia ili kuwasilisha jibu lako na lihesabiwe katika umahiri wako.
Ingia ili kufanya mazoeziMwalimu
Umekwama? Niulize chochote kuhusu mada hii.
Ingia ili kumuuliza Mwalimu wa AI wa Sonza kuhusu swali hili.
Ingia ili kuulizaMajadiliano
Hakuna maswali bado