SLR 2.2 Programming Techniques Flashcards
What is iteration?
‘iteration’ is repeating the same code more than once (looping).
Iteration is one of three main constructs in programming
What type of programming construct is demonstrated by the following pseudocode:
for i=0 to 7
print(i)
next i
This is an example of iteration
How many times would the following pseudocode print?
for i=0 to 7
print(i)
next i
8 times - 0 1 2 3 4 5 6 7
What would the following pseudocode do?
for i=0 to 7
print(i)
next i
it would print the numbers 0 1 2 3 4 5 6 7
Which programming construct is shown by the following pseudocode?
if entry == ”a” then print(“You selected A”) elseif entry == ”b” then print(“You selected B”) else print(“Unrecognised selection”) endif
This is an example of selection
Which programming construct is shown by the following pseudocode?
while answer!=”computer”
answer=input(“What is the password?”)
endwhile
This is an example of iteration
What does the following pseudocode do?
while answer != ”computer”
answer=input(“What is the password?”)
endwhile
repeatedly asks the user to input the password until they enter “computer”
Is the user automatically shown the request for the password to be entered?
while answer != ”computer”
answer=input(“What is the password?”)
endwhile
no - if the variable answer is already == “computer” then the request is not shown.
What is the condition to trigger the request for the password to be entered?
while answer != ”computer”
answer=input(“What is the password?”)
endwhile
if the variable answer is not equal to “computer”
What is sequence?
‘sequence’ is about the ordering of the steps in an algorithm.
sequence is one of 3 main constructs in programming.
Which programming construct is shown by the following pseudocode?
print(“Welcome to my program”)
username = input(“What is your username?”)
password = input(“What is your password?”)
sequence
What is an integer?
A data type that represents whole number values
What is a real?
A data type that represents number values that contain decimal points
What is a Boolean?
A data type that represents only True or False (these are sometimes used to represent on/off or yes/no)
What does alphanumeric mean?
Either a letter or a number
What is a character?
A single alphanumeric value or a symbol (e.g. ! , ? # & etc.)
What is a string?
A series of characters (alphanumeric or symbols) e.g. a sentence or word.
What is an array?
A set of data items of the same type grouped together using a single identifier. Each of the data items is addressed by the variable name and an index e.g. my_index[3] would access the fourth item in the array.
What is a record?
A data structure which consists of a collection of elements, typically in fixed number and sequence and typically indexed by names. The elements of records may also be called fields.
What is selection?
One of the 3 basic programming constructs where a Boolean expression is analysed and the code executed depends on the result of the anaylsis.
What is branching?
It is another name for selection - it is when the code executed depends on a Boolean expression being analysed and the result of the analysis directs what code is executed.
What is a global variable?
A global variable is one which can be used anywhere in a program
What is a local variable?
A local variable is one which is defined and can only be used within one part of a program (usually a function or procedure)
What is modularity?
Modularity is building code in a modular way (in sections).
Give three reasons why a modular approach to coding is a good idea
It allows the task of coding to be split between a team of people, it allows code to be reused (thus shortening the amount of code and thus the time needed to produce it), it is easier to maintain as the code is in one place and reused not repeated throughout the program
What is a module?
A block of code that is reused
What is a procedure?
A module of code that may or may not take parameters but which does not return a value. The procedure should carry out one task or action that is clearly indicated by its name.
What is a function?
A module of code that may or may not take parameters and which returns a value. The function should carry out one task or action that is clearly indicated by its name.
What is a parameter?
A value (or data structure containing a set of values) that are passed to a module of code when it is called.
List the key words for SQL you need to know for GCSE
SELECT, FROM, WHERE, LIKE, AND, OR
In an SQL search how is an asterisk (*) used?
An asterisk (*) is used to select all fields e.g. SELECT * FROM customers WHERE customer_id = 1
In an SQL search how is a percent sign (%) used?
A percent sign (%) is used as a wildcard (to match anything) e.g.
SELECT name, address FROM customers WHERE customer_name LIKE ‘J%’
This would show the name and address of all customers whose name starts with J
What is the difference between a for loop and a while loop?
A for loop will execute a fixed number of times e.g. For x in range(0, 5) will execute 5 times. This is count controlled iteration.
A while loop will execute until the Boolean expression it is based on evaluates to False e.g. While goals < 10 will execute until goals is not less than 10. This is condition controlled iteration.