43 exam-style questions on Programming fundamentals — topic B2.1 of Programming in the IB Computer Science syllabus — with answers and explanations. Samples below; the full set is free with an account.
A program stores a person's height in metres, recorded to two decimal places, and uses it in calculations. Which data type is most suitable?
Answer: Real
A real holds a value with a fractional part and can take part in arithmetic, which is what this value needs. An integer would discard the decimal places, and a string would preserve them but could not be used in a calculation until it had been converted.
A school stores locker numbers such as 007 and 250. The numbers are printed on labels and used to look a locker up, but they are never added, averaged or compared for size. Identify the single detail in this description that decides the data type.
Answer: That a leading zero must be kept and no arithmetic is ever done.
A numeric type would store 007 as 7 and lose the printed form, while offering arithmetic that is never wanted. Data that is only ever displayed and matched is held as a string, however digit-like it looks.
A program adds up the marks entered by a teacher and then divides the total by the number of marks entered. The teacher is allowed to enter no marks at all. Identify the step, placed before the division, that deals with this case.
Answer: Test whether the count of marks is zero before dividing.
With no marks entered the count is 0 and the division has no defined result, so the program must recognise that case and report that no mean exists instead of dividing.
A named store whose contents may change while the program is running is called ___. (one word)
Answer: variable
The name is fixed when the program is written but the value it holds may be replaced as often as the program requires. A store whose value cannot be replaced during the run is a constant.
The rules that fix how the statements of a language must be written, so that a translator will accept them, are the ___ of that language. (one word)
Answer: syntax
A statement that breaks these rules is rejected before the program can run at all, whereas a statement that obeys them may still be logically wrong. Syntax governs form, not meaning.
In IB pseudocode, one operator gives the whole-number part of a division and another gives what is left over. State the three-letter operator that gives what is left over. (one word)
Answer: mod
The pair div and mod belong together: div returns the whole-number part and mod returns the remainder, so 23 div 4 is 5 and 23 mod 4 is 3. Other languages write the same operation as % or call it modulo, but IB pseudocode uses mod.
That was 6 of 43 Programming fundamentals questions.
Practise all 43 freeTraceAO2 · 2–4 marks
Follow the algorithm step by step in a trace table, one row per pass, showing every variable that changes.
OutlineAO1 · 1–2 marks
A brief account or summary: the main points in two or three sentences, no evaluation.
StateAO1 · 1–2 marks
One word or one short sentence. No explanation, no working: the mark is for the fact itself.
43 Programming fundamentals questions — free with an account. Spaced repetition, streaks and full exam simulations included.
Practise them freeThis platform is independently developed and is not endorsed by, affiliated with, or sponsored by the International Baccalaureate Organization. “International Baccalaureate” and “IB” are registered trademarks of the IBO.