EXAM QUESTIONS · IGCSE 0478
Programming Exam-Style Questions with Answers (IGCSE 0478)
Original exam-style questions on data types, MOD and DIV, string handling, loops, arrays, procedures and functions, local and global variables, library routines and file handling for Cambridge IGCSE Computer Science 0478 (Paper 2). There are 25 marks in total. Try each question on paper first, then press Show answer to see the mark scheme.
State the most suitable data type for each value.
- The number of students in a class [1]
- Whether a student has paid for a trip [1]
- The average height of the students in metres [1]
Show answer
- INTEGER [1]
- BOOLEAN [1]
- REAL [1]
State the value of each expression.
- 17 MOD 5 [1]
- 17 DIV 5 [1]
Show answer
- 2 (the remainder) [1]
- 3 (the whole-number result) [1]
State the value returned by each function.
- LENGTH(“Hello World”) [1]
- SUBSTRING(“REVISION”, 3, 4) [1]
- UCASE(“cs”) [1]
Show answer
- 11 (the space counts as a character) [1]
- “VISI” (start at character 3, take 4 characters) [1]
- “CS” [1]
State the output of this algorithm.
Count ← 0
FOR X ← 1 TO 10
IF X MOD 3 = 0
THEN
Count ← Count + X
ENDIF
NEXT X
OUTPUT CountShow answer
18 [2]
The values of X divisible by 3 are 3, 6 and 9, and 3 + 6 + 9 = 18. 1 mark for identifying 3, 6, 9; 1 mark for 18.
A program contains the declaration:
DECLARE Marks : ARRAY[1:30, 1:3] OF INTEGER
- State how many values the array can store. [1]
- Write a pseudocode statement to store the value 72 in row 5, column 2. [1]
Show answer
- 90 (30 × 3) [1]
- Marks[5, 2] ← 72 [1]
Write a pseudocode function called Larger that takes two integers as parameters and returns the larger of the two.
Show answer
FUNCTION Larger(Num1 : INTEGER, Num2 : INTEGER) RETURNS INTEGER
IF Num1 > Num2
THEN
RETURN Num1
ELSE
RETURN Num2
ENDIF
ENDFUNCTION- 1 mark: function header with two parameters
- 1 mark: RETURNS INTEGER
- 1 mark: correct comparison with IF … ELSE … ENDIF
- 1 mark: returns the correct value in both cases, and ENDFUNCTION
Explain the difference between a local variable and a global variable.
Show answer
- A local variable is declared inside a subroutine and can only be used inside that subroutine. [1]
- A global variable is declared in the main program and can be used anywhere in the program. [1]
State the output of ROUND(7.456, 2) and explain why programmers use library routines such as ROUND and RANDOM.
Show answer
- 7.46 [1]
- Library routines are already written and tested, so they save time and are less likely to contain errors. [1]
Write pseudocode to store the value of the variable Name in a text file called names.txt.
Show answer
OPENFILE "names.txt" FOR WRITE WRITEFILE "names.txt", Name CLOSEFILE "names.txt"
- 1 mark: OPENFILE … FOR WRITE
- 1 mark: WRITEFILE with the file name and Name
- 1 mark: CLOSEFILE
State the output of this algorithm.
Word ← "computer" Result ← "" FOR Pos ← 1 TO LENGTH(Word) STEP 2 Result ← Result & SUBSTRING(Word, Pos, 1) NEXT Pos OUTPUT Result
Show answer
cmue [2]
The loop takes the letters at positions 1, 3, 5 and 7: c, m, u, e. The & operator joins strings together.
Frequently asked questions
Which string functions do I need for IGCSE 0478?
LENGTH, LCASE, UCASE and SUBSTRING. SUBSTRING(string, start, length) starts counting from position 1 in Cambridge pseudocode.
Are these past paper questions?
No. These are original exam-style questions written by a Computer Science teacher in the Cambridge style.
Revise the topic: IGCSE programming notes · How to write pseudocode · 15-mark question guide · Coding Lab · All exam-style questions