Você está na página 1de 4

Activity Programming

Complete the table inserting the correct heading or definition


Declaration

Input
Output
assignment
Variable

Local variable
Global variable
Constants
Sub-routines

A statement of a variable name, data type and


sometimes initial value in most languages, must
be done before the variable is used
Taking data into the program. For example, a mouse click,
selection of a value in a combo box or a value typed into a text
box.
Is data produced from the program. Could be
displayed on-screen or sent to a printer
Setting a variable to a value
A value represented by a name. The value can be
changed throughout the program. The scope of the
variable is where it can be used in the program
(local or global)
Used in one sub-routine only
Can be used anywhere in the program
Is similar to a variable but is not changed; it is always the same
Is part of a program and allows the program to be
broken into chunks. A sub-routine can be called
from the main program as many times as needed.

Worked example
Identify one assignment and one global variable in this code
Global variable

Declaration
Beginning subroutine
Declarations

Dim percentage As Real


Private Sub Button1 on Click
Dim score As Integer
Local variables

Dim totalmarks As Integer =50


Assignment (putting
result of calculation in
percentage)

End of sub-routine

Answer:

Percentage = (score/totalmarks)/100
MessageBox.Show (percentage + %)
End Sub

Assignment
Constant

Fill in the labels of this piece of code:


The four labels are:
Declaration on a global variable
Assignment
Variable
Output
Dim age as Integer

a)Dec

b)Assignment

Dim yearofbirth as Integer

Dim currentyear as Integer = 2014


Private Sub CalcButton onClick
c)Variable

Age=currentyear yearofbirth
MessageBox.Show (age)

d)Output

End Sub
Explain why software developers annotate their code
Software developers annotate their code when writing programs to allow for maintenance. Annotations
are comments written into the code to explain what parts of the program are there for.
Annotating code is useful for a programmer who has been asked to edit or maintain code, as the original
developers comments will help them to understand how it works. Original authors can use their own
annotations as reminders if they need to maintain the code.

Data Types
Complete the following table:
Variable Data Type
Character
String

Definition
A single letter or
number
Any combination of letters,
numbers, symbols and
spaces

Example
M
L McGinn

A whole number
A number with fractions

Integer
Real
Boolean

True or false

23
23.34
True

Which one of these will store 1.75?


Integer
Boolean
Character
Real

Worked example
Suggest an appropriate data type for each variable
CustomerName
String

Gender
Character

Age
Integer

In this example pseudocode, what happens when there is smoke?


If hot = true THEN
Turn on sprinkler
ELSE IF smoke true THEN
Sound alarm
END IF
The alarm sounds

Data structures
How is the first element of an array identified?
A
B
C
D

0
1
2
3

Describe the data structure of a record

Records are like a database


A database is a collection of data
Data about one topic is stored e.g customer details
A row in a table is a record e..g. info about one customer
The columns in a table store categories called fields e.g. Name, Address,
Gender
This table shows an array of zoo animals
0
Lion

1
Giraffe

2
Penguin

3
Elephant

4
Tiger

5
Monkey

Identify the data at zoo [4]


Tiger

Worked example:
Lynda is creating a program for a game of chess.
What data structure should she use? Justify your choice
2D array
It represents the two axes on the board. Each dimension can store
an axis of the board.

6
Peacock

Você também pode gostar