- Subjects
- Computer Science
- Question bank
- B2.1 Programming fundamentals
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.
| Paper | SL and HL | HL only | All |
|---|---|---|---|
| Paper 1 | 0 | 4 | 4 |
| Paper 2 | 132 | 28 | 160 |
| Every paper | 132 | 32 | 164 |
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.
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.
- (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
- (b)
The same program is instead passed to a compiler.
Deduce what happens.
2 marks
- (c)
Explain why neither translator reports the error on line 18.
2 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.
- (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
- (b)
Explain why boundary values should be included in the test plan.
2 marks
A university's online judge tests students' programming assignments by compiling each submission and then running it against hidden test data.
- (a)
State one kind of error that would stop a submission from compiling.
1 mark
- (b)
Explain why a submission that compiles successfully can still crash when the judge runs it.
2 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 |
- (a)
State the most appropriate data type for a variable that stores each of the five items in the table.
5 marks
- (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
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.
- (a)
State what is meant by source code.
1 mark
- (b)
Identify two differences between the files a student would hand in with each language if asked to submit a runnable program.
2 marks
- (c)
Explain how the time at which errors are detected differs between the two languages, and why this matters for a beginner.
3 marks
- (d)
Discuss which language the lecturers should choose for this course.
6 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
minutes = 135
hours = minutes // 60
extra = minutes % 60
if extra > 0:
hours = hours + 1
rate = 2.5
fee = hours * rate
print(hours, fee)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);- (a)
State the data type of the variable
extraand of the variablefee.2 marks
- (b)
Copy and complete the trace table for the code.
minuteshoursextrafeeoutput
135
3 marks
- (c)
Deduce the output when
minutesis set to 59 instead of 135.2 marks
- (d)
Explain why the code uses integer division (
//in Python,/with twointoperands in Java) to calculatehours.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.
More questions in Programming
- B2.1Programming fundamentalsThis page
- B2.2Data structures
- B2.3Programming constructs
- B2.4Programming algorithms
- B2.5File processing
More on Programming fundamentals
- B2.1 Programming fundamentals notesWhat Programming fundamentals covers, explained, with its key terms.
- IB Computer Science question bankEvery Computer Science topic counted, and one question from each with its markscheme.
- Computer Science exam formatEach Computer Science paper, how long it is and its share of the grade.
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.