Learning Objectives
By the end of this lesson, you will be able to:
- Draw basic program flowcharts that demonstrate decision-making processes
- Edit and modify given flowcharts to correct errors or improve logic
- Design flowcharts to solve specific computational problems
- Identify and correctly use flowchart symbols: input/output, decision, terminator, process boxes, subroutine, connector, and flow lines
- Identify errors in algorithms and program flowcharts for given scenarios
- Create trace tables to follow flowchart execution with test data
- Convert between pseudocode, algorithms, and flowchart representations
- Implement and write Cambridge-style pseudocode from given flowcharts or structured English
- Write pseudocode statements for declaring variables and constants, assignments, expressions, and input/output operations
Key Terms
Flowchart
A diagrammatic way of representing an algorithm used to produce the solution to a problem
Terminator
Symbol used to show where a flowchart begins (START) and where it ends (STOP)
Process Box
Rectangle symbol representing any calculation or variable assignment (uses ← symbol)
Input/Output
Parallelogram shape representing input or output operations (equivalent to INPUT or PRINT)
Decision Box
Diamond shape representing conditional statements (IF) or loops, with Yes/True and No/False branches
Subroutine
Symbol used to call a subroutine from the main flowchart (equivalent to CALL statement)
Flow Line
Arrow lines showing the direction to follow when working through a flowchart
Connector
Circle symbol indicating continuation of a flowchart across multiple pages
Algorithm
A step-by-step procedure or formula for solving a problem
Trace Table
A table used to track variable values and outputs as an algorithm executes step by step
Sequence
The simplest programming construct where instructions are executed one after another
Test Data
Data used to test a program, including normal, abnormal/erroneous, and boundary/extreme cases
Pseudocode
A simplified programming language used to design algorithms, following Cambridge conventions
Structured English
A restricted subset of English used to describe algorithms in a clear, unambiguous way
Flowchart Fundamentals
A program flowchart is a diagrammatic way of representing an algorithm used to produce the solution to a problem. Flowcharts help visualize the logic and flow of a program before writing actual code.
Flowchart Symbols
Standard Flowchart Symbols
Symbol Details:
- Terminator: Oval shape showing where flowchart begins and ends
- Process Box: Rectangle representing calculations or variable assignments (uses ← symbol)
- Input/Output: Parallelogram equivalent to INPUT or PRINT statements
- Decision Box: Diamond shape with Yes/True and No/False branches
- Subroutine: Symbol used to call a subroutine (equivalent to CALL)
- Flow Line: Arrows showing direction through the flowchart
- Connector: Circle indicating flowchart continuation across pages
Real-Life Analogy:
Think of a flowchart like a recipe for cooking:
- Terminator: "Start cooking" and "Serve meal"
- Process Box: "Chop vegetables", "Mix ingredients"
- Input/Output: "Add 2 cups of flour", "Taste the sauce"
- Decision Box: "Is the pasta cooked?" → Yes/No branches
- Subroutine: "Make the sauce" (a separate procedure)
- Flow Lines: The order of steps in the recipe
Flowchart Symbols Interactive Guide
Drag and drop flowchart symbols to build a simple algorithm. This simulation helps you understand how different symbols connect to form a complete flowchart.
How to use: Drag symbols from the palette to the canvas. Connect them in logical order to create algorithms like "Check if a number is positive" or "Calculate average of three numbers".
Example: Weather Decision Flowchart
Flowchart Description:
- START
- Check the Weather Channel
- Decision: Rain Predicted? (Yes/No)
- If Yes: Stay Home
- If No: Play Golf
- STOP
This is a simple sequence with one decision point. The Weather Channel is a Cable Channel.
Real-Life Example: Mobile App Login Flowchart
Most mobile apps use flowcharts to design their user experience. Here's a simplified login process:
This flowchart helps developers visualize the login process before writing code, ensuring all cases (valid/invalid credentials, remember me option) are handled.
Check Your Understanding: Flowchart Fundamentals
1. What shape is used for a decision box in a flowchart? [1 mark]
Answer
- [1 mark] Diamond shape
- [Additional] The diamond has two arrows coming out: one for Yes/True and one for No/False
2. What is the purpose of a terminator symbol? [2 marks]
Answer
- [1 mark] To show where the flowchart begins (START)
- [1 mark] To show where the flowchart ends (STOP)
- [Additional] Usually oval-shaped, marks entry and exit points of the algorithm
3. Which flowchart symbol represents input or output operations? [1 mark]
Answer
- [1 mark] Parallelogram shape
- [Additional] Equivalent to INPUT or PRINT statements in pseudocode
4. When would you use a connector symbol in a flowchart? [2 marks]
Answer
- [1 mark] When a flowchart extends over multiple pages
- [1 mark] To indicate continuation points between pages
- [Additional] Usually a circle with a letter or number inside to match corresponding connectors
5. What is the difference between a process box and an input/output symbol? [2 marks]
Answer
- [1 mark] Process box: Rectangle used for calculations and variable assignments (uses ←)
- [1 mark] Input/Output: Parallelogram used for reading input or displaying output
- [Additional] Example: "X ← Y + Z" goes in process box, "INPUT name" goes in input/output symbol
Drawing and Interpreting Flowcharts
Flowcharts visually represent algorithms. Being able to draw and interpret them is essential for designing, understanding, and debugging programs.
Example: Profit/Loss Calculation
Problem Description:
Read Cost Price (CP) and Selling Price (SP). Determine if there's a profit or loss.
- Read CP
- Read SP
- If SP > CP then Profit = SP - CP
- Otherwise Loss = CP - SP
- End
Trace Example:
When CP = 325 and SP = 458:
- Condition: Is 458 > 325? → Yes
- Profit = 458 - 325 = 133
- Result: Profit = Rs. 133
Activity 1: Trace Table Practice
Complete the trace table for the following flowchart using test data: 9, 7, 3, 12, 6, 4, 15, 2, 8, 5
| A | B | C | X | Output |
|---|---|---|---|---|
| 0 | 0 | 100 | ||
| 1 | 9 | 9 | ||
| 2 | 7 | 7 | ||
| 3 | 3 | 3 | ||
| 4 | 12 | 12 | ||
| 5 | 6 | |||
| 6 | 4 | |||
| 7 | 15 | 15 | ||
| 8 | 2 | 2 | ||
| 9 | 8 | |||
| 10 | 5 | |||
| 15 |
Flowchart Logic:
Solution:
| A | B | C | X | Output |
|---|---|---|---|---|
| 0 | 0 | 100 | ||
| 1 | 9 | 9 | 9 | |
| 2 | 9 | 7 | 7 | |
| 3 | 9 | 3 | 3 | |
| 4 | 12 | 3 | 12 | |
| 5 | 12 | 3 | 6 | |
| 6 | 12 | 3 | 4 | |
| 7 | 15 | 3 | 15 | |
| 8 | 15 | 2 | 2 | |
| 9 | 15 | 2 | 8 | |
| 10 | 15 | 2 | 5 | |
| 15, 2 |
Explanation: The algorithm finds the maximum (B) and minimum (C) values from 10 inputs. B tracks the highest value seen, C tracks the lowest. Final output is B=15, C=2.
Flowchart with Subroutine
Pseudocode:
What this algorithm does:
- Calculates area of one triangle using subroutine
- Then calculates areas of multiple rectangles using a loop
- Uses a WHILE loop with counter (count)
- Demonstrates subroutine calls within a flowchart
Activity 2: Draw a Flowchart
Draw a flowchart to add up five numbers.
Pseudocode provided:
Note: There's an error in the pseudocode - it should INPUT Num inside the loop!
Draw the correct flowchart that:
- Initializes count and total to 0
- Uses a loop to input 5 numbers
- Adds each number to the total
- Outputs the final sum
Solution Flowchart:
Key points: The loop continues while count < 5 (0-4 = 5 iterations). We INPUT a number inside the loop, add it to total, then increment count. The pseudocode is missing the INPUT statement inside the loop.
Real-Life Example: Online Shopping Checkout Flowchart
Most e-commerce websites use complex flowcharts to design their checkout process:
This flowchart ensures all cases are handled: user authentication, address validation, payment processing, and error handling.
Check Your Understanding: Drawing & Interpreting
1. What does the following flowchart find? [2 marks]
Start → A=0, B=0, C=100 → Loop: Input X → If X>B then B=X → If X=10 → Output B,C
Answer
- [1 mark] Finds the maximum value (stored in B) from 10 inputs
- [1 mark] Finds the minimum value (stored in C) from 10 inputs
- [Additional] B starts at 0, C starts at 100. After processing 10 numbers, B contains the highest, C contains the lowest.
2. What is wrong with the pseudocode in the "Add up five numbers" example? [2 marks]
Answer
- [1 mark] There is no INPUT statement to read the numbers
- [1 mark] The variable "Num" is used in the calculation but never assigned a value
- [Additional] Corrected version should have "INPUT Num" inside the while loop before adding to total
3. How many times will the loop execute in the triangle/rectangle example? [2 marks]
count ← 0, WHILE count < number, ... , count ← count + 1
Answer
- [1 mark] The loop executes "number" times
- [1 mark] Count starts at 0, increments by 1 each time, loop continues while count < number
- [Additional] If number=5: count=0,1,2,3,4 (5 iterations). When count=5, condition fails, loop stops.
4. What would be the output of the profit/loss flowchart with CP=200, SP=150? [2 marks]
Answer
- [1 mark] Condition: Is SP > CP? 150 > 200? → No
- [1 mark] Loss = CP - SP = 200 - 150 = 50
- [Additional] Since selling price (150) is less than cost price (200), there's a loss of 50.
5. Identify three types of test data [3 marks]
Answer
- [1 mark] Normal test data
- [1 mark] Abnormal / erroneous / invalid test data
- [1 mark] Boundary / extreme test data
- [Additional] 5: "A programmer can use three types of test data when testing a program"
Exam-Style Flowchart Questions
Exam questions often ask you to draw flowcharts based on algorithm descriptions or identify errors in given flowcharts.
Example: Prime Number Counter
Algorithm Description:
- Input an integer value.
- Jump to step 6 if the value is less than zero.
- Call the function IsPrime() using the integer value as a parameter.
- Keep a count of the number of times function IsPrime() returns TRUE.
- Repeat from step 1.
- Output the value of the count with a suitable message.
What this algorithm does:
- Continuously reads integers until a negative number is entered
- For each non-negative number, checks if it's prime using IsPrime() function
- Counts how many prime numbers were entered
- When a negative number is entered, stops and outputs the count
- Uses a sentinel value (negative number) to terminate input
Common Flowchart Errors to Avoid
Structural Errors:
- Missing terminators - No START or STOP symbols
- Incorrect symbol shapes - Using rectangle for decision or parallelogram for process
- Unconnected flow lines - Gaps between symbols
- Crossing flow lines - Makes the flowchart hard to follow
- Missing decision branches - Only showing Yes or No path, not both
Logic Errors:
- Infinite loops - No way to exit the loop
- Incorrect loop conditions - Wrong comparison or counter update
- Missing initialization - Variables not set before use
- Wrong order of operations - Processing before input or vice versa
- Off-by-one errors - Looping one time too many or too few
Exam Tip: How to Check Your Flowchart
- Trace with sample data - Walk through with simple test values
- Check all paths - Ensure every Yes/No branch leads somewhere valid
- Verify loop exit - Make sure loops can terminate
- Test boundary cases - What happens with minimum/maximum values?
- Use correct symbols - Examiners check symbol shapes carefully
Exam Question Practice
Exam-Style Question: A school library system needs a flowchart for checking out books. The process is:
Algorithm:
- Start
- Input StudentID and BookID
- Check if StudentID is valid (call ValidateStudent subroutine)
- If invalid, output "Invalid Student ID" and stop
- Check if BookID is available (call CheckAvailability subroutine)
- If not available, output "Book not available" and stop
- Update records (call UpdateRecords subroutine)
- Output "Book checked out successfully"
- Stop
Draw a flowchart for this library checkout system. Include all symbols: terminators, input/output, decisions, process boxes, and subroutines.
Solution Flowchart:
Key features: Uses three subroutines (ValidateStudent, CheckAvailability, UpdateRecords). Has two decision points with error handling. Shows both successful and unsuccessful paths. All symbols are correctly shaped.
Converting Between Flowcharts and Pseudocode
Flowchart Symbol → Pseudocode
| Flowchart Symbol | Pseudocode Equivalent |
|---|---|
| Terminator (START/STOP) | Beginning/end of algorithm |
| Input/Output (Parallelogram) | INPUT or OUTPUT/PRINT statements |
| Process Box (Rectangle) | Assignment statements (variable ← value) |
| Decision (Diamond) | IF...THEN...ELSE or WHILE conditions |
| Subroutine | CALL statement |
| Flow Lines | Sequence of execution |
Example Conversion:
Check Your Understanding: Exam Preparation
1. In the prime number counter algorithm, what triggers the output? [2 marks]
Answer
- [1 mark] When a negative number is input
- [1 mark] The negative number acts as a sentinel value to terminate input
- [Additional] The algorithm says: "Jump to step 6 if the value is less than zero"
2. What type of loop is used in the "Add up five numbers" flowchart? [1 mark]
Answer
- [1 mark] Count-controlled loop (WHILE loop with counter)
- [Additional] The loop executes exactly 5 times, controlled by "count < 5" condition
3. Why is initialization important in flowcharts? [2 marks]
Answer
- [1 mark] Ensures variables start with known values before use
- [1 mark] Prevents errors from uninitialized variables (garbage values)
- [Additional] Example: In "Add five numbers", total must start at 0 before adding numbers
4. How would you modify the profit/loss flowchart to handle zero profit? [2 marks]
Answer
- [1 mark] Change decision from "SP > CP" to "SP >= CP"
- [1 mark] Or add another decision: If SP = CP then output "No profit, no loss"
- [Additional] Current flowchart treats SP = CP as loss (since SP > CP is false), which is incorrect
5. What is the purpose of a trace table? [2 marks]
Answer
- [1 mark] To track variable values as an algorithm executes step by step
- [1 mark] To verify algorithm correctness and identify logic errors
- [Additional] Used for debugging and understanding how algorithms work with specific test data
Cambridge Pseudocode Implementation
Cambridge pseudocode is a standardized way to represent algorithms using a structured, programming-like syntax that follows Cambridge International conventions. It bridges the gap between flowcharts/structured English and actual programming code.
Cambridge Pseudocode Syntax Rules
1. Declaration and Initialization
2. Assignment Statements
3. Expressions with Operators
4. Input and Output Statements
Structured English for Algorithm Design
What is Structured English?
Structured English is a restricted subset of English used to describe algorithms in a clear, unambiguous way. It uses:
- Imperative verbs (Read, Write, Calculate, If, While, Repeat)
- Clear, simple sentences
- Indentation to show structure
- Standardized keywords
Example: Structured English for Finding Maximum
2. Read three numbers: num1, num2, num3
3. Set max to num1
4. If num2 > max then set max to num2
5. If num3 > max then set max to num3
6. Output "Maximum is: " followed by max
7. End
Converting to Cambridge Pseudocode
Practice: Convert Flowchart to Cambridge Pseudocode
Convert this flowchart to Cambridge pseudocode:
Write the complete Cambridge pseudocode including variable declaration, input, decision logic, and output.
Solution:
Marking points: Correct variable declaration [1], proper INPUT statement [1], correct IF condition [1], appropriate OUTPUT statements [1], proper indentation and ENDIF [1].
Practice: Structured English to Pseudocode
Convert this Structured English algorithm to Cambridge pseudocode:
2. Read a number
3. If the number is greater than 0
4. Output "Positive"
5. Else if the number is less than 0
6. Output "Negative"
7. Else
8. Output "Zero"
9. End
Write the complete Cambridge pseudocode with proper indentation and syntax.
Solution:
Key features: Uses ELSEIF for multiple conditions, proper indentation for readability, correct comparison operators, and ENDIF to close the conditional block.
Check Your Understanding: Cambridge Pseudocode
1. Write Cambridge pseudocode to declare a constant called VAT_RATE with value 0.2 and a variable called price of type REAL. [2 marks]
Answer
- [1 mark] Correct constant declaration using CONSTANT keyword
- [1 mark] Correct variable declaration with REAL type
2. Write a Cambridge pseudocode assignment statement to calculate total price including VAT. [2 marks]
Answer
- [1 mark] Correct use of assignment operator (←)
- [1 mark] Correct calculation including parentheses for order of operations
3. Write Cambridge pseudocode to input a student's mark and output "Pass" if mark ≥ 50, otherwise output "Fail". [4 marks]
Answer
- [1 mark] Correct variable declaration
- [1 mark] Correct INPUT statement
- [1 mark] Correct IF condition with comparison operator
- [1 mark] Proper OUTPUT statements in both branches
4. Write a logical expression in Cambridge pseudocode to check if a number is between 10 and 20 inclusive. [2 marks]
Answer
- [1 mark] Correct use of AND operator
- [1 mark] Correct comparison operators (>= and <= for inclusive range)
5. Convert this Structured English to Cambridge pseudocode: [4 marks]
"Read three numbers, calculate their average, and output the result."
Answer
- [1 mark] Correct variable declarations
- [1 mark] Correct INPUT statement for three values
- [1 mark] Correct calculation with parentheses
- [1 mark] Correct OUTPUT statement
Key Takeaways
- Flowcharts are diagrammatic representations of algorithms using standardized symbols
- Terminator (oval) shows START and STOP points of the algorithm
- Process box (rectangle) represents calculations and variable assignments (uses ← symbol)
- Input/Output (parallelogram) represents INPUT or PRINT operations
- Decision box (diamond) represents conditional statements with Yes/True and No/False branches
- Subroutine symbol indicates a call to another procedure or function
- Flow lines (arrows) show the direction of execution through the flowchart
- Connector (circle) indicates continuation of a flowchart across multiple pages
- Trace tables help track variable values and verify algorithm correctness
- Three types of test data: Normal, Abnormal/Erroneous, and Boundary/Extreme
- Common errors include missing terminators, incorrect symbols, infinite loops, and uninitialized variables
- Cambridge pseudocode syntax uses DECLARE for variables, CONSTANT for constants, ← for assignment, and INPUT/OUTPUT for I/O operations
- Arithmetic operators (+, -, *, /, MOD) and logical operators (AND, OR, NOT) are used in expressions
- Structured English is a clear, unambiguous way to describe algorithms using imperative verbs
- Flowcharts, pseudocode, and structured English are interchangeable representations that can be converted between each other
- Exam questions often require converting between different algorithm representations
- Real-world applications include login systems, e-commerce checkouts, and mobile app workflows
Question Bank
1. Draw a flowchart for an algorithm that inputs three numbers and outputs the largest. [6 marks]
Marking Scheme & Answer
Alternative simpler solution: Compare num1 and num2, store larger in max. Then compare max with num3. If num3 > max, update max. Output max.
2. Identify errors in the following flowchart description: [5 marks]
"Start → Input X → If X>10 then Output 'Large' → Process: Y←X+5 → Output Y → Stop"
Marking Scheme & Answer
- [1 mark] Decision box missing "No" branch - what happens if X ≤ 10?
- [1 mark] Output 'Large' should be in output symbol (parallelogram), not decision box
- [1 mark] Process box (Y←X+5) should be rectangle, not just "Process:"
- [1 mark] Output Y should be separate output symbol
- [1 mark] Missing symbols: Need actual flowchart symbols with correct shapes
- [Additional] Corrected: START → Input X (parallelogram) → X>10? (diamond) → Yes: Output 'Large' (parallelogram) → No: (could go directly to next step) → Y←X+5 (rectangle) → Output Y (parallelogram) → STOP
3. Create a trace table for this algorithm with inputs: 5, 12, 8, -1 [6 marks]
total ← 0
count ← 0
REPEAT
INPUT number
IF number > 0 THEN
total ← total + number
count ← count + 1
ENDIF
UNTIL number < 0
average ← total / count
OUTPUT average
Marking Scheme & Answer
| Iteration | number | total | count | average | Output |
|---|---|---|---|---|---|
| Initial | - | 0 | 0 | - | - |
| 1 | 5 | 5 | 1 | - | - |
| 2 | 12 | 17 | 2 | - | - |
| 3 | 8 | 25 | 3 | - | - |
| 4 | -1 | 25 | 3 | 8.33 | 8.33 |
Explanation: The algorithm calculates average of positive numbers until a negative is entered. With inputs 5, 12, 8, -1: total = 5+12+8 = 25, count = 3, average = 25/3 ≈ 8.33. The negative number (-1) triggers loop exit but is not added to total.
4. Convert this pseudocode to a flowchart: [5 marks]
INPUT age
IF age >= 18 THEN
OUTPUT "Adult"
ELSE
IF age >= 13 THEN
OUTPUT "Teenager"
ELSE
OUTPUT "Child"
ENDIF
ENDIF
Marking Scheme & Answer
Key points: Nested IF structure. First checks if adult (≥18). If not, checks if teenager (13-17). If not, must be child (<13). All outputs in parallelogram symbols, decisions in diamonds.
5. Draw a flowchart for a simple calculator that: [6 marks]
- Inputs two numbers and an operator (+, -, *, /)
- Performs the calculation
- Outputs the result
- For division, check for divide by zero error
Marking Scheme & Answer
Alternative approach: Use CASE structure or nested IFs. Key elements: Check for division by zero before calculating, handle all four operators, provide error messages for invalid operator or division by zero.
6. What is the difference between a connector and a subroutine symbol? [3 marks]
Marking Scheme & Answer
- [1 mark] Connector: Circle symbol used when flowchart continues on another page
- [1 mark] Subroutine: Rectangle with extra lines (or dashed) representing a call to another procedure
- [1 mark] Connector connects parts of same flowchart, subroutine calls separate algorithm
- [Additional] Example: Connector A on page 1 connects to Connector A on page 2. Subroutine CALL triangle(width,height) executes triangle calculation procedure.
7. Explain why flowcharts are useful in programming. [4 marks]
Marking Scheme & Answer
- [1 mark] Visual representation makes algorithms easier to understand
- [1 mark] Helps identify logic errors before coding
- [1 mark] Standard symbols provide clear communication between programmers
- [1 mark] Useful for documentation and explaining program logic to others
- [Additional] Particularly helpful for complex algorithms with multiple decisions and loops
8. Write Cambridge pseudocode for finding factorial of a number. [5 marks]
Marking Scheme & Answer
Alternative using WHILE loop:
DECLARE n, factorial, i : INTEGER
INPUT n
factorial ← 1
i ← 1
WHILE i <= n
factorial ← factorial * i
i ← i + 1
ENDWHILE
OUTPUT "Factorial of ", n, " is ", factorial
9. Write Structured English for an algorithm that checks if a number is prime. [4 marks]
Marking Scheme & Answer
2. Input a number n
3. If n is less than 2 then output "Not prime" and end
4. Set divisor to 2
5. Set isPrime to TRUE
6. While divisor is less than n
7. If n divided by divisor has remainder 0 then
8. Set isPrime to FALSE
9. End if
10. Increment divisor by 1
11. End while
12. If isPrime is TRUE then output "Prime"
13. Else output "Not prime"
14. End
Note: This is basic prime checking. More efficient versions check only up to √n or skip even numbers.
10. Convert this flowchart to Cambridge pseudocode: [6 marks]
Start → Input username, password → Valid? → Yes: Output "Access granted" → No: Output "Access denied" → Stop
Marking Scheme & Answer
Alternative simpler version: Without constants and Boolean variable:
DECLARE username, password : STRING
INPUT username, password
IF username = "admin" AND password = "password123" THEN
OUTPUT "Access granted"
ELSE
OUTPUT "Access denied"
ENDIF