A York cinema logs 24 seats sold and a 12-second booking. Why use two types?
A cinema in York sells twenty-four seats for a screening. Its app also records a booking that took twelve seconds. Both numbers are whole today. What could happen tomorrow that would make the app need a different kind of number for the booking time?
You’ve already sorted lists of numbers. Here are the seat counts for four screenings: twenty-four, eighteen, thirty-one and twelve. A sorting algorithm can compare them to put the screenings in order. Before you can sort them, the program needs to store each count.
When one more seat sells, the count jumps from twenty-four to twenty-five. There’s no seat count halfway between them. Now look at the timer. A booking could take twelve seconds, twelve and a half seconds, or thirteen seconds.
The app records two numbers: the number of seats sold and the time it took to book. Which value can include a fraction and still make sense? Pick one answer.
A data type sets which values you can store and how you can use them. Integers represent whole numbers, including negatives and zero. Reals can also represent numbers with a fractional part. Use an integer for seats sold and a real for booking time. You can compare and sort both.
Start with twenty-four seats and add one more to get twenty-five. Choose integer for the seat count and store twenty-five. For the booking time, add half a second to twelve seconds to get twelve point five seconds. Choose real for the time and store twelve point five.
At the next screening, the app records thirty-one seats sold and a booking time of eight point two seconds. The types need to suit future readings too. Pick the best pair, with the seat count first and the time second.
Suppose today’s booking takes exactly twelve seconds. If you look only at today’s reading, an integer might seem fine. Tomorrow’s booking could take twelve and a quarter seconds. Choose a real so the app can store both the whole-number reading and the one with a fraction.
If an exam asks you to state and justify a suitable data type, give the type and explain what values are possible. For forty seats sold, choose integer because seats are counted in whole numbers. For a nine-second booking, choose real because another booking could take nine and a half seconds.