DigiBacc

Practice questions › IB Computer Science › Programming
IB Computer Science

Programming practice questions.

213 exam-style questions on Programming with answers and explanations. Six real samples below — the full set is free with an account.

Syllabus

Topics covered

Try it

Sample questions

A booking system must store a customer telephone number that begins with a zero and is never used in a calculation. Which data type is the most suitable?

  • Integer
  • Real
  • String
  • Boolean

Answer: String

Stored as a number the leading zero would be lost and no arithmetic is ever wanted on the value, so the digits are held as characters. A telephone number looks numeric but behaves like text.

A variable is created inside a subprogram and its value is not passed back to the calling code. Which statement about that variable is correct?

  • It keeps its value between separate calls of the subprogram
  • It can be read by any other subprogram in the program
  • It must be given the same name as the value returned
  • It exists only while the subprogram is running

Answer: It exists only while the subprogram is running

A local variable is created when the subprogram is entered and destroyed when it ends, so nothing outside can reach it and nothing survives to the next call. That is exactly why the same identifier may be reused safely elsewhere.

A whole number of items is typed at the keyboard and arrives in the variable ENTRY as text. The program must add that number to a running total. What must happen before the addition can be carried out?

  • ENTRY must be converted to an integer
  • The running total must be converted to text
  • ENTRY must be stored as a Boolean value
  • The running total must be rounded to a whole number

Answer: ENTRY must be converted to an integer

Arithmetic needs a numeric type, so the characters have to be converted to an integer before they can be added; joining text to text would only place the digits side by side. Converting the running total to text instead would lose the arithmetic altogether.

A programmer stores the names of a class in an array that is created with 30 places. Which consequence follows directly from the array being a static data structure?

  • The number of places is decided when the array is created, so a 31st name cannot be stored.
  • The names are held at memory locations that are chosen separately for each name as it is stored.
  • The array grows on its own once more than 30 names have been stored in it.
  • Each place in the array may hold a value of a different data type.

Answer: The number of places is decided when the array is created, so a 31st name cannot be stored.

A static structure fixes its capacity at creation, so the only ways out are to create a larger array and copy, or to choose a dynamic structure. Arrays also store their elements contiguously and hold a single data type, so the other statements describe no array at all.

A print server holds documents until the printer is free and prints them in the order in which they were sent to it. Which data structure models this behaviour?

  • A stack, because the item added most recently is removed first.
  • An array, because each document is reached directly by its index number.
  • A collection, because the documents are traversed from the first one to the last.
  • A queue, because the item that has waited longest is removed first.

Answer: A queue, because the item that has waited longest is removed first.

Printing in the order of arrival is first-in first-out, which is exactly the queue rule. A stack would print the newest document first and leave the earliest job waiting indefinitely.

A club stores, for each member, a name (string), a membership number (integer) and whether the fee is paid (Boolean). Which approach keeps the three values of different data types together as one item?

  • Three separate arrays that share the same index position
  • A record whose named fields hold the three values
  • A one-dimensional array holding the three values
  • A stack onto which the three values are pushed

Answer: A record whose named fields hold the three values

A record groups values of different types under named fields, so one member is one item. An array is homogeneous and could not hold a string, an integer and a Boolean, and parallel arrays keep the values in three separate places that must be kept in step by hand.

That was 6 of 213 Programming questions.

Practise all 213 free
Exam tips

Command terms in this unit

213 Programming 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.