Fetching your paper…
Paper 22, worked through. Cambridge IGCSE Computer Science, May/June 2026: worked solutions
Computer Science 0478/22 · May/June 2026 · 10 questions · 75 marks

Seventy-five marks in an hour and three quarters. The last question is a fifteen-mark program, so leave half an hour for it. Pseudocode is marked for what it does, not for perfect keywords, but it must be precise: write Count ← Count + 1, not "add one". Whenever you write an algorithm, check it against the bullet points in the question one at a time. Each bullet is worth marks, and a missed one is the usual way they are lost.
- 1Picking the pair of statements that are both loops.[1]
The question as printed, from page 2 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- Iteration means repeating. The loops in pseudocode are FOR … NEXT, WHILE … DO … ENDWHILE and REPEAT … UNTIL.
- IF and CASE are selection statements: they choose, they do not repeat.
- Only one option has two loops and no selection statement.
AnswerC: FOR … NEXT and WHILE … DO … ENDWHILE
Three of the four options mix a loop with a selection statement. Check both halves of each option.
Revise this: Iteration: the three kinds of loop - 2Naming the data type that holds one character.[1]
The question as printed, from page 2 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- A single letter, symbol or digit typed on the keyboard is one character.
- The data type for a single character is char.
AnswerB: char
A string holds several characters. Boolean is true or false, and integer and real are numbers.
Revise this: Variables, constants and data types - 3(a)(i)Naming the validation check that makes sure something has been entered.[1]
The question as printed, from page 2 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- The check is that data is present, and the field has not been left blank.
AnswerA presence check
Revise this: Validation and verification - 3(a)(ii)Naming the check that uses an extra value calculated from the others.[1]
The question as printed, from page 2 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- A digit worked out from all the other digits and placed at the end of a code is a check digit.
- When the code is entered, the digit is worked out again and compared.
AnswerA check digit
Revise this: Validation and verification - 3(b)Explaining what a format check is for, with an example.[3]
The question as printed, from page 2 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- A format check tests whether the data follows a set pattern.
- Say what a pattern is: particular kinds of character in particular places, such as two letters followed by four digits.
- Then give a real example of data that has a fixed pattern.
AnswerPurpose: to check that the data entered matches a required pattern, with set numbers of letters and digits in set positions. Example: a date, which must be in the form DD/MM/YYYY.
Two marks for the purpose and one for the example. The example has to show a pattern. "A password" is not one, but "an email address must contain an @" is.
Revise this: Validation and verification - 3(c)Writing an algorithm that keeps asking until it has stored fifteen whole numbers.[6]
The question as printed, from page 3 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- Fifteen numbers are needed, and the number is known, so use a FOR loop from 1 to 15.
- Each number may have to be asked for more than once, so put a REPEAT … UNTIL loop inside. It always asks at least once.
- A whole number has nothing after the decimal point. MOD(Number, 1) gives the part after the point, so the number is whole when MOD(Number, 1) = 0.
- If it is not whole, output a message and let the REPEAT loop ask again.
- Once it is whole, store it in Accepted, using the FOR loop's counter as the index.
- After the FOR loop, output the message that the check is complete.
AnswerA FOR loop for the fifteen numbers, with a REPEAT loop inside it that asks again until the number is whole.
FOR Count ← 1 TO 15 REPEAT OUTPUT "Enter a whole number" INPUT Number IF MOD(Number, 1) <> 0 THEN OUTPUT "That is not a whole number. Try again." ENDIF UNTIL MOD(Number, 1) = 0 Accepted[Count] ← Number NEXT Count OUTPUT "The check has been completed"One mark each for: the loop for 15, the input, the test for a whole number, asking again until it is whole, storing in the right element, and at least two messages. Tick them off against your answer.
Comparing ROUND(Number, 0) with Number is another accepted test for a whole number.
Revise this: Validation and verification - 4Outlining what is done in the coding stage and in the testing stage.[6]
The question as printed, from page 4 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- Six marks, three for each stage. Give three separate points for each.
- Coding: the program code is written in a programming language, following the flowcharts and pseudocode from the design stage. Comments are added. Each part is tested as it is written, and corrected: this is iterative testing.
- Testing: the whole finished program is tested, using test data for which the correct results are already known. The actual results are compared with the expected ones, and any errors found are corrected.
AnswerCoding: the program is written in a programming language, using the designs from the design stage. Each part is tested as it is written, to make sure it works. Testing: the complete program is tested with test data that has known outcomes, to check that it produces the expected results. Errors that are found are corrected.
Testing happens in both stages, and the difference is the mark. In coding, small parts are tested as they are written. In the testing stage, the whole program is tested with planned test data.
Revise this: The program development life cycle - 5(a)Finding four errors in an algorithm that searches a 2D array, and correcting them.[4]
The question as printed, from page 6 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- Read the description first, then check each line against it.
- Line 03: the account ID "contains letters and numbers", so it cannot be an INTEGER. It should be DECLARE AccountID : STRING.
- Line 05: after the prompt, the program must read the ID from the user, not display it. It should be INPUT AccountID.
- Line 07: a CASE statement does not test a condition like this, and line 10 says ENDIF. It should be IF AccountID = Accounts[Row, 1].
- Line 09: the name must come from the row where the match was found, not always from row 1. It should end with Accounts[Row, 2].
AnswerLine 03: DECLARE AccountID : STRING. Line 05: INPUT AccountID. Line 07: IF AccountID = Accounts[Row, 1]. Line 09: OUTPUT "The customer's name is ", Accounts[Row, 2].
Give the line number and the corrected line in full. Clues are often in the description: "letters and numbers" points straight at the data type.
Revise this: Trace tables and finding errors - 5(b)Naming an algorithm that checks every item of a list in turn.[1]
The question as printed, from page 6 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- The loop looks at each row of the array, from the first to the last, comparing it with the ID.
- Checking each item in turn is a linear search.
AnswerA linear search
Revise this: Linear search and bubble sort - 5(c)Adding statements so that the user is told when the account ID is not in the array.[5]
The question as printed, from pages 6 and 7 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- The program needs to remember whether a match was found. Use a Boolean variable as a flag.
- Before the loop (before line 06), set the flag to FALSE: nothing has been found yet.
- Where the match is found (after line 09, inside the IF), set the flag to TRUE.
- After the loop (after line 11), test the flag. If it is still FALSE, output a message that the ID was not found.
AnswerUse a flag: set it to FALSE before line 06, set it to TRUE after line 09, and after line 11 output a message if it is still FALSE.
// before line 06 DECLARE Found : BOOLEAN Found ← FALSE // after line 09, inside the IF statement Found ← TRUE // after line 11 IF Found = FALSE THEN OUTPUT "The account ID was not found" ENDIFSay where every new statement goes. Without the positions, most of the marks are lost. Putting the "not found" message in an ELSE inside the loop is wrong: it would be output for every row that does not match.
Revise this: Linear search and bubble sort - 6(a)Completing a trace table for a flowchart that examines each letter of a word.[6]
The question as printed, from pages 8 and 9 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- First word, post: WordLength is 4, Count is 0, NumLetter is 1.
- p and o are different, so NumLetter becomes 2. o and s are different: 3. s and t are different: 4. NumLetter now equals WordLength, so 0 is output. Choice is Y, so another word is read.
- Second word, committee: WordLength is 9, Count is 0, NumLetter is 1.
- NumLetter 1 and 2: no match. At NumLetter 3, m and m match, so Count becomes 1. At 4 and 5: no match. At 6, t and t match: Count is 2. At 7: no match. At 8, e and e match: Count is 3.
- NumLetter becomes 9, which equals WordLength, so 3 is output. Choice is N, so the algorithm stops.
Answerpost: WordLength 4, Count 0, NumLetter 1, 2, 3, 4, OUTPUT 0, Choice Y. committee: WordLength 9, Count 0 then 1, 2, 3, NumLetter 1 to 9, OUTPUT 3, Choice N.
The third word, bookkeeper, is never used: the algorithm stops when Choice is N. Extra input data is there to see whether you follow the flowchart or guess.
One mark for each column. Count goes back to 0 for the second word, and so does NumLetter to 1.
Revise this: Trace tables and finding errors - 6(b)Stating what the algorithm is for.[1]
The question as printed, from pages 8 and 9 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- It compares each letter with the one after it, and adds 1 to Count when they are the same.
- So it counts double letters: post has none, and committee has three (mm, tt, ee).
AnswerIt counts, and outputs, the number of pairs of identical letters next to each other in a word.
State the purpose, not the steps. "It compares letters and adds one to a counter" describes how, not what for.
Revise this: Flowcharts and pseudocode - 7(a)Giving a reason for storing data in a file.[1]
The question as printed, from page 10 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- Data in variables is held in memory and is lost when the program stops.
- A file is on secondary storage, so the data is kept.
AnswerSo that the data is not lost when the program ends, and can be used again later.
Revise this: File handling - 7(b)Writing statements to read one line from a text file into a variable.[4]
The question as printed, from page 10 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- Four marks, four statements. Declare a variable with a sensible name to hold the line.
- Open the file for reading.
- Read a line from the file into the variable.
- Close the file.
AnswerDeclare a string variable, open the file for reading, read a line into the variable, and close the file.
DECLARE MemberName : STRING OPENFILE "Names.txt" FOR READ READFILE "Names.txt", MemberName CLOSEFILE "Names.txt"
Put the file name in quotation marks, spelt exactly as in the question, in all three statements. FOR READ, not FOR WRITE: writing would replace what is in the file.
Revise this: File handling - 8(a)Drawing the circuit for a logic expression with five operators.[5]
The question as printed, from page 11 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- One gate for each operator, so five gates. Work from the insides of the brackets outwards.
- NOT C: put C through a NOT gate.
- B OR NOT C: feed B and the output of that NOT gate into an OR gate.
- NOT (B OR NOT C): put the output of the OR gate through a second NOT gate.
- A NAND C: feed A and C into a NAND gate. C is used twice, so its wire splits.
- XOR: feed the outputs of the second NOT gate and the NAND gate into an XOR gate. Its output is Z.
AnswerFive gates: a NOT gate on C; an OR gate with inputs B and NOT C; a NOT gate on the output of the OR gate; a NAND gate with inputs A and C; and an XOR gate that takes the outputs of the second NOT gate and the NAND gate, giving Z.
"Do not simplify" means draw exactly what is written. An OR gate followed by a NOT gate must not be swapped for a NOR gate. One mark for each correct gate with the correct inputs.
Revise this: Logic circuits, truth tables and logic expressions - 8(b)Completing the truth table for the same expression.[4]
The question as printed, from page 11 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- Use the working space for extra columns. Call NOT (B OR NOT C) P, and A NAND C Q.
- P is 1 only when B OR NOT C is 0, which needs B = 0 and C = 1. That is rows 001 and 101. P is 0 in every other row.
- Q is 0 only when A and C are both 1, which is rows 101 and 111. Q is 1 in every other row.
- Z = P XOR Q is 1 when P and Q are different. Row by row: 1, 0, 1, 1, 1, 1, 1, 0.
AnswerZ = 1, 0, 1, 1, 1, 1, 1, 0 for the rows 000 to 111.
Do one gate at a time, a column each. In row 001 both P and Q are 1, so XOR gives 0. In row 111 both are 0, so XOR gives 0 again.
Revise this: Logic circuits, truth tables and logic expressions - 9(a)Choosing a data type for each field of a table of car parts.[4]
The question as printed, from page 12 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- Read each description for what kind of value is stored.
- PartID has letters and numbers: text. PartName is words: text. Size holds a size or the words "one size": text.
- CarType is a four-digit number code: integer. NumberInStock is a quantity, a whole number: integer.
- Price has two decimal places: real. Colour is a single letter: character. InStock is yes or no: Boolean.
AnswerPartID: text. PartName: text. CarType: integer. Price: real. Size: text. Colour: character. NumberInStock: integer. InStock: Boolean.
Use only the six data types listed in the question. A single letter is character, not text. One mark is given for every two correct, so fill in all eight.
Revise this: Databases: tables, fields, records and primary keys - 9(b)Completing an SQL query for three fields of the brake pads.[4]
The question as printed, from page 12 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- SELECT lists the fields wanted: the part ID, the type of car and the quantity in stock. Use the field names from the table: PartID, CarType and NumberInStock.
- FROM names the table: CAR_PARTS.
- WHERE picks the records. "Brake pads" is the name of a part, so test the PartName field. Text goes in quotation marks.
AnswerSELECT PartID, CarType, NumberInStock FROM CAR_PARTS WHERE PartName = 'brake pads';
Copy the field and table names exactly, with no spaces inside them. "List only" means select just those three fields, not all of them.
Revise this: SQL queries - 9(c)Explaining why one field of the table is unnecessary.[2]
The question as printed, from page 12 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- InStock says whether a part is in stock. Look for another field that already tells you that.
- NumberInStock gives the quantity. If it is 0 the part is out of stock, and if it is more than 0 the part is in stock.
AnswerThe NumberInStock field already gives this information: a value of 0 means the part is not in stock, and any larger value means that it is.
Two marks: name the other field, and say how it shows whether the part is in stock.
Revise this: Databases: tables, fields, records and primary keys - 10Writing a complete program to record a year of daily rainfall and analyse it.[15]
The question as printed, from page 14 of the paper.The paper couldn’t be fetched just now, so the question isn’t shown. Open the whole paper Show how to do itHide the working
- Turn the bullet points into a plan: declare, set the array to zero, input 365 values, calculate four statistics, output them, and test for a drought.
- Declare the array with 365 elements of type REAL, and a variable for each thing to be worked out. Use names that say what they hold.
- One FOR loop sets every element to zero. A second inputs the rainfall for each day, with a prompt that says which day.
- A third loop goes through the year. It adds each day to a running total. If the day is dry it counts it, and adds one to the length of the current dry spell, keeping the longest spell seen so far. A day with rain sets the current spell back to zero.
- After the loop: the total in centimetres is the total ÷ 10, rounded to 2 places, and the mean is the total ÷ 365, rounded to 4 places.
- Output each statistic with a message. Then, if the longest dry spell is 15 or more, output the drought message.
AnswerThe program below declares everything it uses, has a comment for each section, and meets every bullet point.
// the array of daily rainfall and the variables used DECLARE Rainfall : ARRAY[1:365] OF REAL DECLARE Day : INTEGER DECLARE TotalMm : REAL DECLARE TotalCm : REAL DECLARE MeanMm : REAL DECLARE DryDays : INTEGER DECLARE DrySpell : INTEGER DECLARE LongestDrySpell : INTEGER // set every element of the array to zero FOR Day ← 1 TO 365 Rainfall[Day] ← 0 NEXT Day // input the rainfall for each day of the year FOR Day ← 1 TO 365 OUTPUT "Enter the rainfall in millimetres for day ", Day INPUT Rainfall[Day] NEXT Day // go through the year: total, dry days and longest dry spell TotalMm ← 0 DryDays ← 0 DrySpell ← 0 LongestDrySpell ← 0 FOR Day ← 1 TO 365 TotalMm ← TotalMm + Rainfall[Day] IF Rainfall[Day] = 0 THEN // a dry day: count it and extend the current dry spell DryDays ← DryDays + 1 DrySpell ← DrySpell + 1 IF DrySpell > LongestDrySpell THEN LongestDrySpell ← DrySpell ENDIF ELSE // rain ends the dry spell DrySpell ← 0 ENDIF NEXT Day // total in centimetres to 2 places, mean in millimetres to 4 places TotalCm ← ROUND(TotalMm / 10, 2) MeanMm ← ROUND(TotalMm / 365, 4) // output the statistics OUTPUT "Total rainfall for the year: ", TotalCm, " cm" OUTPUT "Mean daily rainfall: ", MeanMm, " mm" OUTPUT "Number of days with no rainfall: ", DryDays OUTPUT "Longest run of days with no rainfall: ", LongestDrySpell // fifteen or more dry days in a row is a drought IF LongestDrySpell >= 15 THEN OUTPUT "There was a drought this year" ENDIFThe fifteen marks are for using the right techniques (loops, totalling, counting, selection, an array), for meeting every requirement, and for comments and meaningful names. A program that works but has no comments cannot get full marks.
The hard part is the longest dry spell. It needs two variables: the length of the spell you are in, and the longest so far. Reset the first to zero whenever it rains.
You may write this in Python, Visual Basic or Java if you prefer. Do not mix pseudocode and a programming language in one answer.
Revise this: Arrays
What this paper asked about
Got one wrong? That’s the topic to revise next.
- Validation and verification4 parts
- Trace tables and finding errors2 parts
- Linear search and bubble sort2 parts
- File handling2 parts
- Logic circuits, truth tables and logic expressions2 parts
- Databases: tables, fields, records and primary keys2 parts
- Iteration: the three kinds of loop1 part
- Variables, constants and data types1 part
- The program development life cycle1 part
- Flowcharts and pseudocode1 part
- SQL queries1 part
- Arrays1 part
These explanations are Papermunch’s own, written to teach the method. The answers have been checked against the exam board’s mark scheme, which has the final say: open it above. The question paper and mark scheme belong toCambridge University Press & Assessment: each question shown here is drawn from the paper itself as you read, and is not kept on this site.