3.2 Programming Flashcards

1
Q

The three combining principles that are basic to all high-level imperative programming languages.

A

sequence, iteration/repetition and selection/choice

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The three programming constructs:

A

Sequence, selection, iteration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Two types of iterations (2 names each), also known as

A
definite iteration (also known as count-controlled iteration)
indefinite iteration (also known as condition-controlled iteration)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Sequence is

A

Sequence is the order in which programming statements are executed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why is the sequence of a program important?

A

The sequence of a program is extremely important as once these are translated, carrying out instructions in the wrong order leads to a program performing incorrectly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In this pseudo-code program, designed to find the average of two whole numbers, there is an error. What kind?

total ← 0 
average ← number1/number2
OUTPUT “Enter the first number”
number1 ← USERINPUT
OUTPUT “Enter the second number”
number2 ← USERINPUT 
OUTPUT "The average is " + average
A

Running this program would result in a logic error, because it tries to calculate the average before it knows the values of the numbers.

This version has the instructions in the correct sequence:

total ← 0 
OUTPUT “Enter the first number”
number1 ← USERINPUT
OUTPUT “Enter the second number”
number2 ← USERINPUT
average ← number1/number2
OUTPUT "The average is " + average
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Selection is?

- it is the process of?

A

Selection is a programming construct where a section of code is run only if a condition is met.

  • Selection is the process of making a decision.
  • The result of the decision determines which path the program will take next.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does selection work?

A

Selection works by testing a condition. The test gives a Boolean result - TRUE or FALSE.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In programming, how is selection implemented? - so how would it be written in pseudo-code

A

In programming, selection is implemented using IF THEN ELSE statements:

OUTPUT “How old are you?”
age ← USERINPUT
IF age > 16 THEN
OUTPUT “You are old enough to drive a car”
ELSE
OUTPUT “Come back when you are older!”
ENDIF

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Iteration is

A

The repetition of a block of statements within a computer program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Iteration is often referred to as _ (2)

A

Iteration is often referred to as looping, since the program ‘loops’ back to an earlier line of code. Iteration is also known as repetition.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why iteration is helpful?

A

Iteration allows programmers to simplify a program and make it more efficient . Instead of writing out the same lines of code again and again, a programmer can write a section of code once, and ask the program to execute the same line repeatedly until no longer needed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When a program needs to iterate a set number of times, this is known as __ iteration and makes use of a __ loop.

A () loop uses an extra variable called a __ __ that keeps track of the number of times the loop has been run.

A

Definite iteration
FOR loop

A FOR loop uses an extra variable called a loop counter that keeps track of the number of times the loop has been run.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

This program would print a message out six times:

OUTPUT “Coding is cool”
OUTPUT “Coding is cool”
OUTPUT “Coding is cool”
OUTPUT “Coding is cool”
OUTPUT “Coding is cool”
OUTPUT “Coding is cool”

Improve efficiency using iteration.

A

Definite iteration (also known as count-controlled iteration):

FOR count ← 1 TO 6
OUTPUT “Coding is cool”
ENDFOR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

FOR count ← 1 TO 6
OUTPUT “Coding is cool”
ENDFOR

What kind of variable is ‘count’ ? (not important)

A

Stepper variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Use iteration to print out the ten times table, from 1 to 10.

A

The stepper variable used to initialise a FOR loop can be used within the loop itself. This program uses a loop’s condition variable to print the ten times table:

FOR count ← 1 TO 10
OUTPUT count * 10
ENDFOR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How does iteration simplify a program? (2)

A

As can be seen above, by using iteration a program is simplified, less error prone and more flexible. This is because:

There are fewer lines of code, meaning fewer opportunities for typing errors to creep in

To increase or decrease the number of iterations, all the programmer has to do is change the loop’s end value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is STEP?

A

It is also possible to add the keyword STEP to the first line of a FOR loop to determine how much the stepper variable increases or decreases by with each iteration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Code to output 1, 3, 5, 7, 9 as the value of count increases by two for each iteration

A

FOR count ← 1 TO 10 STEP 2
OUTPUT count
ENDFOR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Code to display 5, 4, 3, 2, 1

A

The code below would display 5, 4, 3, 2, 1 as the value of count decreases by one for each iteration:

FOR count ← 5 TO 1 STEP -1
OUTPUT count
ENDFOR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What does indefinite iteration do

A

Indefinite iteration repeatedly executes a section of code until a condition is met - or no longer met.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

There are two types of indefinite iteration:

A

There are two types of indefinite iteration:

WHILE loops - uses the statements WHILE and ENDWHILE

REPEAT UNTIL loops - uses the statements REPEAT and UNTIL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Print a string six times, using a while loop

A
count ← 0
WHILE count < 6
     OUTPUT “Coding is cool”
     count ← count + 1
ENDWHILE
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

When do WHILE loops test the condition is met

A

At the beginning of the loop.

If the condition is met, the code within the loop is executed before the program loops back to test the condition again.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Scope of the while loop?

A

The WHILE statement defines the start of the loop. The ENDWHILE statement declares the end of the loop. By combining the start and the end, the scope of the statement is identified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

When does a while loop stop?

A

The iteration continues until the condition test result is FALSE, at which point the loop ends and the program executes the next line of code in sequence after the loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Is it possible for the code in a WHILE loop to never be executed.

A

Because the condition is tested at the start of the loop, it is possible for the code within it to never actually be executed. Consider this program:

password ← USERINPUT
WHILE password <> “B1t3s1z£”
     OUTPUT “Password incorrect. Try again.”
     password ← USERINPUT
ENDWHILE
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Are while loops useful for validation?

A

Yh

Consider this program:

password ← USERINPUT
WHILE password <> “B1t3s1z£”
     OUTPUT “Password incorrect. Try again.”
     password ← USERINPUT
ENDWHILE

The first time the condition is tested, the result may be FALSE if the value of password matches. Because of this, none of the code within the loop will be executed and the program will move onto the next line of code in sequence after the loop.

WHILE loops are particularly useful for validation of user inputs as the code can insist that they retry entering data until it is correct.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Difference between a WHILE and REPEAT UNTIL loop

A

REPEAT UNTIL loops function in the same way as WHILE loops, with one major difference - the condition is tested at the end of the loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Print a string ten times using repeat until loop

A
count ← 0
REPEAT
     OUTPUT “Coding is cool”
     count ← count + 1
UNTIL count = 10
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Is it possible for the code in a REPEAT UNTIL loop to never be executed.

A

No.

The REPEAT statement defines the start of the loop. The UNTIL statement tests the condition and declares the end of the statement scope. Because the condition is tested at the end, the code within the loop is always executed at least once, even if the result of the test is FALSE.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Key difference between WHILE and REPEAT UNTIL loop in terms of function

A

With a WHILE loop, the code within the iteration may never be executed. With a REPEAT UNTIL loop, the code is always executed at least once.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Another type indefinite (condition controlled) iteration with the condition at the end - according to spec (not repeat until)

A

DO
… Instructions here …
WHILE NotSolved

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

Use nested iteration to print out the times table for all numbers from one to ten

A

Iteration can also be nested. This program uses two definite FOR loops, one within another, to print out the times table for all numbers from one to ten:

FOR x ← 1 TO 10 
     FOR y ← 1 TO 10
          result ← y * x
          OUTPUT y + " * " + x + " = " + result
     ENDFOR
ENDFOR
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What can be in nested iteration?

A

Nested iteration isn’t limited to FOR loops. A WHILE loop can be nested in a FOR loop and a FOR loop can be nested in a WHILE loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

An example of nested iteration would be:

Using while and for

A

An example of nested iteration would be:

 WHILE NotSolved
   ... Instructions here ...
   FOR i ← 1 TO 5
      ... Instructions here ...
   ENDFOR
   ... Instructions here ...
ENDWHILE
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

An example of nested selection would be:

A

An example of nested selection would be:

 IF GameWon THEN
   ... Instructions here ...
   IF Score > HighScore THEN
      ... Instructions here ...
   ENDIF
   ... Instructions here ...
ENDIF
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

Why nested selection can be good?

A

Nested selection can be built up over and over to include many possibilities and paths for a program to follow. It allows for complex decisions to be made.

(Strange answer)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

The grade of a student depends on the marks gained in an exam. The grade bands are
Grade C if the marks are less than or equal to 20%
Grade B if marks are more than 20% and less than or equal to 60%
Grade A if marks are more than 60%

Write pseudo-code using nested something

A

The pseudocode below makes use of nested IFs to work out the grade
Mark USERINPUT(“Enter your exam result as a percentage”)
IF Mark <= 20 THEN
PRINT ‘You obtained a C grade’
ELSE
IF Mark > 20 AND Mark <= 60 THEN
PRINT ‘You obtained a B grade’
ENDIF
ELSE
PRINT ‘You obtained an A grade’
ENDIF

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

Does nested ifs have to be used?

A

No.

IF-THEN-ELSE IF ENDIF (removes the need for multiple indentation levels)

  • see aqa pseudo-code syntax pdf - could not copy it here properly (but two programs are same, but one makes use of nested, while other does not)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

A variable is

A

A variable is a named piece of memory that holds a value. The value held in a variable can - and usually does - change as the program is running.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

A variable’s name is known as

A

Identifier

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

Identifier naming conventions (5)

A

It can contain letters and numbers but must start with a letter.

It must contain at least one letter - at the start of the name.

It must not contain special characters such as !@£$%&* or punctuation characters. However, an underscore can be used.
Spaces are not allowed.

It should contain lowercase letters. However, uppercase letters can be used if a variable name comprises more than one word joined together.

The name should be meaningful - it should represent the value it is holding.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

Use meaningful identifier names and know why it is important to use them.
What should the name do?

A

It is good practice in programming to give variables a sensible name that will help explain its purpose.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

Link between variables and memory locations (not important?)

A

Variables make it easy for a programmer to use memory locations. The computer keeps track of which memory location the variable refers to. All the programmer has to do is remember the identifier the variable was given.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

Variable Declaration

A

Most programming languages require a variable to be identified before a value is assigned to it. This is known as declaring a variable.

Some programming languages, such as Python, do not require variables to be explicitly declared before use.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

Giving a variable a value is known as __

A

Assignment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

A constant is?

A

A constant is a named piece of memory where the value cannot be changed while a program runs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

Why constants are useful

A

Constants are useful because they are declared and assigned once, but can be referred to over and over again throughout the program. This means that if the programmer needs to change the value throughout the program code, they only need to make one change. This can help make a program easier to maintain.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

Constant naming convention

A

Constants follow the same naming conventions as variables, except that they are often written in uppercase. Some programming languages, such as Python, do not support constants.

Constants are used for values that are unlikely to change, for example:

CONSTANT PI ← 3.141

(AQA pseudo-code ‘names of constants will always be written in capitals’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

Global vs local variables?

A

A global variable is one that can be accessed and changed throughout the whole program. Local variables only exist within a particular subroutine.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

Advantages of local variables (2) - guessing there will be another question like this, with better answers later

A

Using local variables rather than global variables makes it easier to debug a program as the value of that variable can only be read or changed within one subroutine.

Another advantage of local variables is memory efficiency. Once a subroutine has finished running, the memory used for all local variables is removed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

27

Data type and purpose?

A

Integer Whole numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

27.5

Data type and purpose

A

Real Decimal numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

A

Data type and purpose

A

Character A single alphanumeric character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
56
Q

ABC

Data type and purpose

A

String One or more alphanumeric characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
57
Q

TRUE

Data type and purpose

A

Boolean TRUE/FALSE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
58
Q

Limitations of different data types (2)

A

integers and real numbers cannot be concatenated, ie joined together.

numbers held in strings cannot be subject to mathematical operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
59
Q

Casting

A

Changing the data type of a variable

60
Q

Operator

A

A character, or characters, that determine what action is to be performed or considered.

61
Q

3 types of operator that programmers use.

These operators are common to most __-__ __ __.

A

There are three types of operator that programmers use:

  • arithmetic operators
  • relational operators
  • Boolean operators

These operators are common to most high-level programming languages.

62
Q

Arithmetic operators allow

A

Arithmetic operators allow numerical operations to be performed on values

63
Q
Arithmetic operation	Operator	Example
Addition
Subtraction
Multiplication	
Real division
Integer division
Remainder
A
Arithmetic operation	Operator	Example
Addition	+	x = x + 5
Subtraction	-	x = x - 5
Multiplication	*	x = x * 5
Real division	/	x = x / 5
Integer division	DIV	x = x DIV 5
Remainder	MOD	x = x MOD 5
64
Q

Relational operators allow

A

Relational operators allow for assignment and for comparisons to be made. They are used in condition testing such as IF statements and loops.

65
Q

Remember the differences in pseudo-code and python for relational operators.

A

.

66
Q

Boolean operators are used

A

Boolean operators are used to combine relational operators to give more complex decisions.

67
Q

3 Boolean operators

A

AND
OR
NOT

IF x > 0 AND x < 10
IF topic = "Computing" OR topic = "Computer Science"
WHILE NOT (a < b) // WHILE NOT x
68
Q

What is an array

A

An array is a data structure that holds similar, related data

69
Q

Each ‘what’ in an array

Each Piece of data within the array is ‘what’

A

(An) Element

70
Q

Each element has a position in the array, and can hold a value.

What is the key thing about data in an array>

A

The data in an array must all be of the same data type.

71
Q

What is an array a substitute for?

A

Sometimes a programmer needs to store a lot of related data. For example, a game might record the scores achieved by players.

One way to do this would be to declare a variable for each score. So for ten scores, the game program would require ten variables:

score1

score2

score3

And so on, up to score10

While certainly possible, this is not a practical method of recording such data. Suppose the program needed to record 100 scores? 100 variables would be required!

A better method to solve the problem above is to use an array.

72
Q

What must be done, before an array can be used?

A

Before an array can be used, it must be declared.

73
Q

To declare an array a programmer gives it at least two properties:

A

an identifier

a size - the number of elements it will hold

74
Q

Once declared, can the name and structure of an array be changed?

A

No

75
Q

Is it possible to declare an array without setting the size first?

A

Yes.

It is possible to declare an array without setting the size first. This is called a dynamic array. To use a dynamic array, data must be added to the end of the array, or a new size set each time more data is added.

In pseudo-code, declaring an array before use is not needed.

76
Q

How to assign a value to an element in an array

A

Values are assigned to an element in an array by referring to the element’s position.

77
Q

Assign the value 100 to the first element in the array ‘score’

A

score[0] ← 100 - would assign the value 100 to the first element in the array

78
Q

How to overwrite values in elements in an array

A

Values in elements can be overwritten at any point, simply by assigning another value to that element.

79
Q

How to retrieve values from an array

A

Values are retrieved from an element in the array by again referring to the element’s positioN

80
Q

Output the the eighth value held in the array ‘score’

A

OUTPUT score[7]

81
Q

What’s a two-dimensional array?

A

A two-dimensional array can hold more than one set of data. This type of array is like a table, with data held in rows and columns.

The following array would hold ten scores for two players. The first player (0) has data stored in the first row. The second player (1) has data stored in the second row.

0 1 2 3 4 5 6 7 8 9
0 100 110 85 80 92 72 66 98 100 120
1 90 99 102 88 78 100 67 120 88 105

82
Q

Declaring a 2D array

A

table ← [[1, 2],[2, 4],[3, 6],[4, 8]]

83
Q

What does indexing in an array start as

A

0

84
Q

2D array, fill in gaps

Identifier[?][?]

A

Identifier[row][column]

85
Q

table ← [[1, 2],[2, 4],[3, 6],[4, 8]]

table[3][1]

Result?

A

table ← [[1, 2],[2, 4],[3, 6],[4, 8]]
table[3][1]

evaluates to 8 as second element # (with index 1) of fourth array # (with index 3) in table is 8

86
Q

How to repeat statements the number of times that there are elements in an array?

A

FOR Identifier IN array
# statements here
ENDFOR

primes ← [2, 3, 5, 7, 11, 13] total ← 0
FOR prime IN primes
ENDFOR
OUTPUT ‘Sum of the values in primes is’ OUTPUT total

87
Q

Make 7 into 11:

MyArray ← (3,56,21,5,7)

A

MyArray ← (3,56,21,5,7)
MyNumber ← 11
MyArray[4] ← MyNumber

88
Q

Declare an empty array called myArray

A

array MyArray []

Ignore?

89
Q

Advantage of array

A

An advantage of array is that a number of sorting, searching and updating functions can be applied to it.

90
Q

Length of myArray in pseudo-code

A

LEN(myArray)

91
Q

Output each element in an array using length function

A

loopcount ← LEN(MyArray) - 1
FOR x ← 0 TO loopcount:
OUTPUT MyArray[x]
ENDFOR

92
Q

Write a program that requests the user to input a list of their favourite animals. The user types in ‘end’ to indicate that the list is complete. This data needs to be stored and then printed out once the input is complete.

In Python

A
favAnimals = []
index = 0

currentAnimal = “”

print(“Enter your favourite animals. Enter ‘end’ when done.”)

while currentAnimal != “end”:
currentAnimal = input()
favAnimals.append(currentAnimal)

print(“Your favourite animals are: “)
for animals in favAnimals:
print(animals)

93
Q

How to delete item at given index in python

A

list.pop(index)

94
Q

thislist = [“apple”, “banana”, “cherry”]

Remove ‘banana’, be deleting its index

A

[‘apple’, ‘cherry’] outputted

thislist = [“apple”, “banana”, “cherry”]
thislist.pop(1)
print(thislist)

95
Q

thislist = [“apple”, “banana”, “cherry”]

Remove the last item.

A

[‘apple’, ‘banana’] outputted

thislist = [“apple”, “banana”, “cherry”]
thislist.pop()
print(thislist)

Or

thislist = [“apple”, “banana”, “cherry”]
thislist.pop(-1)
print(thislist)

96
Q

thislist = [“apple”, “banana”, “cherry”]

Clear the list

A

thislist = [“apple”, “banana”, “cherry”]
thislist.clear()
print(thislist)

97
Q

thislist = [“apple”, “banana”, “cherry”]

Remove ‘banana’ using ‘banana’

A

thislist = [“apple”, “banana”, “cherry”]
thislist.remove(“banana”)
print(thislist)

98
Q

Two dimensional array also known as a __.

Where one-dimensional arrays are __, two dimensional arrays are __.

A

Matrix
Lists
Tables

99
Q

Declaring a 2D array pseudo-code, 3 rows, 4 columns : weird

A

My2DArray [3] [4] - teachICT

array score [1,9] - would give an array with two rows and ten columns - bite size

???

100
Q

A 2D array is ideal for

A

A 2D array is ideal for storing any data that has been arranged in a grid - for example the computer screen you are reading right now is made up of pixels, and any pixel can be identified by its vertical and horizontal location

101
Q

Declare a 2D array, with 600 rows and 800 columns

Initialise the structure so that every element is white - this is value 255

A

Wierd

screen ← [600] [800]

FOR row  ← 0 to 599
                    FOR col  ← 0 to 799
                        screen [row] [col] ←  255
                    ENDFOR
                 ENDFOR
102
Q

5 common actions that can be done on arrays

A

append - add an item to the end of an array
insert - insert an item at a specific location in the array, all the data above is moved up one location
delete - remove an item from a location, then all the data moves down one place.
split - split an array at a given point and create two new arrays.
slice - take a chunk of data out of an array to form a new array, the original array remains intact

103
Q

What do records allow?

A

Records allow data values of different types that relate to each other to be stored together instead of in different arrays.

104
Q

Record declaration pseudo-code

A
RECORD Record_identifier
   field1 : 
   field2 : 
   ...
ENDRECORD
105
Q

Record for a car: make, model, reg, price, noOfDoors

A
RECORD Car
make : String 
model : String
reg : String
price : Real noOfDoors : Integer
ENDRECORD
106
Q

Pseudo-code record variable initialisation

A

varName ←
Record_identifier(value1,
value2, …)

107
Q
RECORD Car
make : String 
model : String
reg : String
price : Real noOfDoors : Integer

Initialise a ford: pseudo-code

A

myCar ← Car(‘Ford’, ‘Focus’, ‘DX17

GYT’, 1399.99, 5)

108
Q

Assigning a value to a field in a record - pseudo-code

A

varName.field ← Exp

109
Q

myCar ← Car(‘Ford’, ‘Focus’, ‘DX17
GYT’, 1399.99, 5)

Change model to fiesta, pseudo-code

A
myCar.model ←'Fiesta'
# The model field of the myCar # record is assigned the value # 'Fiesta'.
110
Q

Accessing values of fields within records - pseudocode

A

varName.field

111
Q

What does this do? (Records topic)

OUTPUT myCar.model

A

OUTPUT myCar.model

# Will output the value stored in
the
# model field of the myCar record
112
Q

4 differences between records and arrays

A

An array tends to have the same data type for every element, records often have mixed data type fields

The number of fields within a record is fixed once it is declared, they cannot be added to or deleted as the program runs.

A record declaration does not contain actual data - it is a template with which to create variables of that type.

Arrays can be used to store records with each element in the array of the same record type.

113
Q

String concatenation, how?

A

Concatenation means to join things together. You can do this with strings using the ‘+’ operator.
Like this :-
Line 1: FirstName ← input(“Enter your first name”)
Line 2: Surname ← input(“Enter your surname”)
Line 3: Message ←”Your name is “ + FirstName + “ “ + Surname
Line 4: output(Message)

114
Q

What do you need to remember when concatenating (2)

A
  • same data type (string)

- you must manually add a space if you want it

115
Q

Length ? Python, pseudo-code

A

len()

LEN()

116
Q

Casting to integer, string, real in python, character, code

A
int(item) casts the item into an integer
str(item) casts the item into a string
float(item) casts the item into a floating point real number
chr()
ord()
117
Q

Purpose of ‘import random’

A

It imports the random library(/module) so that… (random integers can be generated)

118
Q

What are subroutines?

A

Subroutines are smaller, named sections of code that are written within a larger program. The purpose of a subroutine is to perform a specific task. This task may need to be done more than once at various points in the main program.

119
Q

Advantages of subroutines explained (3)

A

Subroutines are usually small in size, which means they are much easier to write, test and debug. They are also easy for someone else to understand.

As they are written outside of the main program, subroutines can be saved separately as modules and used again in other programs. This saves time because the programmer can use code that has already been written, tested and debugged.

A subroutine may be used repeatedly at various points in the main program and changed by passing in data known as parameters. However, the code only has to be written once, resulting in shorter programs.

120
Q

2 types of subroutine

A

There are two types of subroutine:

procedures
functions

121
Q

What is a procedure?

A

A procedure is a subroutine that performs a specific task. When the task is complete, the subroutine ends and the main program continues from where it left off. For example, a procedure may be written to reset all the values of an array to zero, or to clear a screen.

122
Q

Procedure pseudo-code syntax

A

SUBROUTINE identifier (parameters)
procedure code
ENDSUBROUTINE

123
Q

How is a procedure run?

A

A procedure is run by calling it. To call it, a programmer uses the procedure name and includes any parameters (values) that the procedure needs, for example:

clear_screen(5)

124
Q

What’s a parameter?

A

In computer programming, a parameter is a value that is passed into a function or procedure.

125
Q

What is function?

A

A function works in the same way as a procedure, except that it manipulates data and returns a result back to the main program.

126
Q

Fucntion example pseudo-code

A

For example, a function might be written to turn Fahrenheit into Celsius:

SUBROUTINE f_TO_c(temperature_in_f)
temperature_in_c ← (temperature_in_f –32) * 5/9
RETURN temperature_in_c
ENDSUBROUTINE

127
Q

How is a function run

A

A function is run by calling it. To call it, a programmer uses the function’s identifier, the value to be passed into the function, and a variable for the function to return a value into, for example:

celsius ← f_to_c(32)

128
Q

Procedures vs function difference (in purpose)

A

Procedures perform a specific task but do not return a value. Functions manipulate data and return a value to the main program.

129
Q

Procedures vs function difference (in code)

A

AQA pseudo-code does not use a different keyword to show the difference between a procedure and a function. Instead, it adds a RETURN statement to show that a subroutine is a function.

130
Q

2 levels to variable scope

A

Global, Local

131
Q

Why use local variables (5) - advantages

A
  1. global variables waste memory
  2. variable names can be unique
  3. global variables can cause bugs local variables 4. start as null each time
  4. global variables are hard to trace

declaring variables in a subroutine means that memory allocation is only needed while the subroutine is executing – if the variables were all declared globally, then unnecessary memory would be used whereas

local variables are removed from memory once the subroutine has completed local variables only need to be unique within the subroutine rather than throughout the whole program – this means that a programmer does not need to know the names of variables used within other subroutines

local variables cannot be changed by another subroutine which could interfere with the way a program work

when a subroutine is executed, all local variables are added to memory with no data so any previous data from a previous execution of a subroutine will not affect the result

..because they can be manipulated by multiple subroutines

132
Q

Why design robust programs?

A

When writing code, it is important to ensure that a program runs correctly and continues to run no matter what actions a user takes. This is done through planning for all possibilities and thinking about what a user may do that the program does not expect.

133
Q

Designing robust programs encompasses three areas:

This anticipation and protection is done through:

A

protection against unexpected user inputs or actions, such as a user entering a letter where a number was expected

confirming that users on a computer system are who they say they are

minimising or removing bugs

This anticipation and protection is done through:

validation
authentication
testing

134
Q

What does validation do

A

A programmer should consider that any inputs a user makes may be incorrect and should plan for such unexpected actions. Using validation helps a programmer to ensure that any data input is possible and sensible.

135
Q

5 types of validation

A

Range check - the input must fall within a specified range. This is usually applied to numbers and dates, but can apply to characters too. For example, when a payment needs to be made to someone, the amount to be entered must be set to be greater than zero and not greater than the available funds.

Length check - the input must not be too long or too short. For example, a surname will require at least one letter, but is unlikely to require more than 40.

Presence check - a data value must be entered. For example, a quantity is required when placing an order.

Format check - the data must be in the correct format. For example, a date must be in the format DD/MM/YYYY.

Type check - the data must be of a specified data type, such as an integer when a quantity is to be specified.

136
Q

Does validation ensure that the data is correct?

- how to get around this

A

Validation does not ensure that the data entered is correct, just that it is possible and sensible. A user may accidentally enter a date of birth that is possible and sensible, but incorrect. The program has no way of knowing that the date has been entered incorrectly.

To get around this, many programs include verification checks - they repeat the entered data to the user and ask them to confirm if this data is correct. If the user confirms the data, the program then assumes it to be correct. This is an example of how planning the design of a program can help reduce errors.

137
Q

In validation, what if data does not follow the rules?

A

Validation applies rules to inputted data. If the data does not follow the rules, it is rejected, reducing the risk that incorrectly input data may crash a program.

138
Q

What is authentication?

A

Authentication is the process of a user confirming that they are who they say they are on a computer system. In a network, this is often done through inputting a username and password. For networks that require high levels of security, authentication may include other methods.

139
Q

The factors of authentication can be broken down into three main groups:

A

something you are - username, bank account number, or anything that identifies the user uniquely

something you know - password, pin, secret answer to a question

something you have - swipe card, biometrics, any other physical identifying device

140
Q

Syntax error

A

Error in a program resulting from code not following syntax rules governing how to write statements in a programming language.

141
Q

Logic error

A

Error in a program which does not cause a program to crash but causes unexpected results.

142
Q

Purpose of testing?

A

The purpose of testing is to help the programmer remove such bugs and to ensure that the program functions as intended.

Testing requires a test plan. This is a list of all the tests that the programmer intends to use to ensure the program functions as intended.

143
Q

What should test data cover

A

Test data is data that is used to test whether or not a program is functioning correctly. Ideally, test data should cover a range of possible and impossible inputs, each designed to prove a program works or to highlight any flaws.

144
Q

3 types of test data

A

normal data - typical, sensible data that the program should accept and be able to process

boundary data - valid data that falls at the boundary of any possible ranges, sometimes known as extreme data

erroneous data - data that the program cannot process and should not accept

145
Q

Tests are laid out in a testing table, which indicates:

A

the test number
a description of what the test intends to check
the test data being used
the type of test - normal, boundary or erroneous
expected outcome
actual outcome

146
Q
valid ← FALSE
WHILE valid = FALSE
     OUTPUT "Enter a number from 1 to 10"
     number ← USERINPUT
     IF number < 1 OR number > 10 THEN
          OUTPUT “Number outside the range 1 to 10. Enter another number”
     ELSE
          valid ← TRUE
     ENDIF
ENDWHILE
OUTPUT ("Number entered is ", number)

This program could be tested using the following normal, boundary and erroneous data.

A

Test no. Description Test data Test type Expected Actual
1 Test that a possible number is accepted 5 Normal Data is accepted Data is accepted
2 Test the lower boundary 1 Boundary Data is accepted Data is accepted
3 Test the upper boundary 10 Boundary Data is accepted Data is accepted
4 Test that the program does not accept a number less than 1 -5 Erroneous Data is not accepted Data is not accepted
5 Test that the program does not accept a number greater than 10 20 Erroneous Data is not accepted Data is not accepted

147
Q

Advantages of subroutines and the structured approach

A
Decomposition
Abstraction
Generalisation
Re-usable
Easier to read code
Debugging
Maintenance
Development teams
Local variables

Using subroutines means that a top-down design can be naturally achieved because the main program forms the top of the tree with each subroutine being a branch of the tree. This means that each task within the top-down design can be tackled separately rather than trying to tackle the whole problem at once.

Abstraction hides unnecessary data. With subroutines, the detail of how each subroutine is removed from the main program meaning that only the identifier name of the subroutine needs to be used, plus any parameters.

Subroutines can be used for a variety of different situations. This generalises the subroutine so it is not just used once. For example, a subroutine that finds the average of all values in an array can be used for any array and not just a specific array within a program.

Subroutines can be used over and over again within a program and if they are within a module they can even be used in other programs. This saves having to repeat sections of code as the subroutine just needs to be called each time instead.
It is easier to read the name of a subroutine than all the detail involved in how the subroutine works. This makes the code easier to follow.

Each subroutine can be tested on its own without being executed as part of the main program. This means that any bugs within the subroutine can be corrected before it is tested within the main program.

If code needs to be changed in the future, then it is easier to change the code within a subroutine rather than having to work through all the code.

It is possible for different people to write the code for each subroutine because each subroutine can exist separately.

All the advantages of local variables discussed on other flashcard