B2.1 Programming fundamentals questions for IB Computer Science

164 questions on Programming fundamentals, written by Augment in the style of IB exam papers. Six of them are below in full, to answer on paper.

  • IB Computer Science
  • Part of B2 Programming
  • SL and HL

Questions by paper and level

SL and HL questions are for students at either level. HL only questions cover what only HL students study.

PaperSL and HLHL onlyAll
Paper 1044
Paper 213228160
Every paper13232164

Counted on

Questions to try

Written by Augment in the style of IB exams, not past papers. Answer them on paper, then check each one against its markscheme with a free account.

Question 1 · CS-00101Paper 1 · HL only · 6 marks

A ticket kiosk program has 60 lines. Line 2 displays a welcome message. Line 35 contains a syntax error (a missing bracket). Line 18 contains a logic error: it adds the booking fee twice.

  1. (a)

    The program is run by a pure line-by-line interpreter, and the user's choices cause every line from 1 to 35 to be reached.

    Deduce what the user sees.

    2 marks

  2. (b)

    The same program is instead passed to a compiler.

    Deduce what happens.

    2 marks

  3. (c)

    Explain why neither translator reports the error on line 18.

    2 marks

Question 2 · CS-01015Paper 2 · 6 marks

A fitness app awards a badge when a user's daily step count is at least 10 000. The problem specification says a step count is a whole number from 0 to 100 000 inclusive; any other value is rejected as a sensor error.

  1. (a)

    Construct a table of four test cases for this feature, giving the input and the expected output for each. Include at least one boundary value and one invalid value.

    4 marks

  2. (b)

    Explain why boundary values should be included in the test plan.

    2 marks

Question 3 · CS-00109Paper 1 · HL only · 3 marks

A university's online judge tests students' programming assignments by compiling each submission and then running it against hidden test data.

  1. (a)

    State one kind of error that would stop a submission from compiling.

    1 mark

  2. (b)

    Explain why a submission that compiles successfully can still crash when the judge runs it.

    2 marks

Question 4 · CS-01021Paper 2 · 7 marks

A mountain weather station sends a record every ten minutes. A program stores each record in variables before it is uploaded.

Item

Example value

Station name

Ben Alder North

Air temperature (°C)

−3.7

Whether it is snowing

yes

Wind direction, as one compass letter

N

Number of records sent so far today

87

  1. (a)

    State the most appropriate data type for a variable that stores each of the five items in the table.

    5 marks

  2. (b)

    The station's emergency contact number, +44 1632 960512, is also stored. Explain why it should not be stored as an integer.

    2 marks

Question 5 · CS-00570Paper 1 · HL only · 12 marks

A university runs a first-year programming course for 400 students. The lecturers are choosing between a language that is usually interpreted and one that is compiled to bytecode before running on a virtual machine.

  1. (a)

    State what is meant by source code.

    1 mark

  2. (b)

    Identify two differences between the files a student would hand in with each language if asked to submit a runnable program.

    2 marks

  3. (c)

    Explain how the time at which errors are detected differs between the two languages, and why this matters for a beginner.

    3 marks

  4. (d)

    Discuss which language the lecturers should choose for this course.

    6 marks

Question 6 · CS-01022Paper 2 · 9 marks

A multi-storey car park charges £2.50 for each hour or part of an hour. The following code works out the fee for one stay.

Python

Python
minutes = 135
hours = minutes // 60
extra = minutes % 60
if extra > 0:
    hours = hours + 1
rate = 2.5
fee = hours * rate
print(hours, fee)

Java

Java
int minutes = 135;
int hours = minutes / 60;
int extra = minutes % 60;
if (extra > 0) {
    hours = hours + 1;
}
double rate = 2.5;
double fee = hours * rate;
System.out.println(hours + " " + fee);
  1. (a)

    State the data type of the variable extra and of the variable fee.

    2 marks

  2. (b)

    Copy and complete the trace table for the code.

    minutes

    hours

    extra

    fee

    output

    135

    3 marks

  3. (c)

    Deduce the output when minutes is set to 59 instead of 135.

    2 marks

  4. (d)

    Explain why the code uses integer division (// in Python, / with two int operands in Java) to calculate hours.

    2 marks

Practice all 164 in Augment

Free with an account. Every question has its markscheme, and Augment keeps the ones you got wrong so you can come back to them.

The notes on B2.1 Programming fundamentals

More questions in Programming

  1. B2.1Programming fundamentalsThis page
  2. B2.2Data structures
  3. B2.3Programming constructs
  4. B2.4Programming algorithms
  5. B2.5File processing

Check your answers in Augment

A free account opens all 164 questions on Programming fundamentals with their markschemes, and keeps a record of what you have marked.