AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Safe to practise

Week 17 · 2.1 Modelling · 3 lessons
3

Feeding the simulator

Computing 8: Topic 2.1, pp. 197–211
GoalTell apart the data a simulator needs from the user and the data used to build it.
New words
user input · data the user types or chooses while the simulator runsbuilding data · facts and rules the programmer uses when making the simulator, such as limits and speedsoutput · what the simulator shows or reports back to the user
Explanation

A simulator needs two kinds of data. The first kind comes from the user while it runs. In a greenhouse simulator the user may choose how many heaters are on and how many windows are open. The second kind is used by the programmer to build the simulator. It includes facts about the real world, such as how much one heater warms the air and how much one open window cools it. These values are stored in the program, often as constants, so the user does not have to type them. The simulator combines both kinds of data and reports an output, such as the temperature. Better building data gives a more realistic simulator.

Worked examples
Pseudocode
1CONSTANT HEAT = 3
2CONSTANT COOL = 2
3temperature ← 15
4INPUT heaters
5INPUT windows
6temperature ← temperature + heaters * HEAT - windows * COOL
7OUTPUT "Temperature: ", temperature
Output
Temperature: 19
The greenhouse model as pseudocode. HEAT and COOL are building data, set once as constants. heaters and windows are user input. With 2 heaters and 1 window typed, the temperature is 15 + 6 − 2 = 19.
DataKind
number of heaters switched onuser input
how much one heater warms the airbuilding data
number of windows openuser input
how much one open window cools the airbuilding data
starting temperature, 15building data
Sorting the data. Each item is either typed in by the user, or stored by the programmer when the simulator is built.
heaterswindowsTemperature
2119
039
3024
Three runs of the same simulator. Only the user input changes. The building data stays the same.
Class activity

Greenhouse game (no computer). Partner A is the simulator and keeps the rules on a card: start at 15, add 3 for every heater, subtract 2 for every open window. Partner B is the user and chooses heaters and windows, each from 0 to 3. Partner A works out the temperature on paper. B tries to reach a temperature between 18 and 24. Record each try in a table. Then partner A secretly changes one building data value, such as the heater adding 4, and B tries again. What does B notice? If you have a computer or tablet, ask an adult to help you run a similar program.

Practice
1
A simulator lets you practise delivering parcels by bicycle. Which is user input and which is building data: (a) the route chosen by the player; (b) the top speed of a bicycle in the program; (c) how hard the player pedals; (d) how heavy a parcel can be?
DataUser input or building data?
(a) the route chosen by the player?
(b) the top speed of a bicycle?
(c) how hard the player pedals?
(d) how heavy a parcel can be?
2
A different greenhouse has other building data, shown in the code. What is the temperature for 2 heaters and 1 window?
Pseudocode
1CONSTANT HEAT = 4
2CONSTANT COOL = 3
3temperature ← 12
4INPUT heaters
5INPUT windows
6temperature ← temperature + heaters * HEAT - windows * COOL
7OUTPUT "Temperature: ", temperature
3
A tester says the greenhouse simulator is not realistic, because it does not know what the weather is like outside. What kind of data is missing, and how could it be added?
4
Write a list of three user inputs and three building data items for a simulator of a boat on a lake.