DigiBacc

Practice questions › IB Computer Science › Programming › Programming fundamentals
IB Computer Science · Programming

Programming fundamentals practice questions.

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.

At a glance

About this topic

Syllabus code
B2.1
Subject
IB Computer Science
Topic
B2 · Programming
Questions
43 with worked answers
Question types
11 fill-in-the-gap questions · 11 multiple-choice questions · 7 flashcards · 6 matching tasks · 4 structured questions · 4 true/false questions
Try it

Sample questions on Programming fundamentals

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?

  • Real
  • Integer
  • String
  • Boolean

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.

  • That the numbers run only as far as 250, which is small enough for any numeric type.
  • That a leading zero must be kept and no arithmetic is ever done.
  • That the numbers are stored by a school rather than by a commercial system.
  • That the value is used to look a locker up, which requires a whole-number key.

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.

  • Set the running total to zero, so that the division always has a defined starting value.
  • Convert the running total to a real number, so that the division does not lose a remainder.
  • Test whether the count of marks is zero before dividing.
  • Round the running total down before dividing, so that the result is always a whole number.

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 free
Exam tips

Command terms in this topic

Keep going

More topics in Programming

All of Programming →

43 Programming fundamentals questions — free with an account. Spaced repetition, streaks and full exam simulations included.

Practise them free

This 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.