Exam Preparation

IGCSE 0478

Practice Tasks

100 exam-style programming tasks across 6 modules, covering every topic in the IGCSE Pseudocode Checklist. For every task, click Show Hints for progressive nudges or Show Pseudocode for the worked solution (Easy questions show the complete pseudocode; Medium-to-Hard questions add a step-by-step breakdown; the hardest Hard questions show two valid approaches to compare).

M1

Module 1

The Essential Foundations

Exam-style questions on variables, constants, types, I/O, operators and arithmetic.

1EasyVariables (DECLARE)

A veterinary clinic stores each pet's name and its age in whole years. Write pseudocode to declare two variables with the most appropriate data types for this data.

2EasyOutput (OUTPUT)

A vending machine displays a welcome message when a customer approaches. Write a single pseudocode statement to output the message: Welcome - please make your selection.

3MediumConstants (CONSTANT)

A pizza shop charges $9.50 per pizza and adds a flat $2.50 delivery fee on every order. Write pseudocode using a CONSTANT for the delivery fee, then input the number of pizzas ordered, calculate the total cost, and output it.

4MediumData Types

A smartphone contact app stores for each contact: a mobile phone number (e.g. 07712345678), a nickname, whether the contact is a favourite, and the number of times they have been called. Write pseudocode to declare these four variables with appropriate data types, justifying why the phone number is stored as text.

5MediumAssignment (arrow)

A weather app stores HighTemp and LowTemp (both REAL). When the user enters them the wrong way around, the app needs to swap them. Write pseudocode to swap the two values using a third REAL variable called Temp.

6MediumInput (INPUT)

A theme park ride has a minimum height of 140 cm. Write pseudocode to ask the user for their height in cm and output whether they are allowed on the ride.

7MediumArithmetic (+ - * / DIV MOD ^)

A marathon runner records their total running time in seconds. Write pseudocode to input the total seconds (INTEGER) and output the time converted into hours, remaining minutes, and remaining seconds.

8MediumRelational Ops (> >= < <= = <>)

A water tank is considered safe if the water level is between 100 and 500 litres (inclusive). Write pseudocode to input the current level and output whether the tank is safe.

9HardVariables + Data Types + Input + Output

A school registers a new pupil. The office needs to input and store: the pupil's full name, age in years, and whether they consent to photo use. Write pseudocode to declare these variables with appropriate types, input all three values (with prompts), and output a single confirmation line.

10HardConstants + Arithmetic

An electricity company charges a flat daily standing charge of $0.25 and $0.18 per unit of electricity used. Write pseudocode using CONSTANTS for both rates. Input the number of days and the number of units used, then calculate and output the total bill.

11HardAssignment + Arithmetic

A teacher records Test1 and Test2 as INTEGER scores out of 50. She wants to scale them: add 5 to Test1, then swap the two values so the scaled mark is in Test2. Using a temporary variable, write pseudocode to add 5 to Test1 and then swap Test1 and Test2.

12HardInput + Relational Ops

A username and password are stored as the strings USERNAME and PASSWORD. Write pseudocode to input a username and password from the user, and output "Login OK" only if BOTH match the stored values, otherwise output "Login failed".

13HardOutput + Arithmetic

A shop sells three items with prices stored as REAL variables Price1, Price2 and Price3. Write pseudocode to compute the subtotal, a 20% tax, and the grand total, then output a 3-line receipt showing each line clearly labelled.

14HardArithmetic + Variables

A landscaper is laying rectangular paving slabs. Write pseudocode to input the length and width of one slab in metres (both REAL), the number of slabs required (INTEGER), and output the total area paved.

15HardRelational Ops + Logical Ops

A year is a leap year if it is divisible by 4 but NOT by 100, UNLESS it is also divisible by 400. Write pseudocode to input a year (INTEGER) and output "Leap year" or "Not a leap year".

16HardLogical Ops (AND OR NOT)

A website requires a password to be at least 8 characters long AND to contain at least one digit (the variable HasDigit is BOOLEAN, set elsewhere). Given the password length stored in Length (INTEGER), write pseudocode using a single IF with logical operators to output "Password accepted" or "Password rejected".

17HardVariables + Logical Ops

A voter is eligible to vote in a national election if they are 18 or older AND a citizen (Citizen is BOOLEAN) AND have NOT been disqualified (Disqualified is BOOLEAN). Write pseudocode to input Age, Citizen and Disqualified and output "Eligible" or "Not eligible".

18HardArithmetic + Constants

A currency exchange converts pounds to dollars at a fixed rate. Write pseudocode using a CONSTANT EXCHANGE_RATE = 1.27. Input an amount in pounds (REAL), calculate the dollar value, and output both amounts on one line.

19HardConstants + Arithmetic + Relational (taxi fare)

A taxi firm charges a flat base fare of $3.00 plus $1.50 for every kilometre travelled. Write pseudocode using CONSTANTS, input the distance in km (INTEGER), calculate the fare, and add a $5 surcharge if the distance is over 20 km. Show two approaches: a single-expression formula that adds the surcharge with an IF, and a step-by-step version using intermediate variables.

20HardLogical + Relational + Constants (bank loan)

A bank approves a personal loan only if the applicant is 21 or older, has an annual income of at least $20,000, AND has a credit score of at least 600. Write pseudocode using CONSTANTS for the three thresholds. Input Age (INTEGER), Income (INTEGER) and CreditScore (INTEGER), and output "Approved" or "Declined". Show two approaches: a single compound IF, and nested IFs that set a BOOLEAN flag.

M2

Module 2

Mastering Control Flow

Exam-style questions on IF/ELSE, ELSEIF, CASE, FOR, WHILE and REPEAT.

1EasyIF / ELSE

A theme park offers a discount to children under 12. Write pseudocode to input a child's age and output "Discount applies" if the age is less than 12, otherwise "No discount".

2EasyFOR

A teacher wants to display the numbers 1 to 10 on separate lines for a counting exercise. Write pseudocode using a FOR loop to output each number from 1 to 10.

3MediumIF / ELSE

An exam is marked out of 50. A score of 25 or below is a Fail; anything above 25 is a Pass; a score of 45 or above is a Distinction. Write pseudocode to input a score and output Fail, Pass or Distinction using IF/ELSE statements (not ELSEIF).

4MediumELSEIF

A teacher awards grades based on marks: A for 90+, B for 80-89, C for 70-79, D for 60-69, otherwise F. Write pseudocode to input a mark and output the grade using an ELSEIF chain.

5MediumFOR

A class has 30 students. Write pseudocode using a FOR loop to input each student's exam score, total the scores, and output the class average.

6MediumWHILE

A program must ask the user to enter a positive number, and keep asking while they enter zero or a negative value. Write pseudocode using a WHILE loop to repeatedly prompt and input a number until it is greater than 0.

7MediumREPEAT

A login screen must keep prompting for a password until the user enters the correct one ("IGCSE2026"). Write pseudocode using a REPEAT...UNTIL loop to repeatedly prompt and input the password until it matches.

8MediumCASE

A program inputs a number from 1 to 7 representing a day of the week. Write pseudocode using a CASE statement to output the day name (1 = Monday, 2 = Tuesday, ..., 7 = Sunday). Include an OTHERWISE branch for invalid input.

9HardIF / ELSE + Logical Ops

A shipping company charges extra for parcels that are heavy OR bulky. A parcel is heavy if Weight > 25 (kg) and bulky if Volume > 100000 (cm cubed). Write pseudocode to input Weight (INTEGER) and Volume (INTEGER) and output "Surcharge applies" if EITHER condition holds, otherwise "No surcharge".

10HardELSEIF (income tax)

A country taxes income in bands: the first $12,570 is tax-free; the portion from $12,571 to $50,270 is taxed at 20%; the portion above $50,270 is taxed at 40%. Write pseudocode to input an annual income (INTEGER) and output the tax owed (REAL).

11HardFOR (find maximum)

A judge scores 20 gymnasts. Write pseudocode using a FOR loop to input each score (REAL) and output the highest score awarded.

12HardWHILE (sentinel value)

A shop keeps entering item prices until the cashier types -1 to finish. Write pseudocode using a WHILE loop to add up all positive prices entered and output the total. Stop when -1 is entered.

13HardREPEAT (menu validation)

A simple menu offers options 1 to 4. The program must keep asking the user to choose an option until they enter a valid number (1, 2, 3 or 4). Write pseudocode using a REPEAT...UNTIL loop that re-prompts on invalid input and outputs the chosen option once valid.

14HardCASE + Arithmetic (calculator)

A simple calculator inputs two numbers (REAL) and an operator as a single character (+, -, *, /). Write pseudocode using a CASE statement to perform the correct calculation and output the result. Include an OTHERWISE branch for unknown operators.

15HardFOR + IF (counting)

A data logger records 50 temperature readings. Write pseudocode using a FOR loop to input each reading (INTEGER) and count how many are even numbers. Output the count.

16HardFOR + Variables (times table)

A teacher wants to display the 7 times table from 7 x 1 to 7 x 12. Write pseudocode using a FOR loop to output each line in the form: 7 x 1 = 7.

17HardWHILE + Relational (guessing game)

A guessing game has a secret number stored in Secret (INTEGER). The player must keep guessing until they get it right. Write pseudocode using a WHILE loop to repeatedly input a guess, output "Too low" or "Too high" as appropriate, and end with "Correct!" when the guess equals Secret.

18HardREPEAT + Logical Ops (ATM)

An ATM allows up to 3 attempts to enter the correct PIN. Write pseudocode using a REPEAT...UNTIL loop with an Attempts counter. If the user enters the correct PIN, output "Access granted". If they fail 3 times, output "Card locked". Assume the correct PIN is stored as PIN.

19HardFOR vs WHILE (sum 1..N)

A program must calculate the sum of all whole numbers from 1 to N, where N is input by the user (INTEGER). Write pseudocode to input N and output the sum. Show two approaches: using a FOR loop, and using a WHILE loop.

20HardELSEIF vs CASE (season)

A program inputs a month number (1 to 12) and outputs the season: months 12, 1, 2 = Winter; 3, 4, 5 = Spring; 6, 7, 8 = Summer; 9, 10, 11 = Autumn. Show two approaches: an ELSEIF chain that checks ranges, and a CASE statement that lists each month.

M3

Module 3

Working with Data — Arrays & Strings

Exam-style questions on 1D/2D arrays, traversing, searching, totalling and string manipulation.

1Easy1D Arrays (DECLARE)

A weather station records the noon temperature every day for a week (7 days). Write pseudocode to declare an array called Temperatures with 7 elements of type REAL.

2EasyString Length (LENGTH)

A username must be checked for length. A variable UserName has been declared as STRING. Write a single pseudocode statement to assign the length of UserName to an INTEGER variable called NameLength (already declared).

3EasyConcatenation (&)

A website builds a display name from a user's first name (FirstName) and last name (LastName), both STRING, with a space between them. Write pseudocode to assign the full name to a STRING variable FullName (already declared).

4Medium1D Arrays (input + output)

A weather station records the noon temperature every day for a week (7 days). Write pseudocode to input the 7 temperatures (REAL) into an array Temperatures and then output all 7 values, one per line.

5Medium2D Arrays (declare + initialise)

A cinema has 5 rows of seats with 8 seats in each row. Write pseudocode to declare a 2D array Seats that can store whether each seat is booked (BOOLEAN). Then set every seat to FALSE (not booked).

6MediumTraversing

A shop stores the names of 10 products in an array Products (already filled with STRING values). Write pseudocode to traverse the array and output each product name on a new line, numbered 1 to 10.

7MediumMax / Min

A teacher has 25 exam scores stored in an array Scores (INTEGER, already filled). Write pseudocode to find and output the highest score in the array.

8MediumTotalling / Averaging

A class has 30 students. Their marks are stored in an array Marks (INTEGER, already filled). Write pseudocode to calculate and output the class average (REAL).

9MediumLinear Search

A library stores the names of 50 books in an array BookTitles (STRING, already filled). Write pseudocode to input a search term and use a linear search to find whether the book is in the list. Output "Found" or "Not found".

10MediumCounting

A teacher has 40 exam scores (INTEGER) stored in an array Scores. The pass mark is 50. Write pseudocode to count how many students passed and output the count.

11MediumSubstrings (SUBSTRING)

A UK phone number is stored as a STRING in PhoneNumber (e.g. "02079460958"). The area code is the first 4 characters. Write pseudocode to assign the area code to a STRING variable AreaCode (already declared) using the SUBSTRING function, then output it.

12MediumCase (UCASE/LCASE)

A user inputs their first name into Name (STRING). The first letter has been typed in lower case by mistake. Write pseudocode to convert only the first letter to upper case using UCASE and SUBSTRING, then reassemble the name and output it.

13Hard1D Arrays + Totalling (rainfall)

A weather station stores daily rainfall (REAL, in mm) for a 30-day month in an array Rainfall. Write pseudocode to calculate the total rainfall for the month and the average daily rainfall, then output both values.

14Hard2D Arrays + Traversing (seating)

A classroom has 4 rows of desks with 5 desks per row. Each desk is assigned to a student whose name is stored in a 2D array Seating (STRING, already filled). Write pseudocode to traverse the entire grid and output the row number, desk number, and student name for every occupied desk (i.e. name is not empty).

15HardMax/Min + Linear Search (top scorer)

A teacher has 20 student scores stored in parallel arrays Names (STRING) and Scores (INTEGER). Write pseudocode to find the highest score and the name of the student who achieved it, and output both. If there is a tie, output the first student found.

16HardLinear Search + Counting (occurrences)

A survey recorded 100 responses (each an INTEGER from 1 to 5) stored in an array Responses. Write pseudocode to input a target value (1-5) and count how many times it appears in the array. Output the count.

17HardString Length + Logical (password)

A password policy requires a password to be between 8 and 16 characters inclusive. Write pseudocode to input a password (STRING), check its length, and output "Valid" or "Invalid" using logical operators.

18HardSubstrings + Concatenation (name)

A name is stored as "LastName, FirstName" in a STRING variable FullName (e.g. "Smith, John"). Write pseudocode to find the comma, extract the first name and last name, then output the name in the form "FirstName LastName" (e.g. "John Smith").

19HardCase + String Length (capitalise)

A sentence is stored in Sentence (STRING). Each word starts with a lower-case letter and words are separated by single spaces. Write pseudocode to capitalise the first letter of every word and output the new sentence. (Hint: a letter that follows a space should be upper-cased; the very first letter should also be upper-cased.)

20Hard2D Arrays + Max/Min (matrix max)

A 4x4 grid of INTEGER values is stored in a 2D array Matrix. Write pseudocode to find the largest value anywhere in the grid and output it.

21Hard1D Arrays + Linear Search (find by ID)

A school has 200 students. Their IDs (INTEGER) are stored in an array IDs and their names (STRING) in a parallel array Names, both already filled. Write pseudocode to input a student ID and use a linear search to find and output the student's name. If the ID is not found, output "Not found".

22HardTraversing + Totalling (diagonal)

A 5x5 grid of INTEGER values is stored in a 2D array Grid. Write pseudocode to traverse the main diagonal (top-left to bottom-right) and output the sum of the diagonal elements.

23HardCounting + Case (count upper-case)

A sentence is stored in Sentence (STRING). Write pseudocode to traverse the sentence and count how many UPPER-CASE letters it contains. Output the count. (Hint: a character is upper-case if it equals UCASE(itself) AND it is a letter A-Z.)

24HardMax/Min + Arithmetic (second highest)

A list of 15 distinct INTEGER scores is stored in an array Scores. Write pseudocode to find and output the SECOND-highest score. (Hint: track both Highest and SecondHighest in a single pass.)

25HardSubstrings + Arithmetic (date parts)

A date is input as a STRING in the form "DD/MM/YYYY" (e.g. "25/03/2026"). Write pseudocode to extract the day, month and year as substrings, convert each to an INTEGER, and output the three values. (Assume a function STRING_TO_INTEGER exists.)

26HardConcatenation + String Length (email)

A company creates email addresses for new staff using the rule: first initial + last name + "@company.com" (all lower case). The staff member's first name and last name are stored in FirstName and LastName (STRING). Write pseudocode to build and output the email address.

27HardLinear Search + Logical (multi-criteria)

An estate agent has 50 properties stored in parallel arrays: Price (INTEGER), Bedrooms (INTEGER) and Suburb (STRING). Write pseudocode to input a maximum price, a minimum number of bedrooms, and a suburb name. Output the index of the FIRST property that matches ALL THREE criteria, or "None found" if no property matches.

28HardTotalling/Averaging (filtered, FOR vs WHILE)

A scientist recorded 20 temperature readings (REAL) in an array Temps. She wants the average EXCLUDING any reading below 0 or above 40 (instrument errors). Write pseudocode to compute this filtered average. Show two approaches: using a FOR loop, and using a WHILE loop with an index variable.

29HardLinear Search (REPEAT vs WHILE)

A shop keeps a list of 100 product codes (INTEGER) in an array Codes. A cashier inputs a product code to look up. Write pseudocode to find the position of the product in the list (assume it is definitely there). Show two approaches: using REPEAT...UNTIL and using WHILE. Output the position once found.

30HardMax/Min (one pass vs two passes)

A list of 50 INTEGER values is stored in an array Values. Write pseudocode to find BOTH the largest and the smallest value in the array. Show two approaches: a single pass that updates both Highest and Lowest together, and two separate passes (one for Highest, one for Lowest). Output both values.

M4

Module 4

Modular Programming — Procedures & Functions

Exam-style questions on procedures, functions and parameters.

1EasyProcedures (PROCEDURE)

A program needs a reusable procedure that displays a welcome banner whenever it is called. Write pseudocode for a procedure called ShowWelcome that outputs the single line: Welcome to the Library System.

2MediumProcedures (parameter)

A receipt-printing program calls a procedure to print a header showing the shop name and the date. The shop name is fixed but the date varies. Write pseudocode for a procedure PrintHeader that takes one parameter Date (STRING) and outputs two lines: the shop name on the first line and the date on the second.

3MediumFunctions (FUNCTION/RETURN)

A program needs a function that calculates the area of a rectangle. Write pseudocode for a function CalculateArea that takes two REAL parameters Length and Width and RETURNS the area. (Do not call the function — just declare it.)

4MediumParameters (passing data)

A program needs a procedure GreetUser that takes a user's name as a STRING parameter and outputs a personalised greeting. Write pseudocode for the procedure. The greeting should read: Hello, <name> — welcome back!

5HardFunctions + Parameters (tax)

A country taxes income at a flat 20% on everything earned above $12,570 (the tax-free allowance). Write pseudocode for a function CalculateTax that takes an INTEGER parameter Salary and RETURNS the tax owed (REAL). Include the allowance as a CONSTANT inside the function. If Salary is below the allowance, the tax is 0.

6HardProcedures + Parameters (update balance)

A bank account program stores the current balance in a global REAL variable Balance. Write pseudocode for a procedure ApplyFee that takes a REAL parameter Fee and reduces Balance by that amount. If the fee would make the balance negative, output "Insufficient funds" and leave Balance unchanged. (Assume Balance is already declared globally.)

7HardFunctions + Arithmetic (factorial)

A program needs a function that calculates the factorial of a non-negative integer N (e.g. 5! = 5 x 4 x 3 x 2 x 1 = 120). Write pseudocode for a function Factorial that takes an INTEGER parameter N and RETURNS the factorial as an INTEGER. Use an iterative (loop) approach.

8HardFunctions + Logical (prime check)

A program needs a function that decides whether a number is prime. Write pseudocode for a function IsPrime that takes an INTEGER parameter N and RETURNS a BOOLEAN: TRUE if N is prime, FALSE otherwise. (Assume N >= 2.) Use a loop that checks divisors from 2 to N - 1.

9HardFunctions (factorial: iterative vs recursive)

A program needs a function to compute the factorial of a non-negative integer N. Show two approaches: an iterative version using a FOR loop, and a recursive version where Factorial(N) calls Factorial(N - 1). Both should RETURN an INTEGER.

10HardProcedures + Functions (pay: single vs split)

A factory pays workers a base rate of $15 per hour for the first 40 hours, then $22.50 per hour for any overtime. Write pseudocode to input HoursWorked (INTEGER) and output the total pay. Show two approaches: a single function CalculatePay that does everything, and a main program that calls two separate functions BasePay and OvertimePay and adds the results.

M5

Module 5

Advanced & Rare Topics

Exam-style questions on bubble sort, file handling, validation routines and recursion.

1EasyFile Handling (WRITE)

A logging program needs to write a single line "Transaction complete" to a file called log.txt. Write pseudocode to open the file for writing, write the line, and close the file.

2MediumFile Handling (READ)

A file students.txt contains one student name per line, with the special value "XXX" marking the end of the data. Write pseudocode to open the file for reading, read and output each name in turn, and stop when "XXX" is read. Close the file at the end.

3MediumValidation (range check)

A teacher inputs an exam mark that must be between 0 and 100 inclusive. Write pseudocode using a REPEAT...UNTIL loop that keeps asking for the mark until a valid value is entered. Output "Mark accepted" once valid.

4MediumRecursion (countdown)

A rocket launch program needs a recursive procedure to count down from N to 1, outputting each number, then output "Lift off!" when it reaches zero. Write pseudocode for a recursive procedure CountDown that takes an INTEGER parameter N. The base case is N = 0.

5HardBubble Sort

A program stores 10 INTEGER scores in an array Scores. Write pseudocode to sort the array into ascending order using the bubble sort algorithm. Output the sorted array after the sort completes.

6HardFile Handling (APPEND)

A till program needs to log every sale. Each sale has a SaleID (INTEGER) and an Amount (REAL). Write pseudocode to open the file sales.txt for appending, write TWO lines per sale (the SaleID on the first line, the Amount on the second), then close the file. Assume SaleID and Amount already hold the values for the current sale.

7HardValidation (presence + length)

A sign-up form requires a username that is not empty AND is at least 4 characters long. Write pseudocode using a REPEAT...UNTIL loop that keeps prompting for a username until both validation checks pass. Output "Username accepted" once valid.

8HardRecursion (Fibonacci)

A program needs a recursive function to compute the Nth Fibonacci number, where Fib(1) = 1, Fib(2) = 1, and Fib(N) = Fib(N-1) + Fib(N-2) for N > 2. Write pseudocode for a recursive function Fib that takes an INTEGER parameter N and RETURNS the Nth Fibonacci number as an INTEGER.

9HardBubble Sort (basic vs early-exit)

A program stores 10 INTEGER values in an array Values. Write pseudocode to sort the array into ascending order using the bubble sort algorithm. Show two approaches: a basic bubble sort that always does all 9 passes, and an optimised version that stops early if no swaps were made in a pass (the array is already sorted).

10HardRecursion vs Iteration (factorial)

A program needs to compute the factorial of a non-negative integer N. Show two approaches: a recursive function (Factorial(N) calls Factorial(N-1)) and an iterative function (uses a FOR loop). Both should RETURN an INTEGER.

M6

Module 6

Exam Technique & Accuracy

Spot-the-error, fix-this-code and complete-the-trace-table questions on pseudocode conventions.

1EasyUppercase Keywords

A student has written the following pseudocode but used lower-case keywords. Rewrite the snippet with all keywords in UPPER CASE.

declare age : integer
input age
if age >= 18 then
    output "Adult"
endif
2MediumIndentation

The pseudocode below is correct in keywords but the indentation is wrong, making it hard to read. Rewrite it with correct indentation (4 spaces per level) so the structure of the IF inside the FOR is clear.

DECLARE I : INTEGER
FOR I <- 1 TO 5
IF I MOD 2 = 0 THEN
OUTPUT I
ENDIF
NEXT I
3MediumNo Python Syntax

A student who knows Python has written the following pseudocode but used Python syntax. Rewrite it as valid CIE pseudocode so it does the same thing.

age = int(input("Enter age: "))
if age >= 18:
    print("Adult")
else:
    print("Child")
4MediumTrace Tables

Complete the trace table for the following pseudocode. Show the value of Counter and Total after each iteration of the FOR loop.

DECLARE Counter, Total : INTEGER
Total <- 0
FOR Counter <- 1 TO 4
    Total <- Total + Counter * 2
NEXT Counter
OUTPUT Total
5HardUppercase Keywords + Indentation

A student has written the following pseudocode with lower-case keywords AND no indentation. Rewrite it with all keywords in UPPER CASE and correct 4-space indentation so the nested structure (FOR containing IF) is clear.

declare sum : integer
sum <- 0
for i <- 1 to 10
if i mod 2 = 0 then
sum <- sum + i
endif
next i
output sum
6HardNo Python Syntax + Indentation (Python -> pseudocode)

A student has written the following Python program. Convert it to valid CIE pseudocode with correct UPPER-CASE keywords and proper 4-space indentation. The Python uses a list (-> CIE array), len() (-> LENGTH), and a for-in loop (-> FOR with a counter).

names = ["Amy", "Ben", "Cleo"]
for n in names:
    if len(n) == 4:
        print(n)
7HardTrace Tables (nested loops)

Complete the trace table for the following nested-loop pseudocode. Show the values of Outer, Inner and Product after each iteration of the INNER loop.

DECLARE Outer, Inner, Product : INTEGER
FOR Outer <- 1 TO 2
    FOR Inner <- 1 TO 3
        Product <- Outer * Inner
        OUTPUT Product
    NEXT Inner
NEXT Outer
8HardTrace Tables (with array)

Complete the trace table for the following pseudocode that uses an array. Show the values of Index and Count after each iteration of the FOR loop, and the final output.

DECLARE Index, Count : INTEGER
DECLARE Marks : ARRAY[1:5] OF INTEGER
Marks[1] <- 40
Marks[2] <- 55
Marks[3] <- 30
Marks[4] <- 70
Marks[5] <- 60
Count <- 0
FOR Index <- 1 TO 5
    IF Marks[Index] >= 50 THEN
        Count <- Count + 1
    ENDIF
NEXT Index
OUTPUT Count
9Hard15-Mark Option (FOR vs WHILE input)

A 15-mark exam question asks you to write a program that inputs the names and marks of 30 students, then outputs the name and grade of each student. Grades: A for 90+, B for 75-89, C for 60-74, otherwise Fail. Show two approaches for the main input loop: using a FOR loop, and using a WHILE loop with a counter. Both should use a procedure AwardGrade that takes a mark and outputs the grade.

10Hard15-Mark Option (single function vs split)

A 15-mark exam question asks you to write a cinema ticket system. The cinema charges $8 for adults, $5 for children. Input the number of adults and the number of children, then output the total cost. Show two approaches: a single function CalculateTotal that does everything, and a main program that uses two separate functions (AdultCost and ChildCost) and adds their results.