Digital development concepts
Computer programs use data storeA data store is a location for keeping and managing collections of data including databases and simpler types such as files and emails to organise different data within a program.
Data can be constant or variable within programs and functions. When we create a program, we also need to create ways for users to input data into the program and output information from it.
Input, output, variables, constants and assignment
To store data within a computer program you need to create a data store. This can either be a constant, a variableA named storage location. The value of a variable can change or an arrayA set of data values of the same type, stored in a sequence in a computer program. Also known as a list. .
Variables
A variable is a named memory location. Data stored in that location changes throughout the duration of the program, for example the high score in a computer game.
When we create a variable, we allocate a space in the memory for it and give it a name.
We give variables names as identifiers to help explain the value assigned to it. For example, age = 16.
We assign values to variables using an assignmentSetting the value of a variable in a computer program. operator. For example, = (the 'equals' sign).
We can change the value of our variable at any time during the running of a program. For example, age = age + 1. Here, we have added 1 to the value of the variable 'age'. The age variable will now store the value 17.
Constants
A constant is a named location in memory that contains a value, that does not change during the execution of a program. Data is assigned to a constant in the same way as a variable. For example, in a computer game:
CONST CHARACTERSPEED = 5
CONST GRAVITY = -5When writing code, we often use UPPER CASE to help identify constants.
Arrays
If you need to store multiple values you will need to use an arrayA set of data values of the same type, stored in a sequence in a computer program. Also known as a list. . This is a set of values of the same data typeThe format in which a variable or constant holds data, such as ‘integer’ or ‘string’. stored under one identifier.
Input functions
To get input from a user we have to use an functionA group of instructions, also known as a procedure. The input function is used to ask the user a question, and invites them to give a response. This value of this user response is then returned as the result of the function, and is stored in a variable. By default, this will be a stringA sequence of characters often stored as a variable in a computer program. These characters can include numbers, letters and symbols. , however we can use castingA way to convert a variable from one data type to another data type. Such as string to integer. (converting one data type into another) to change the data type. For example:
To output information from a computer program we use a procedureA set of code instructions that tell a computer how to run a program (this is not used for printing output on to paper). Most programming languages will provide a print procedure for writing or displaying information to the screen. For example: