Question Simulator

IGCSE Computer Science (0478)

Programming Banker

32 questions · about 18% of the marks we indexed · examined in 9 of 9 sessions.

Questions by year

2026

  • 2026 May/June · Paper 22 · Q11 markData types, variables, constants, selection and iteration
  • 2026 May/June · Paper 22 · Q21 markData types, variables, constants, selection and iteration
  • 2026 May/June · Paper 22 · Q7 (a, b)5 marksFile handling
  • 2026 May/June · Paper 22 · Q1015 marksExtended programming task (15-mark scenario)

2025

  • 2025 Oct/Nov · Paper 22 · Q11 markString handling and operators
  • 2025 Oct/Nov · Paper 22 · Q2 (b(i), b(ii))6 marksProcedures, functions and library routines
  • 2025 Oct/Nov · Paper 22 · Q4 (b)6 marksString handling and operators
  • 2025 Oct/Nov · Paper 22 · Q5 (c)4 marksArrays
  • 2025 Oct/Nov · Paper 22 · Q815 marksExtended programming task (15-mark scenario)
  • 2025 May/June · Paper 22 · Q5 (b)2 marksProcedures, functions and library routines
  • 2025 May/June · Paper 22 · Q7 (b)4 marksArrays
  • 2025 May/June · Paper 22 · Q1015 marksExtended programming task (15-mark scenario)

2024

  • 2024 Oct/Nov · Paper 22 · Q21 markData types, variables, constants, selection and iteration
  • 2024 Oct/Nov · Paper 22 · Q106 marksFile handling
  • 2024 Oct/Nov · Paper 22 · Q1215 marksExtended programming task (15-mark scenario)
  • 2024 May/June · Paper 22 · Q56 marksString handling and operators
  • 2024 May/June · Paper 22 · Q7 (a)3 marksData types, variables, constants, selection and iteration
  • 2024 May/June · Paper 22 · Q1115 marksExtended programming task (15-mark scenario)

2023

  • 2023 Oct/Nov · Paper 22 · Q3 (a)4 marksData types, variables, constants, selection and iteration
  • 2023 Oct/Nov · Paper 22 · Q53 marksData types, variables, constants, selection and iteration
  • 2023 Oct/Nov · Paper 22 · Q75 marksString handling and operators
  • 2023 Oct/Nov · Paper 22 · Q84 marksProcedures, functions and library routines
  • 2023 Oct/Nov · Paper 22 · Q1115 marksExtended programming task (15-mark scenario)
  • 2023 May/June · Paper 22 · Q55 marksFile handling
  • 2023 May/June · Paper 22 · Q66 marksMaintainable programs
  • 2023 May/June · Paper 22 · Q7 (a)3 marksData types, variables, constants, selection and iteration
  • 2023 May/June · Paper 22 · Q11 (a, b, c)7 marksData types, variables, constants, selection and iteration · String handling and operators
  • 2023 May/June · Paper 22 · Q1215 marksExtended programming task (15-mark scenario)

2022

  • 2022 Oct/Nov · Paper 22 · Q1 (a(i), a(ii), b, c, d, e)20 marksPre-release material tasks (old syllabus)
  • 2022 Oct/Nov · Paper 22 · Q24 marksData types, variables, constants, selection and iteration
  • 2022 May/June · Paper 22 · Q1 (a(i), a(ii), b, c, d, e)20 marksPre-release material tasks (old syllabus)
  • 2022 May/June · Paper 22 · Q3 (a, b)5 marksArrays

References only, not question text. Open Official paper ↗ where Cambridge publishes the paper, or see the official Cambridge past-papers page; for other papers, ask your school. “Paper 42” means Paper 4, variant 2.

Practice questions

Original questions written by HomiLabs in the style of the exam, with answers and mark schemes. They are not Cambridge past paper questions and have not been reviewed by Cambridge. Try each one before opening the answer.

Q1Extended programming task (15-mark scenario) · Core · Paper 2 style · 15 marks

A cricket academy in Sialkot records the runs scored by its 20 players in each of 10 matches. The program uses:• a one-dimensional array PlayerName[1:20] of type STRING, already holding the players' names• a two-dimensional array Runs[1:20, 1:10] of type INTEGERRequirements:• allow the runs for every player in every match to be input, rejecting any value below 0 or above 300• calculate each player's total and average runs (average rounded to 1 decimal place) and output the name, total and average• find and output the name of the player with the highest total.You may answer in pseudocode or a high-level programming language. Use meaningful identifiers and add comments.

  1. (a) Write the section of the program that inputs and validates the runs for every player in every match. [5]
  2. (b) Write the section that calculates and outputs each player's total and average. [5]
  3. (c) Write the section that finds and outputs the name of the player with the highest total. (You may store each total in an array Totals[1:20] in part (b).) [5]
Show answer
  1. (a) FOR Player ← 1 TO 20 FOR Match ← 1 TO 10 OUTPUT "Enter runs for ", PlayerName[Player], " in match ", Match INPUT Runs[Player, Match] WHILE Runs[Player, Match] < 0 OR Runs[Player, Match] > 300 DO OUTPUT "Invalid: runs must be 0 to 300. Re-enter" INPUT Runs[Player, Match] ENDWHILE NEXT MatchNEXT Player
    1 mark each: outer loop for 20 players; inner loop for 10 matches; prompt and input into Runs[Player, Match]; validation condition < 0 OR > 300; re-input with error message inside a loop.
  2. (b) DECLARE Total : INTEGERDECLARE Average : REALFOR Player ← 1 TO 20 Total ← 0 FOR Match ← 1 TO 10 Total ← Total + Runs[Player, Match] NEXT Match Average ← ROUND(Total / 10, 1) OUTPUT PlayerName[Player], " total: ", Total, " average: ", AverageNEXT Player
    1 mark each: loop through players; total reset to 0 for each player; inner loop adds Runs[Player, Match]; average = total / 10 rounded to 1 d.p.; output name, total and average with messages.
  3. (c) // assumes Totals[Player] ← Total was added inside the loop in (b)DECLARE Highest : INTEGERDECLARE BestPlayer : INTEGERHighest ← Totals[1]BestPlayer ← 1FOR Player ← 2 TO 20 IF Totals[Player] > Highest THEN Highest ← Totals[Player] BestPlayer ← Player ENDIFNEXT PlayerOUTPUT "Highest scorer: ", PlayerName[BestPlayer], " with ", Highest, " runs"
    1 mark each: totals stored in an array (or recalculated); highest initialised to first total (or −1); loop compares each total with highest; highest and index updated together; output name of best player using the stored index with message.
Q2Extended programming task (15-mark scenario) · Core · Paper 2 style · 15 marks

A power company calculates monthly bills for 50 households. Each household's meter reading at the start and end of the month is input. Units used = end reading − start reading.Charges:• the first 100 units cost Rs 10 each• units from 101 to 300 cost Rs 15 each• every unit above 300 costs Rs 25The program uses arrays HouseID[1:50] (STRING, already filled) and Bill[1:50] (REAL).Requirements:• input both readings for each house; the end reading must not be less than the start reading• calculate and store each bill, and output the house ID with its units and bill• output the total of all bills and the number of households that used more than 300 units.You may answer in pseudocode or a high-level programming language. Use meaningful identifiers and add comments.

  1. (a) Write the section that inputs and validates both readings for one household and calculates the units used. [4]
  2. (b) Write the section that calculates the bill for one household from Units and stores it in Bill[House]. [5]
  3. (c) Write the rest of the program: the loop for all 50 households, initialising the counters, and outputting the total of all bills and the count of households above 300 units. (Use your sections from (a) and (b).) [5]
  4. (d) Calculate the bill for a household that uses 350 units. [1]
Show answer
  1. (a) OUTPUT "Start reading for ", HouseID[House]INPUT StartReadingOUTPUT "End reading for ", HouseID[House]INPUT EndReadingWHILE EndReading < StartReading DO OUTPUT "End reading cannot be less than start reading. Re-enter end reading" INPUT EndReadingENDWHILEUnits ← EndReading − StartReading
    1 mark each: inputs with prompts; validation condition EndReading < StartReading; loop with error message and re-input; units calculated.
  2. (b) IF Units <= 100 THEN Bill[House] ← Units * 10ELSE IF Units <= 300 THEN Bill[House] ← 100 * 10 + (Units − 100) * 15 ELSE Bill[House] ← 100 * 10 + 200 * 15 + (Units − 300) * 25 Over300 ← Over300 + 1 ENDIFENDIFOUTPUT HouseID[House], " units: ", Units, " bill: Rs ", Bill[House]
    1 mark each for any five of: correct first band (≤ 100 × 10); correct condition for second band; second band = 1000 + (Units − 100) × 15; third band = 1000 + 3000 + (Units − 300) × 25; count of households over 300 incremented; output of ID, units and bill.
  3. (c) DECLARE TotalBills : REALDECLARE Over300 : INTEGERTotalBills ← 0Over300 ← 0FOR House ← 1 TO 50 // section (a) // section (b) TotalBills ← TotalBills + Bill[House]NEXT HouseOUTPUT "Total of all bills: Rs ", TotalBillsOUTPUT "Households using more than 300 units: ", Over300
    1 mark each: totals and counter initialised to 0 before the loop; loop 1 to 50 around (a) and (b); running total updated inside the loop; total output after the loop; count output after the loop with message.
  4. (d) Rs 5250
    100 × 10 + 200 × 15 + 50 × 25 = 1000 + 3000 + 1250 = 5250.
Q3Extended programming task (15-mark scenario) · Core · Paper 2 style · 15 marks

A school canteen sells 5 items. The arrays ItemName[1:5] (STRING) and Price[1:5] (REAL) already hold the item names and prices. An array Sold[1:5] of INTEGER will hold the number of each item sold in a day.Requirements:• set all values in Sold to 0• for each order, display a numbered menu, input the item number (1–5) and quantity (1–10) with validation, output the cost of that order and update Sold• stop taking orders when the item number 9 is entered• output, for each item, the name, number sold and money taken, and then the total money taken for the day.You may answer in pseudocode or a high-level programming language. Use meaningful identifiers and add comments.

  1. (a) Write the section that initialises Sold and displays the menu. [3]
  2. (b) Write the section that takes orders until 9 is entered. [7]
  3. (c) Write the section that outputs the daily summary. [5]
Show answer
  1. (a) FOR Item ← 1 TO 5 Sold[Item] ← 0NEXT Item// menu display (used before each order)FOR Item ← 1 TO 5 OUTPUT Item, " ", ItemName[Item], " Rs ", Price[Item]NEXT ItemOUTPUT "9 Finish for the day"
    1 mark each: loop setting Sold[1..5] to 0; loop outputting number, name and price; option to finish shown.
  2. (b) OUTPUT "Enter item number"INPUT ChoiceWHILE Choice <> 9 DO IF Choice >= 1 AND Choice <= 5 THEN OUTPUT "Enter quantity (1-10)" INPUT Quantity WHILE Quantity < 1 OR Quantity > 10 DO OUTPUT "Quantity must be 1 to 10" INPUT Quantity ENDWHILE OUTPUT "Cost: Rs ", Quantity * Price[Choice] Sold[Choice] ← Sold[Choice] + Quantity ELSE OUTPUT "Invalid item number" ENDIF // display menu again (section a) OUTPUT "Enter item number" INPUT ChoiceENDWHILE
    1 mark each: loop ending when 9 entered; item number validated 1–5; quantity input; quantity validated 1–10 in a loop; cost = quantity × Price[Choice] output; Sold[Choice] increased by quantity; new item number input inside the loop.
  3. (c) DayTotal ← 0FOR Item ← 1 TO 5 Money ← Sold[Item] * Price[Item] OUTPUT ItemName[Item], ": ", Sold[Item], " sold, Rs ", Money DayTotal ← DayTotal + MoneyNEXT ItemOUTPUT "Total for the day: Rs ", DayTotal
    1 mark each: total initialised; loop over 5 items; money per item = Sold × Price; output name, number sold and money; day total accumulated and output after loop.
Q4Extended programming task (15-mark scenario) · Core · Paper 2 style · 15 marks

A fitness club in Kuala Lumpur gives each member a step counter. For one member, the steps taken each day for 4 weeks are stored in a two-dimensional array Steps[1:4, 1:7] of INTEGER (week, day).Requirements:• input the steps for every day; a value must be between 0 and 60 000• output the total steps for each week and the week with the most steps• output the number of days on which the member reached the target of 10 000 steps, and the percentage of days (to 1 decimal place).You may answer in pseudocode or a high-level programming language. Use meaningful identifiers and add comments.

  1. (a) Write the section that inputs and validates the steps. [4]
  2. (b) Write the section that outputs each week's total and the week with the most steps. [6]
  3. (c) Write the section that outputs the number and percentage of days on which 10 000 steps were reached. [4]
  4. (d) The member reached the target on 17 days. State the percentage your program outputs. [1]
Show answer
  1. (a) FOR Week ← 1 TO 4 FOR Day ← 1 TO 7 OUTPUT "Steps for week ", Week, " day ", Day INPUT Steps[Week, Day] WHILE Steps[Week, Day] < 0 OR Steps[Week, Day] > 60000 DO OUTPUT "Must be 0 to 60000, re-enter" INPUT Steps[Week, Day] ENDWHILE NEXT DayNEXT Week
    1 mark each: nested loops 4 × 7; input into Steps[Week, Day]; range check; re-input loop with message.
  2. (b) BestWeek ← 1BestTotal ← -1FOR Week ← 1 TO 4 WeekTotal ← 0 FOR Day ← 1 TO 7 WeekTotal ← WeekTotal + Steps[Week, Day] NEXT Day OUTPUT "Week ", Week, " total: ", WeekTotal IF WeekTotal > BestTotal THEN BestTotal ← WeekTotal BestWeek ← Week ENDIFNEXT WeekOUTPUT "Most steps in week ", BestWeek
    1 mark each: week total reset to 0 each week; inner loop totals 7 days; week total output; best total initialised; comparison updates best total and week; output best week.
  3. (c) TargetDays ← 0FOR Week ← 1 TO 4 FOR Day ← 1 TO 7 IF Steps[Week, Day] >= 10000 THEN TargetDays ← TargetDays + 1 ENDIF NEXT DayNEXT WeekOUTPUT "Target reached on ", TargetDays, " days"OUTPUT "Percentage: ", ROUND(TargetDays / 28 * 100, 1), "%"
    1 mark each: counter initialised; condition >= 10000 counted over all 28 days; percentage = count / 28 × 100 rounded to 1 d.p.; outputs with messages.
  4. (d) 60.7%
    17 ÷ 28 × 100 = 60.71… → 60.7.
Q5Extended programming task (15-mark scenario) · Standard · Paper 2 style · 15 marks

A cinema in Hyderabad has 8 rows (A to H, numbered 1 to 8 in the program) with 12 seats in each row. The program uses a two-dimensional Boolean array Booked[1:8, 1:12], where TRUE means the seat is taken. A ticket costs Rs 900, but seats in rows 1 and 2 cost Rs 600.Requirements:• at the start, set every seat to not booked• repeatedly let a customer choose a row and seat number; validate both; if the seat is free, book it and add the price to the takings, otherwise output a message• stop when the customer enters 0 for the row• at the end, output the total takings and the number of empty seats in each row.You may answer in pseudocode or a high-level programming language. Use meaningful identifiers and add comments.

  1. (a) Write the section that sets every seat to not booked and initialises the takings. [3]
  2. (b) Write the section that handles bookings until 0 is entered for the row. [7]
  3. (c) Write the section that outputs the total takings and the number of empty seats in each row. [5]
Show answer
  1. (a) DECLARE Booked : ARRAY[1:8, 1:12] OF BOOLEANDECLARE Takings : INTEGERTakings ← 0FOR Row ← 1 TO 8 FOR Seat ← 1 TO 12 Booked[Row, Seat] ← FALSE NEXT SeatNEXT Row
    1 mark each: nested loops over 8 rows and 12 seats; each element set to FALSE; takings initialised to 0.
  2. (b) OUTPUT "Enter row number (1-8), or 0 to finish"INPUT RowWHILE Row <> 0 DO IF Row < 1 OR Row > 8 THEN OUTPUT "Invalid row" ELSE OUTPUT "Enter seat number (1-12)" INPUT Seat WHILE Seat < 1 OR Seat > 12 DO OUTPUT "Invalid seat, re-enter (1-12)" INPUT Seat ENDWHILE IF Booked[Row, Seat] = TRUE THEN OUTPUT "Sorry, that seat is already booked" ELSE Booked[Row, Seat] ← TRUE IF Row <= 2 THEN Takings ← Takings + 600 ELSE Takings ← Takings + 900 ENDIF OUTPUT "Seat booked" ENDIF ENDIF OUTPUT "Enter row number (1-8), or 0 to finish" INPUT RowENDWHILE
    1 mark each: condition-controlled loop ending when row = 0; row validated (1–8); seat input and validated (1–12); check Booked[Row, Seat] before booking; seat set to TRUE; correct price added (600 for rows 1–2, otherwise 900); messages for taken seat/invalid input and re-input of row inside the loop.
  3. (c) OUTPUT "Total takings: Rs ", TakingsFOR Row ← 1 TO 8 Empty ← 0 FOR Seat ← 1 TO 12 IF Booked[Row, Seat] = FALSE THEN Empty ← Empty + 1 ENDIF NEXT Seat OUTPUT "Row ", Row, ": ", Empty, " empty seats"NEXT Row
    1 mark each: takings output with message; loop through rows; counter reset for each row; counts seats that are FALSE; outputs row number and count.
Q6Extended programming task (15-mark scenario) · Standard · Paper 2 style · 15 marks

A public library in Peshawar records returned books. For each of 30 returns in a day, the librarian inputs the member ID (exactly 6 characters) and the number of days late (0 to 60). The fine is Rs 20 per day for the first 7 days late and Rs 50 per day after that; the maximum fine is Rs 2000.The program uses arrays MemberID[1:30] (STRING) and Fine[1:30] (INTEGER).Requirements:• input and validate the member ID (length check) and days late (range check)• calculate and store each fine and output it• output the total fines, the average fine of the members who paid a fine (rounded to 2 decimal places), and the member ID with the largest fine.You may answer in pseudocode or a high-level programming language. Use meaningful identifiers and add comments.

  1. (a) Write the section that inputs and validates the data for return number Count. [4]
  2. (b) Write the section that calculates and stores the fine for return number Count. [4]
  3. (c) Write the section that outputs the total, the average fine of members who paid a fine, and the member with the largest fine. [5]
  4. (d) Calculate the fines for members who are 20 days late and 45 days late. [2]
Show answer
  1. (a) OUTPUT "Enter 6-character member ID"INPUT MemberID[Count]WHILE LENGTH(MemberID[Count]) <> 6 DO OUTPUT "ID must be exactly 6 characters. Re-enter" INPUT MemberID[Count]ENDWHILEOUTPUT "Enter days late (0-60)"INPUT DaysLateWHILE DaysLate < 0 OR DaysLate > 60 DO OUTPUT "Days late must be 0 to 60. Re-enter" INPUT DaysLateENDWHILE
    1 mark each for any four of: ID input into array; length check using LENGTH() <> 6; re-input loop with message; days late input; range check 0–60 with re-input loop.
  2. (b) IF DaysLate <= 7 THEN Fine[Count] ← DaysLate * 20ELSE Fine[Count] ← 7 * 20 + (DaysLate − 7) * 50ENDIFIF Fine[Count] > 2000 THEN Fine[Count] ← 2000ENDIFOUTPUT "Fine for ", MemberID[Count], ": Rs ", Fine[Count]
    1 mark each for any four of: condition DaysLate <= 7; fine = days × 20; fine = 140 + (days − 7) × 50; capped at 2000; output of fine with ID.
  3. (c) Total ← 0Payers ← 0MaxIndex ← 1FOR Count ← 1 TO 30 Total ← Total + Fine[Count] IF Fine[Count] > 0 THEN Payers ← Payers + 1 ENDIF IF Fine[Count] > Fine[MaxIndex] THEN MaxIndex ← Count ENDIFNEXT CountOUTPUT "Total fines: Rs ", TotalIF Payers > 0 THEN OUTPUT "Average fine: Rs ", ROUND(Total / Payers, 2)ELSE OUTPUT "No fines today"ENDIFOUTPUT "Largest fine: ", MemberID[MaxIndex], " Rs ", Fine[MaxIndex]
    1 mark each: total accumulated; payers counted only when fine > 0; average = total / payers rounded to 2 d.p. (division by zero avoided); index of largest fine tracked; outputs with messages.
  4. (d) Rs 790 and Rs 2000
    20 days: 140 + 13 × 50 = 790. 45 days: 140 + 38 × 50 = 2040, capped at 2000.
Q7Extended programming task (15-mark scenario) · Standard · Paper 2 style · 15 marks

A shopping mall car park in Karachi records the number plate and the time a car entered and left, as whole hours and minutes on a 24-hour clock (the car park is open from 08:00 to 23:00, so every stay is on one day). The charge is Rs 100 for the first hour or part of an hour, then Rs 60 for each extra hour or part of an hour. Cars staying 15 minutes or less park free.The program processes 200 cars a day, using arrays Plate[1:200] (STRING) and Charge[1:200] (INTEGER).Requirements:• input and validate the times (hours 8–23, minutes 0–59, leaving time after entry time)• calculate the stay in minutes and the charge, and output both• output the total takings and the number of cars that parked free.You may answer in pseudocode or a high-level programming language. Use meaningful identifiers and add comments.

  1. (a) Write the section that inputs and validates the entry and exit times for car number Car and calculates the stay in minutes. [5]
  2. (b) Write the section that calculates and outputs the charge for car number Car. [5]
  3. (c) Write the main loop and the end-of-day output. Initialise any totals. [4]
  4. (d) A car enters at 10:40 and leaves at 13:05. Calculate its charge. [1]
Show answer
  1. (a) OUTPUT "Number plate"INPUT Plate[Car]REPEAT OUTPUT "Entry time: hours then minutes" INPUT InH, InMUNTIL InH >= 8 AND InH <= 23 AND InM >= 0 AND InM <= 59REPEAT OUTPUT "Exit time: hours then minutes" INPUT OutH, OutM Stay ← (OutH * 60 + OutM) − (InH * 60 + InM)UNTIL OutH >= 8 AND OutH <= 23 AND OutM >= 0 AND OutM <= 59 AND Stay > 0
    1 mark each for any five of: plate input; entry time input with range validation; re-input loop; exit time validated; check that exit is after entry; stay calculated in minutes correctly.
  2. (b) IF Stay <= 15 THEN Charge[Car] ← 0 FreeCars ← FreeCars + 1ELSE Hours ← Stay DIV 60 IF Stay MOD 60 > 0 THEN Hours ← Hours + 1 // part of an hour counts as a whole hour ENDIF Charge[Car] ← 100 + (Hours − 1) * 60ENDIFOUTPUT Plate[Car], " stayed ", Stay, " minutes, charge Rs ", Charge[Car]
    1 mark each: free if stay ≤ 15 and free counter increased; hours rounded up using DIV/MOD; charge = 100 + (hours − 1) × 60; stored in Charge[Car]; output with plate and stay.
  3. (c) Total ← 0FreeCars ← 0FOR Car ← 1 TO 200 // section (a) // section (b) Total ← Total + Charge[Car]NEXT CarOUTPUT "Total takings: Rs ", TotalOUTPUT "Cars parked free: ", FreeCars
    1 mark each: totals initialised before loop; loop for 200 cars; total updated inside loop; both results output after the loop.
  4. (d) Rs 220
    Stay = 145 min → 3 hours (rounded up) → 100 + 2 × 60 = 220.
Q8Extended programming task (15-mark scenario) · Standard · Paper 2 style · 15 marks

A pharmacy in Multan keeps 40 medicines. The arrays MedName[1:40] (STRING), Stock[1:40] (INTEGER) and ReorderLevel[1:40] (INTEGER) are already filled.Requirements:• display a menu: 1 Record a sale, 2 Record a delivery, 3 Reorder report, 4 Exit• for a sale or delivery, input the medicine name and search for it; if it is not found output a message; otherwise input the quantity (must be a positive whole number; a sale cannot be more than the stock) and update Stock• the reorder report lists every medicine whose stock is at or below its reorder level, and the number of such medicines• repeat until option 4 is chosen.You may answer in pseudocode or a high-level programming language. Use meaningful identifiers and add comments.

  1. (a) Write the section that inputs a medicine name and performs a linear search, setting Found to the index of the medicine or to 0 if it is not found. [4]
  2. (b) Write the section that processes a sale (option 1) once the medicine has been found. [4]
  3. (c) Write the menu loop, including option 2 (delivery) and option 3 (reorder report). You may refer to your sections (a) and (b). [7]
Show answer
  1. (a) OUTPUT "Enter medicine name"INPUT SearchNameFound ← 0Index ← 1WHILE Found = 0 AND Index <= 40 DO IF MedName[Index] = SearchName THEN Found ← Index ENDIF Index ← Index + 1ENDWHILEIF Found = 0 THEN OUTPUT "Medicine not found"ENDIF
    1 mark each: name input; loop through array stopping when found or end reached; comparison with MedName[Index] and Found set to index; not-found message.
  2. (b) REPEAT OUTPUT "Quantity sold" INPUT QtyUNTIL Qty > 0 AND Qty = ROUND(Qty, 0) AND Qty <= Stock[Found]Stock[Found] ← Stock[Found] − QtyOUTPUT MedName[Found], " stock now ", Stock[Found]
    1 mark each: quantity input; checks positive and whole; checks not greater than Stock[Found]; stock reduced and new level output.
  3. (c) REPEAT OUTPUT "1 Record a sale 2 Record a delivery 3 Reorder report 4 Exit" INPUT Option CASE OF Option 1 : // section (a); IF Found <> 0 THEN section (b) 2 : // section (a) IF Found <> 0 THEN REPEAT OUTPUT "Quantity delivered" INPUT Qty UNTIL Qty > 0 AND Qty = ROUND(Qty, 0) Stock[Found] ← Stock[Found] + Qty ENDIF 3 : Count ← 0 FOR M ← 1 TO 40 IF Stock[M] <= ReorderLevel[M] THEN OUTPUT MedName[M], " stock ", Stock[M] Count ← Count + 1 ENDIF NEXT M OUTPUT Count, " medicines need reordering" 4 : OUTPUT "Goodbye" OTHERWISE OUTPUT "Invalid option" ENDCASEUNTIL Option = 4
    1 mark each: menu output and option input inside a loop ending at 4; selection (CASE or IF) on option; delivery validated positive whole number; stock increased; report loop compares Stock[M] <= ReorderLevel[M]; outputs names and count; invalid option handled.
Q9Extended programming task (15-mark scenario) · Challenge · Paper 2 style · 15 marks

A charity marathon in Lahore has up to 500 runners. Each runner's number (1 to 500) and finishing time in hours, minutes and seconds are input. The program stores the times in seconds in an array Seconds[1:500] of INTEGER; a value of 0 means the runner did not finish.Requirements:• set every element of Seconds to 0• input results until runner number −1 is entered; validate the runner number, minutes and seconds (0–59) and hours (0–7); a runner number that already has a time must be rejected• output the number of finishers, the runner number of the fastest finisher and the average finishing time as hours, minutes and whole seconds• output how many finishers completed in under 4 hours.You may answer in pseudocode or a high-level programming language. Use meaningful identifiers and add comments.

  1. (a) Write the section that initialises the array and inputs and validates all results. [7]
  2. (b) Write the section that calculates and outputs the number of finishers, the fastest runner and the count under 4 hours. [4]
  3. (c) Write the section that outputs the average finishing time in hours, minutes and whole seconds. [3]
  4. (d) The average time is 15 125 seconds. State what your program outputs for the average. [1]
Show answer
  1. (a) DECLARE Seconds : ARRAY[1:500] OF INTEGERFOR R ← 1 TO 500 Seconds[R] ← 0NEXT ROUTPUT "Enter runner number (-1 to finish)"INPUT RunnerWHILE Runner <> -1 DO IF Runner < 1 OR Runner > 500 THEN OUTPUT "Invalid runner number" ELSE IF Seconds[Runner] <> 0 THEN OUTPUT "This runner already has a time" ELSE REPEAT OUTPUT "Enter hours, minutes, seconds" INPUT H, M, S UNTIL H >= 0 AND H <= 7 AND M >= 0 AND M <= 59 AND S >= 0 AND S <= 59 Seconds[Runner] ← H * 3600 + M * 60 + S ENDIF ENDIF OUTPUT "Enter runner number (-1 to finish)" INPUT RunnerENDWHILE
    1 mark each for any seven of: array initialised to 0; loop until −1; runner number range checked; duplicate check (Seconds[Runner] <> 0); hours, minutes, seconds input; validation of all three ranges with re-input; conversion H × 3600 + M × 60 + S; stored at Seconds[Runner] and next runner input inside loop.
  2. (b) Finishers ← 0Total ← 0Fastest ← 0Under4 ← 0FOR R ← 1 TO 500 IF Seconds[R] > 0 THEN Finishers ← Finishers + 1 Total ← Total + Seconds[R] IF Fastest = 0 THEN Fastest ← R ELSE IF Seconds[R] < Seconds[Fastest] THEN Fastest ← R ENDIF ENDIF IF Seconds[R] < 4 * 3600 THEN Under4 ← Under4 + 1 ENDIF ENDIFNEXT ROUTPUT "Finishers: ", FinishersOUTPUT "Fastest runner: ", FastestOUTPUT "Under 4 hours: ", Under4
    1 mark each: only times > 0 counted; fastest found correctly (index stored, first finisher handled); under-4-hours test uses 14 400 seconds; outputs with messages.
  3. (c) IF Finishers > 0 THEN Avg ← ROUND(Total / Finishers, 0) OUTPUT "Average: ", Avg DIV 3600, " h ", (Avg MOD 3600) DIV 60, " min ", Avg MOD 60, " s"ENDIF
    1 mark each: average = total ÷ finishers rounded to whole seconds (division by zero avoided); hours using DIV 3600; minutes and seconds using MOD/DIV.
  4. (d) Average: 4 h 12 min 5 s
    15125 DIV 3600 = 4; 725 DIV 60 = 12; 15125 MOD 60 = 5.
Q10Extended programming task (15-mark scenario) · Challenge · Paper 2 style · 15 marks

A cold-storage warehouse near Okara stores mangoes for export. A temperature reading (°C, REAL) is taken every hour for 7 days and stored in a two-dimensional array Temp[1:7, 1:24]. Safe readings are from 8.0 to 13.0 inclusive.Requirements:• input all 168 readings; any reading below −10 or above 40 must be rejected as a sensor fault and re-entered• for each day output the day number, the lowest and highest reading and the average reading to 1 decimal place• output the day and hour of every unsafe reading• output 'SPOILAGE RISK' for any day that has 3 or more consecutive unsafe readings.You may answer in pseudocode or a high-level programming language. Use meaningful identifiers and add comments.

  1. (a) Write the section that inputs and validates all the readings. [4]
  2. (b) Write the section that outputs each day's lowest, highest and average reading, and the day and hour of every unsafe reading. [7]
  3. (c) Write the section that outputs 'SPOILAGE RISK' for any day with 3 or more consecutive unsafe readings. [4]
Show answer
  1. (a) FOR Day ← 1 TO 7 FOR Hour ← 1 TO 24 REPEAT OUTPUT "Temperature for day ", Day, " hour ", Hour INPUT Temp[Day, Hour] UNTIL Temp[Day, Hour] >= -10 AND Temp[Day, Hour] <= 40 NEXT HourNEXT Day
    1 mark each: nested loops 7 × 24; prompt and input to Temp[Day, Hour]; validation −10 to 40; re-input until valid.
  2. (b) FOR Day ← 1 TO 7 Low ← Temp[Day, 1] High ← Temp[Day, 1] DayTotal ← 0 FOR Hour ← 1 TO 24 DayTotal ← DayTotal + Temp[Day, Hour] IF Temp[Day, Hour] < Low THEN Low ← Temp[Day, Hour] ENDIF IF Temp[Day, Hour] > High THEN High ← Temp[Day, Hour] ENDIF IF Temp[Day, Hour] < 8.0 OR Temp[Day, Hour] > 13.0 THEN OUTPUT "Unsafe reading on day ", Day, " at hour ", Hour ENDIF NEXT Hour OUTPUT "Day ", Day, " low ", Low, " high ", High, " average ", ROUND(DayTotal / 24, 1)NEXT Day
    1 mark each: low and high initialised to first reading of the day; sum reset per day; comparisons update low and high; average = sum / 24 rounded to 1 d.p.; unsafe test < 8.0 OR > 13.0; outputs day and hour of unsafe readings; daily output with messages.
  3. (c) FOR Day ← 1 TO 7 Run ← 0 Risk ← FALSE FOR Hour ← 1 TO 24 IF Temp[Day, Hour] < 8.0 OR Temp[Day, Hour] > 13.0 THEN Run ← Run + 1 IF Run >= 3 THEN Risk ← TRUE ENDIF ELSE Run ← 0 ENDIF NEXT Hour IF Risk = TRUE THEN OUTPUT "Day ", Day, ": SPOILAGE RISK" ENDIFNEXT Day
    1 mark each: counter of consecutive unsafe readings increased; counter reset to 0 on a safe reading; flag set when counter reaches 3 (output only once per day); output with day number.
Q11Extended programming task (15-mark scenario) · Challenge · Paper 2 style · 15 marks

A teacher in Quetta gives a 20-question multiple-choice quiz to a class of 35 students. Each answer is a single character A, B, C or D.The program uses:• Key[1:20] (CHAR) holding the correct answers, already filled• Answers[1:35, 1:20] (CHAR) for the students' answers• StudentName[1:35] (STRING), already filledRequirements:• input every student's answers; accept lower-case letters by converting them to upper case; reject anything other than A–D• calculate each student's score out of 20 and output the name, score and grade (Distinction 17 or more, Merit 13–16, Pass 10–12, otherwise Fail)• output the question number(s) answered correctly by the fewest students.You may answer in pseudocode or a high-level programming language. Use meaningful identifiers and add comments.

  1. (a) Write the section that inputs and validates all answers. [5]
  2. (b) Write the section that calculates and outputs each student's score and grade, and counts how many students got each question right in an array Correct[1:20]. [6]
  3. (c) Write the section that outputs the question number(s) answered correctly by the fewest students. [4]
Show answer
  1. (a) FOR S ← 1 TO 35 FOR Qn ← 1 TO 20 REPEAT OUTPUT StudentName[S], " answer to question ", Qn INPUT Ans Ans ← UCASE(Ans) UNTIL Ans = "A" OR Ans = "B" OR Ans = "C" OR Ans = "D" Answers[S, Qn] ← Ans NEXT QnNEXT S
    1 mark each: nested loops 35 × 20; input with prompt; conversion with UCASE; validation only A–D with re-input; stored in Answers[S, Qn].
  2. (b) FOR Qn ← 1 TO 20 Correct[Qn] ← 0NEXT QnFOR S ← 1 TO 35 Score ← 0 FOR Qn ← 1 TO 20 IF Answers[S, Qn] = Key[Qn] THEN Score ← Score + 1 Correct[Qn] ← Correct[Qn] + 1 ENDIF NEXT Qn IF Score >= 17 THEN Grade ← "Distinction" ELSE IF Score >= 13 THEN Grade ← "Merit" ELSE IF Score >= 10 THEN Grade ← "Pass" ELSE Grade ← "Fail" ENDIF ENDIF ENDIF OUTPUT StudentName[S], " ", Score, "/20 ", GradeNEXT S
    1 mark each: Correct array initialised; score reset for each student; compare Answers[S, Qn] with Key[Qn]; score and Correct[Qn] incremented; grade boundaries correct; output name, score and grade.
  3. (c) Fewest ← Correct[1]FOR Qn ← 2 TO 20 IF Correct[Qn] < Fewest THEN Fewest ← Correct[Qn] ENDIFNEXT QnOUTPUT "Hardest question(s):"FOR Qn ← 1 TO 20 IF Correct[Qn] = Fewest THEN OUTPUT Qn ENDIFNEXT Qn
    1 mark each: minimum initialised; loop finds minimum; second loop finds all questions equal to minimum (handles ties); output with message.
Q12Extended programming task (15-mark scenario) · Challenge · Paper 2 style · 15 marks

A metro bus route in Lahore has 15 stops, numbered 1 to 15. The fare depends on the number of stops travelled: 1–4 stops Rs 30, 5–9 stops Rs 50, 10 or more stops Rs 70. Students pay half fare (rounded down to a whole rupee).The program records journeys during one day using a two-dimensional array Trips[1:15, 1:15] of INTEGER, where Trips[Board, Leave] counts journeys from stop Board to stop Leave.Requirements:• initialise every element of Trips to 0• for each journey, input the boarding stop, the leaving stop (both 1–15 and different) and whether the passenger is a student (Y/N); output the fare and update Trips and the day's takings• stop when 0 is entered as the boarding stop• output the total takings, the number of student journeys, and the busiest journey (the boarding and leaving stops with the highest count).You may answer in pseudocode or a high-level programming language. Use meaningful identifiers and add comments.

  1. (a) Write a function Fare(Board : INTEGER, Leave : INTEGER, Student : BOOLEAN) RETURNS INTEGER that returns the fare for one journey. [5]
  2. (b) Write the section that initialises Trips and processes journeys until 0 is entered. [6]
  3. (c) Write the section that outputs the totals and the busiest journey. [3]
  4. (d) State the fare your function returns for a student travelling from stop 3 to stop 13. [1]
Show answer
  1. (a) FUNCTION Fare(Board : INTEGER, Leave : INTEGER, Student : BOOLEAN) RETURNS INTEGER DECLARE Stops, Cost : INTEGER Stops ← Board − Leave IF Stops < 0 THEN Stops ← -Stops // travel in either direction ENDIF IF Stops <= 4 THEN Cost ← 30 ELSE IF Stops <= 9 THEN Cost ← 50 ELSE Cost ← 70 ENDIF ENDIF IF Student = TRUE THEN Cost ← Cost DIV 2 ENDIF RETURN CostENDFUNCTION
    1 mark each: function header with parameters and return type; number of stops as a positive difference; correct fare bands; half fare using DIV 2 for students; value returned.
  2. (b) FOR F ← 1 TO 15 FOR T ← 1 TO 15 Trips[F, T] ← 0 NEXT TNEXT FTakings ← 0StudentTrips ← 0OUTPUT "Boarding stop (0 to finish)"INPUT BoardWHILE Board <> 0 DO IF Board >= 1 AND Board <= 15 THEN REPEAT OUTPUT "Leaving stop" INPUT Leave UNTIL Leave >= 1 AND Leave <= 15 AND Leave <> Board REPEAT OUTPUT "Student? Y/N" INPUT Reply UNTIL Reply = "Y" OR Reply = "N" IsStudent ← (Reply = "Y") IF IsStudent THEN StudentTrips ← StudentTrips + 1 ENDIF Cost ← Fare(Board, Leave, IsStudent) OUTPUT "Fare: Rs ", Cost Takings ← Takings + Cost Trips[Board, Leave] ← Trips[Board, Leave] + 1 ELSE OUTPUT "Invalid stop" ENDIF OUTPUT "Boarding stop (0 to finish)" INPUT BoardENDWHILE
    1 mark each for any six of: Trips initialised with nested loops; loop ends on 0; boarding stop validated; leaving stop validated (range and different); Y/N validated and student count updated; fare obtained by calling the function and output; takings and Trips[Board, Leave] updated.
  3. (c) OUTPUT "Takings: Rs ", Takings, " Student journeys: ", StudentTripsBestF ← 1BestT ← 1FOR F ← 1 TO 15 FOR T ← 1 TO 15 IF Trips[F, T] > Trips[BestF, BestT] THEN BestF ← F BestT ← T ENDIF NEXT TNEXT FOUTPUT "Busiest journey: stop ", BestF, " to stop ", BestT
    1 mark each: totals output; nested loop searching all elements for the maximum; both indices stored and output.
  4. (d) Rs 35
    10 stops → Rs 70; half fare 70 DIV 2 = 35.
Q13Pre-release material tasks (old syllabus) · Core · Paper 2 style · 11 marks

Pre-release style scenario (practise as if you had programmed it beforehand):A cricket academy in Sialkot measures the speed of every delivery in km/h at a fast-bowling camp. There are 8 bowlers and each bowls 6 deliveries.Task 1 – store the names of the 8 bowlers, then input the 6 speeds for each bowler. A speed is valid only if it is from 60 to 160 km/h.Task 2 – calculate and output each bowler's name and average speed, rounded to one decimal place.Task 3 – find and output the fastest single delivery of the camp and the name of the bowler who bowled it.

  1. (a) Write pseudocode to declare the arrays needed for Task 1. Use BowlerName to store the 8 names and Speed to store the 6 speeds of each bowler. [2]
  2. (b) Write pseudocode for the part of Task 1 that inputs and validates one speed and stores it in Speed[B, D], where B is the bowler number and D the delivery number. [3]
  3. (c) State which of these inputs your validation would reject: 58, 60, 160, 172.5 [1]
  4. (d) In Task 2, Usman's six speeds are 132.4, 138.0, 141.6, 129.9, 135.2 and 137.5. Calculate his average speed, rounded to one decimal place. [2]
  5. (e) Explain how your program would carry out Task 3. [3]
Show answer
  1. (a) DECLARE BowlerName : ARRAY[1:8] OF STRINGDECLARE Speed : ARRAY[1:8, 1:6] OF REAL
    1 mark: BowlerName as a 1D array of 8 strings. 1 mark: Speed as a 2D array 8 × 6 of REAL.
  2. (b) OUTPUT "Enter speed in km/h"INPUT SWHILE S < 60 OR S > 160 DO OUTPUT "Invalid – speed must be from 60 to 160" INPUT SENDWHILESpeed[B, D] ← S
    1 mark: prompt and input. 1 mark: loop with the correct range check (< 60 OR > 160) and an error message with re-input. 1 mark: valid value stored in Speed[B, D].
  3. (c) 58 and 172.5
    1 mark for both values and no others (60 and 160 are boundary values that are accepted).
  4. (d) 135.8 km/h
    M1: total 814.6 ÷ 6 (= 135.766…). A1: 135.8.
  5. (e) Set Fastest to the first speed, Speed[1, 1], and FastBowler to 1. Use nested loops to visit every bowler (1 to 8) and every delivery (1 to 6). If Speed[B, D] is greater than Fastest, store it in Fastest and store B in FastBowler. After the loops output BowlerName[FastBowler] and Fastest.
    1 mark: initialise the highest value (first element or 0) with a variable for the bowler. 1 mark: nested loops through all 48 speeds comparing each with the highest so far and updating both variables. 1 mark: output the name (using the stored index) and the speed.
Q14Pre-release material tasks (old syllabus) · Core · Paper 2 style · 9 marks

Pre-release style scenario (practise as if you had programmed it beforehand):A school in Rawalpindi is running a tree-planting week. Each of its 6 classes plants trees every day for 5 days.Task 1 – set up arrays to store the class names and the number of trees planted by each class on each day; input and validate the daily numbers (0 to 50).Task 2 – calculate and output the total trees for each class and for the whole school.Task 3 – output the name of the class that planted the most trees.

  1. (a) Describe the arrays you would use for Task 1, giving names, sizes and data types. [3]
  2. (b) Write an algorithm for Task 2. [4]
  3. (c) Explain how your program would perform Task 3. [2]
Show answer
  1. (a) ClassName[1:6] of STRING for the class names; Trees[1:6, 1:5] of INTEGER for trees planted by each class on each day (or six 1D arrays, one per day); a ClassTotal[1:6] of INTEGER may be added for Task 2.
    1 mark: array for class names, size 6, STRING. 1 mark: 2D array (6 × 5) or equivalent for daily trees. 1 mark: INTEGER data type for trees.
  2. (b) SchoolTotal ← 0FOR C ← 1 TO 6 ClassTotal[C] ← 0 FOR D ← 1 TO 5 ClassTotal[C] ← ClassTotal[C] + Trees[C, D] NEXT D OUTPUT ClassName[C], " planted ", ClassTotal[C] SchoolTotal ← SchoolTotal + ClassTotal[C]NEXT COUTPUT "Whole school: ", SchoolTotal
    1 mark each: totals initialised; nested loops over classes and days; class total output with name; school total accumulated and output.
  3. (c) Set a variable Most to the first class's total and store its index; loop through the other classes comparing each total with Most, and when a total is larger update Most and the index; after the loop output ClassName at the stored index.
    1 mark: largest total and position initialised and compared in a loop. 1 mark: name of class output using the stored index.
Q15Pre-release material tasks (old syllabus) · Standard · Paper 2 style · 10 marks

Pre-release style scenario:A café in Abu Dhabi runs a loyalty scheme for up to 100 customers. Each customer has a 4-digit card number and a points balance.Task 1 – set up the data structures and allow a new customer to be added with 0 points; the card number must be 4 digits and must not already exist.Task 2 – when a customer buys something, input the card number and the amount spent in whole dirhams; add 1 point for every whole 10 dirhams spent.Task 3 – when a customer has 200 or more points, offer a free drink, which uses 200 points.

  1. (a) Write an algorithm for Task 2. Assume arrays CardNo[1:100] and Points[1:100] and a variable NumCustomers. [5]
  2. (b) Explain how your program checks that a new card number is valid in Task 1. [3]
  3. (c) Calculate the points earned for spending 87 dirhams, and state the new balance of a customer who had 196 points. [2]
Show answer
  1. (a) OUTPUT "Card number"INPUT CardFound ← 0FOR I ← 1 TO NumCustomers IF CardNo[I] = Card THEN Found ← I ENDIFNEXT IIF Found = 0 THEN OUTPUT "Card not found"ELSE OUTPUT "Amount spent" INPUT Spent Points[Found] ← Points[Found] + Spent DIV 10 OUTPUT "Points balance: ", Points[Found]ENDIF
    1 mark each: card input; search through customers to find the card; not-found message; amount input; points increased by amount DIV 10 (whole tens only) and balance output.
  2. (b) It checks that the card number is a whole number between 1000 and 9999 (or that the string has length 4 and contains only digits); it then searches the CardNo array to make sure the number is not already used; if either check fails an error message is shown and the number is re-entered.
    1 mark: range/length check for 4 digits. 1 mark: search for duplicates in the existing card numbers. 1 mark: re-input with a message if invalid.
  3. (c) 8 points; new balance 204 (the customer can now get a free drink).
    1 mark each.
Q16Pre-release material tasks (old syllabus) · Challenge · Paper 2 style · 14 marks

Pre-release style scenario (practise as if you had programmed it beforehand):A coach company runs three trips a day from Lahore to Islamabad, leaving at 07:00, 13:00 and 19:00 (departures 1, 2 and 3). Each coach has 40 seats.Task 1 – set up an array SeatsLeft[1:3] with every value set to 40, and set the day's takings to 0.Task 2 – for a booking, input the departure (1 to 3) and the number of adult and child passengers. An adult ticket costs Rs 2800 and a child ticket Rs 1400. A group of 6 or more passengers gets 10% off the total cost. Refuse the booking if there are not enough seats left. Otherwise output the cost, update the seats left and add the cost to the takings.Task 3 – at the end of the day, output the total takings and the departure time that carried the most passengers.

  1. (a) Write an algorithm in pseudocode for Task 2. Assume the array SeatsLeft[1:3] and a REAL variable Takings have already been set up in Task 1. [6]
  2. (b) A family books 4 adult and 3 child tickets on one departure. Calculate the cost of the booking. Show your working. [2]
  3. (c) A departure has 9 seats left. Give one normal, one boundary and one erroneous value to test the total number of passengers in a booking, and state the expected result of each. [3]
  4. (d) Explain how Task 3 can find the departure with the most passengers, using SeatsLeft. [3]
Show answer
  1. (a) REPEAT OUTPUT "Departure (1, 2 or 3)" INPUT DepUNTIL Dep >= 1 AND Dep <= 3OUTPUT "Number of adults"INPUT AdultsOUTPUT "Number of children"INPUT ChildrenTotal ← Adults + ChildrenIF Total < 1 OR Total > SeatsLeft[Dep] THEN OUTPUT "Booking not possible – seats left: ", SeatsLeft[Dep]ELSE Cost ← Adults * 2800 + Children * 1400 IF Total >= 6 THEN Cost ← Cost * 0.9 ENDIF SeatsLeft[Dep] ← SeatsLeft[Dep] - Total Takings ← Takings + Cost OUTPUT "Cost: Rs ", CostENDIF
    1 mark each for: input and validation of the departure (1 to 3); input of adults and children with total calculated; check that 1 ≤ total ≤ seats left, with a message if not; cost = adults × 2800 + children × 1400; 10% discount only when total ≥ 6; seats left reduced and takings increased, with cost output.
  2. (b) Rs 13 860
    M1: 4 × 2800 + 3 × 1400 = 15 400. A1: 7 passengers ≥ 6 so 10% off: 15 400 × 0.9 = 13 860.
  3. (c) Normal: 4 – booking accepted.Boundary: 9 – booking accepted (the largest group that fits; 10 would be rejected).Erroneous: 15 (or −2, or "two") – booking rejected with an error message.
    1 mark each: a normal value between 1 and 9 with 'accepted'; a boundary value (9 or 1 accepted, or 10 / 0 rejected) with the correct result; an erroneous value (well outside the range or wrong type) with 'rejected'.
  4. (d) For each departure the passengers carried = 40 − SeatsLeft[d]. Set Most to the passengers on departure 1 and BestDep to 1, then loop through departures 2 to 3; if a departure's passengers is greater than Most, update Most and BestDep. Finally output the departure time for BestDep and Most.
    1 mark: passengers calculated as 40 − SeatsLeft (or the smallest SeatsLeft used). 1 mark: loop comparing each departure with the highest so far and storing which departure it is. 1 mark: output of the departure and the number of passengers (with total takings).
Q17Pre-release material tasks (old syllabus) · Challenge · Paper 2 style · 10 marks

Pre-release style scenario:On sports day, a school in Kandy has four houses (Red, Blue, Green, Yellow). There are 12 events. In each event, 1st place earns 5 points, 2nd 3 points and 3rd 1 point.Task 1 – for each event, input the houses that came 1st, 2nd and 3rd; a house cannot be placed twice in the same event.Task 2 – keep a running total of points for each house and output the totals after every event.Task 3 – at the end, output the houses in order from highest to lowest points.

  1. (a) Write an algorithm for Task 1 and Task 2 for one event. Assume House[1:4] holds the house names and Total[1:4] holds the points so far. [6]
  2. (b) Explain how a bubble sort could be used to perform Task 3. [3]
  3. (c) After all 12 events, calculate the total number of points awarded to all houses together. [1]
Show answer
  1. (a) REPEAT OUTPUT "House numbers (1-4) for 1st, 2nd and 3rd" INPUT First, Second, ThirdUNTIL First <> Second AND First <> Third AND Second <> Third AND First >= 1 AND First <= 4 AND Second >= 1 AND Second <= 4 AND Third >= 1 AND Third <= 4Total[First] ← Total[First] + 5Total[Second] ← Total[Second] + 3Total[Third] ← Total[Third] + 1FOR H ← 1 TO 4 OUTPUT House[H], ": ", Total[H]NEXT H
    1 mark each: input of three placings; range check 1–4; check no house is repeated; re-input until valid; correct points added to the right totals (5, 3, 1); loop to output all four house totals.
  2. (b) Compare the totals of adjacent houses; if the first is smaller than the second, swap the totals and also swap the house names so they stay matched; repeat passes through the list until a pass is made with no swaps; then output the names and totals in order.
    1 mark: adjacent pairs compared and swapped (descending order). 1 mark: names swapped together with totals. 1 mark: repeated passes until no swaps (or n − 1 passes) then output.
  3. (c) 108
    12 × (5 + 3 + 1) = 108.
Q18String handling and operators · Core · Paper 2 style · 5 marks

A program contains the statement:City ← "Islamabad"In the string functions, the first character is at position 1. SUBSTRING(Text, Start, Length) returns Length characters starting at position Start.

  1. (a) State the output of each statement:(i) OUTPUT LENGTH(City)(ii) OUTPUT UCASE(City)(iii) OUTPUT SUBSTRING(City, 1, 5)(iv) OUTPUT SUBSTRING(City, 6, 4) [4]
  2. (b) Write a statement that outputs the first letter of City in lower case. [1]
Show answer
  1. (a) (i) 9 (ii) ISLAMABAD (iii) Islam (iv) abad
    1 mark each.
  2. (b) OUTPUT LCASE(SUBSTRING(City, 1, 1))
    B1 correct nesting of LCASE and SUBSTRING with start 1 and length 1.
Q19String handling and operators · Standard · Paper 2 style · 7 marks
  1. (a) State the value of each expression:(i) 47 MOD 5(ii) 47 DIV 5(iii) ROUND(47 / 5, 1) [3]
  2. (b) State whether each Boolean expression is TRUE or FALSE:(i) (8 >= 8) AND (3 <> 3)(ii) NOT (5 < 2) OR FALSE(iii) (10 MOD 4 = 2) AND (10 DIV 4 = 2) [3]
  3. (c) Write a single expression using MOD that is TRUE only when the integer variable Year is divisible by 4. [1]
Show answer
  1. (a) (i) 2 (ii) 9 (iii) 9.4
    1 mark each.
  2. (b) (i) FALSE (ii) TRUE (iii) TRUE
    1 mark each. (iii) 10 MOD 4 = 2 and 10 DIV 4 = 2, both true.
  3. (c) Year MOD 4 = 0
    B1.
Q20String handling and operators · Challenge · Paper 2 style · 6 marks
  1. (a) Write an algorithm in pseudocode that:• inputs a sentence• counts how many vowels (a, e, i, o, u, in either case) it contains• outputs the number of vowels.Use the string functions LENGTH, SUBSTRING and LCASE. [5]
  2. (b) State the output of your algorithm when the input is "Data Science". [1]
Show answer
  1. (a) INPUT SentenceVowels ← 0FOR Pos ← 1 TO LENGTH(Sentence) Letter ← LCASE(SUBSTRING(Sentence, Pos, 1)) IF Letter = "a" OR Letter = "e" OR Letter = "i" OR Letter = "o" OR Letter = "u" THEN Vowels ← Vowels + 1 ENDIFNEXT PosOUTPUT "Number of vowels: ", Vowels
    1 mark each: input sentence and counter initialised to 0; loop from 1 to LENGTH(Sentence); extract one character with SUBSTRING(…, Pos, 1); convert to lower case and compare with all five vowels; increment and output count after loop.
  2. (b) 5
    a, a, i, e, e.
Q21Data types, variables, constants, selection and iteration · Core · Paper 2 style · 8 marks
  1. (a) A program for a sports club stores the following data. Give the most suitable data type (INTEGER, REAL, CHAR, STRING or BOOLEAN) for each.(i) a member's age in whole years(ii) the membership fee, e.g. 1250.50(iii) the member's grade, a single letter such as B(iv) whether the member has paid(v) the member's phone number, e.g. 0300-1234567 [5]
  2. (b) Explain the difference between a variable and a constant. [2]
  3. (c) Write a pseudocode statement that declares a constant for the joining fee of 500. [1]
Show answer
  1. (a) (i) INTEGER (ii) REAL (iii) CHAR (iv) BOOLEAN (v) STRING
    1 mark each. (v) STRING because it contains a hyphen/leading zero and is not used in calculations.
  2. (b) A variable's value can change while the program runs; a constant's value is set once and cannot change while the program runs.
    1 mark: variable can change during execution. 1 mark: constant is fixed during execution.
  3. (c) CONSTANT JoiningFee ← 500
    B1 (identifier without spaces).
Q22Data types, variables, constants, selection and iteration · Standard · Paper 2 style · 7 marks
  1. (a) Name the three types of loop structure used in pseudocode and state when each is most suitable. [3]
  2. (b) Study this algorithm:X ← 100Count ← 0REPEAT X ← X DIV 2 Count ← Count + 1UNTIL X < 5OUTPUT Count, " ", XState the output. [2]
  3. (c) Rewrite the algorithm in (b) using a WHILE loop so that it gives the same output. [2]
Show answer
  1. (a) FOR…NEXT (count-controlled) – when the number of repetitions is known; REPEAT…UNTIL (post-condition) – when the loop must run at least once; WHILE…DO…ENDWHILE (pre-condition) – when the loop may not need to run at all.
    1 mark for each loop with a correct use.
  2. (b) 5 3
    1 mark Count = 5; 1 mark X = 3 (100 → 50 → 25 → 12 → 6 → 3).
  3. (c) X ← 100Count ← 0WHILE X >= 5 DO X ← X DIV 2 Count ← Count + 1ENDWHILEOUTPUT Count, " ", X
    1 mark: WHILE … DO … ENDWHILE structure. 1 mark: condition reversed to X >= 5.
Q23Data types, variables, constants, selection and iteration · Challenge · Paper 2 style · 7 marks
  1. (a) Study this algorithm:Total ← 0FOR Count ← 1 TO 6 Num ← (Count * 3) MOD 4 IF Num = 0 THEN Total ← Total + 10 ELSE Total ← Total + Num ENDIFNEXT CountOUTPUT TotalState the value of Num on each pass of the loop, and the final output. [4]
  2. (b) Rewrite the IF statement in the algorithm as a CASE statement that gives the same result. [3]
Show answer
  1. (a) Num: 3, 2, 1, 0, 3, 2. Output: 21.
    2 marks for all six values of Num (1 mark for at least four correct); 2 marks for 21 (M1 for adding 3 + 2 + 1 + 10 + 3 + 2).
  2. (b) CASE OF Num 0 : Total ← Total + 10 OTHERWISE Total ← Total + NumENDCASE
    1 mark: CASE OF Num … ENDCASE. 1 mark: case 0 adds 10. 1 mark: OTHERWISE adds Num.
Q24File handling · Core · Paper 2 style · 5 marks
  1. (a) Explain why a program might store data in a file. [2]
  2. (b) Write pseudocode to store the value of the variable HighScore in a new text file called "scores.txt". [3]
Show answer
  1. (a) Data in variables and arrays is lost when the program ends; storing it in a file keeps it permanently so it can be used again later or by another program.
    1 mark: data is kept permanently / not lost when the program closes. 1 mark: can be reloaded later / shared with another program.
  2. (b) OPENFILE "scores.txt" FOR WRITEWRITEFILE "scores.txt", HighScoreCLOSEFILE "scores.txt"
    1 mark each: open the file for WRITE; WRITEFILE with the variable; close the file.
Q25File handling · Standard · Paper 2 style · 6 marks
  1. (a) The file "members.txt" stores the number of members on its first line, followed by one member name per line. Write pseudocode that reads every name into the array Names[1:200] and outputs how many names were read. [5]
  2. (b) State what happens to the existing contents of a file when it is opened FOR WRITE. [1]
Show answer
  1. (a) OPENFILE "members.txt" FOR READREADFILE "members.txt", NumMembersFOR I ← 1 TO NumMembers READFILE "members.txt", Names[I]NEXT ICLOSEFILE "members.txt"OUTPUT NumMembers, " names read"
    1 mark each: open for READ; read the first line into a count variable; loop for that number of lines; READFILE into Names[I]; close file and output count.
  2. (b) They are overwritten (the file is replaced with the new data).
    B1.
Q26File handling · Challenge · Paper 2 style · 8 marks
  1. (a) A shop stores its daily sales in the array Sales[1:7] of REAL. Write a procedure SaveWeek() that writes the seven values to the file "week.txt", one per line, and then reads them back from the file and outputs their total. [6]
  2. (b) Explain why the file must be closed after writing before it is opened again for reading. [2]
Show answer
  1. (a) PROCEDURE SaveWeek() DECLARE Value, Total : REAL OPENFILE "week.txt" FOR WRITE FOR Day ← 1 TO 7 WRITEFILE "week.txt", Sales[Day] NEXT Day CLOSEFILE "week.txt" Total ← 0 OPENFILE "week.txt" FOR READ FOR Day ← 1 TO 7 READFILE "week.txt", Value Total ← Total + Value NEXT Day CLOSEFILE "week.txt" OUTPUT "Week total: ", TotalENDPROCEDURE
    1 mark each: PROCEDURE … ENDPROCEDURE; open FOR WRITE and loop writing all 7 values; close before reopening; open FOR READ and loop reading 7 values; total accumulated (initialised to 0); file closed and total output.
  2. (b) Closing makes sure all the data has been saved to the file (buffers written) and releases the file, so it can be reopened in a different mode starting from the beginning.
    1 mark: ensures data is fully written/saved. 1 mark: file can then be reopened (in read mode, from the start).
Q27Arrays · Core · Paper 2 style · 7 marks

The array Marks[1:5] of INTEGER holds these values: Marks[1] = 56, Marks[2] = 78, Marks[3] = 91, Marks[4] = 45, Marks[5] = 67.

  1. (a) State the value of Marks[3]. [1]
  2. (b) Write the pseudocode statement that declares the array. [2]
  3. (c) Write pseudocode to calculate and output the average mark. [3]
  4. (d) State the average your algorithm would output. [1]
Show answer
  1. (a) 91
    B1.
  2. (b) DECLARE Marks : ARRAY[1:5] OF INTEGER
    1 mark: ARRAY[1:5]. 1 mark: OF INTEGER with DECLARE and identifier.
  3. (c) Total ← 0FOR I ← 1 TO 5 Total ← Total + Marks[I]NEXT IOUTPUT "Average: ", Total / 5
    1 mark: total initialised; 1 mark: loop adding Marks[I]; 1 mark: average output.
  4. (d) 67.4
    337 ÷ 5.
Q28Arrays · Challenge · Paper 2 style · 8 marks

A company stores the number of laptops sold by 3 branches in 4 quarters in the array Sales[1:3, 1:4] (branch, quarter):Branch 1: 12, 15, 9, 20Branch 2: 8, 22, 14, 11Branch 3: 17, 10, 19, 13

  1. (a) State the value of Sales[2, 3]. [1]
  2. (b) Write pseudocode that finds and outputs the quarter in which the most laptops were sold in total by all three branches. [5]
  3. (c) State the output of your algorithm for this data, and the total for that quarter. [2]
Show answer
  1. (a) 14
    B1 branch 2, quarter 3.
  2. (b) BestQ ← 1BestTotal ← 0FOR Q ← 1 TO 4 QTotal ← 0 FOR B ← 1 TO 3 QTotal ← QTotal + Sales[B, Q] NEXT B IF QTotal > BestTotal THEN BestTotal ← QTotal BestQ ← Q ENDIFNEXT QOUTPUT "Best quarter: ", BestQ
    1 mark each: outer loop over quarters; quarter total reset; inner loop over branches adding Sales[B, Q]; comparison updating best total and quarter; output.
  3. (c) Quarter 2, with 47 laptops.
    1 mark each (quarter totals 37, 47, 42, 44).
Q29Procedures, functions and library routines · Standard · Paper 2 style · 8 marks
  1. (a) Explain the difference between a procedure and a function. [2]
  2. (b) Explain the difference between a local variable and a global variable. [2]
  3. (c) State the value returned by each library routine:(i) ROUND(7.468, 2)(ii) 29 MOD 6(iii) 29 DIV 6 [3]
  4. (d) Write a statement that assigns a random whole number from 1 to 6 to the variable Dice, using the library routine RANDOM(), which returns a value from 0 up to (but not including) 1. [1]
Show answer
  1. (a) A function always returns a single value to the point where it was called; a procedure performs a task but does not return a value (it is used with CALL).
    1 mark: function returns a value. 1 mark: procedure does not return a value / is called as a statement.
  2. (b) A local variable is declared inside a procedure or function and can only be used there; a global variable is declared in the main program and can be used anywhere in the program.
    1 mark each.
  3. (c) (i) 7.47 (ii) 5 (iii) 4
    1 mark each.
  4. (d) Dice ← ROUND(RANDOM() * 6 + 0.5, 0)
    B1 any correct expression giving only whole numbers 1 to 6, e.g. ROUND(RANDOM() * 6 + 0.5, 0) (each value equally likely). Also accept ROUND(RANDOM() * 5, 0) + 1 (gives 1 to 6, though 1 and 6 are less likely).
Q30Procedures, functions and library routines · Challenge · Paper 2 style · 7 marks

A bookshop gives loyalty points with this function:FUNCTION Points(Amount : INTEGER, Member : BOOLEAN) RETURNS INTEGER DECLARE P : INTEGER P ← Amount DIV 100 IF Member = TRUE THEN P ← P * 2 ENDIF IF P > 50 THEN P ← 50 ENDIF RETURN PENDFUNCTION

  1. (a) State the value returned by each call:(i) Points(2350, FALSE)(ii) Points(2350, TRUE)(iii) Points(3020, TRUE) [3]
  2. (b) Identify the parameters of the function and the local variable. [2]
  3. (c) Write a statement in the main program that calls the function for a member who spends Rs 4100 and adds the result to the variable Balance. [2]
Show answer
  1. (a) (i) 23 (ii) 46 (iii) 50
    1 mark each; (iii) 30 × 2 = 60, capped at 50.
  2. (b) Parameters: Amount and Member. Local variable: P.
    1 mark: both parameters. 1 mark: P.
  3. (c) Balance ← Balance + Points(4100, TRUE)
    1 mark: function called with correct arguments. 1 mark: result added to Balance in an assignment.
Q31Maintainable programs · Core · Paper 2 style · 6 marks
  1. (a) Give four ways a programmer can make a program easier to maintain. [4]
  2. (b) Explain why maintainable programs are important for a software company. [2]
Show answer
  1. (a) Use meaningful identifiers; add comments; use procedures and functions (modular code); use indentation/white space; use constants for fixed values.
    1 mark each for any four of: meaningful identifier names; comments; procedures/functions; indentation; white space; constants.
  2. (b) Other programmers (or the same programmer later) must be able to understand the code quickly in order to fix errors or add new features, which saves time and money.
    1 mark: others can understand/update the code. 1 mark: errors fixed or features added more easily/cheaply.
Q32Maintainable programs · Standard · Paper 2 style · 7 marks

A student wrote this algorithm:INPUT aINPUT bc ← a * 0.17d ← a + c − bOUTPUT dThe algorithm calculates the price to pay for an item: a is the price, 0.17 is the sales tax rate and b is a discount.

  1. (a) Rewrite the algorithm so that it is easier to maintain. Use a constant, meaningful identifiers, comments and prompts. [5]
  2. (b) Explain why using a constant for the tax rate helps when the rate changes. [1]
  3. (c) Calculate the output when the price is 2000 and the discount is 150. [1]
Show answer
  1. (a) CONSTANT TaxRate ← 0.17// input the price and discountOUTPUT "Enter price"INPUT PriceOUTPUT "Enter discount"INPUT Discount// add tax then subtract the discountTax ← Price * TaxRateAmountToPay ← Price + Tax − DiscountOUTPUT "Amount to pay: ", AmountToPay
    1 mark each: constant for the tax rate; meaningful names for price and discount; meaningful names for tax and total; at least one useful comment; prompts/messages for input and output.
  2. (b) The value only needs to be changed in one place, so it is quicker and every use is updated consistently.
    B1.
  3. (c) 2190
    2000 + 340 − 150 = 2190.

Similar questions

Questions that test the same subtopic in different years, grouped so you can work on one skill at a time.

References only: find each question in its paper (official link where available, otherwise through your school).

Extended programming task (15-mark scenario) 7 questions · 7/9 sessions
Pre-release material tasks (old syllabus) Rare2 questions · 2/9 sessions
String handling and operators 5 questions · 4/9 sessions
Data types, variables, constants, selection and iteration 9 questions · 6/9 sessions
File handling 3 questions · 3/9 sessions
Arrays 3 questions · 3/9 sessions
Procedures, functions and library routines 3 questions · 3/9 sessions

Subtopics

Our analysis of how often each subtopic was examined and how many marks it carried, 2022 to May/June 2026.

SubtopicMarks indexedSessions
Extended programming task (15-mark scenario) 1057/9
Pre-release material tasks (old syllabus) Rare402/9
String handling and operators 234/9
Data types, variables, constants, selection and iteration 226/9
File handling 163/9
Arrays 133/9
Procedures, functions and library routines 123/9
Maintainable programs Rare61/9

← All Computer Science topics