paper 2 - section 5 - programming Flashcards

1
Q

name 5 different data types

A
  1. integer
  2. real (or float)
  3. boolean
  4. character
  5. string
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is the pseudocode for an integer?

A

int

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

what is the pseudocode for a real (or float)?

A

real

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

what is the pseudocode for boolean?

A

bool

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

what is the pseudocode for character

A

char

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

what is the pseudocode for a string?

A

string

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

what type of data do integers hold?

A

whole numbers only

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

what type of data do reals (or floats) hold?

A

numbers that have a decimal part

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

what are the characteristics of boolean data types?

A

they can take one of two values, usually true or false

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

what type of data does the character data type hold?

A

a single letter, number or symbol

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

what type of data do strings hold?

A

a collection of characters - strings are used to represent text

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

what are the benefits of using the correct data types?

A

using the correct data types makes code more memory efficient, robust and predictable

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

Each data type is allocated a different amount of memory. how much is the typical amount of memory taken up for an integer?

A

2 bytes or 4 bytes

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

Each data type is allocated a different amount of memory. What is the typical amount of memory taken up by a real (or a float)?

A

4 bytes or 8 bytes

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

Each data type is allocated a different amount of memory. What is the typical amount of memory taken up by a boolean value?

A

1 bit is needed but 1 byte is usually used

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

Each data type is allocated a different amount of memory. What is the typical amount of memory taken up by a character?

A

1 byte

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

Each data type is allocated a different amount of memory. What is the typical amount of memory taken up by a string?

A

1 byte for every character in the string

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

what is the difference between weakly typed and strongly typed languages?

A

weakly types languages will try to convert data types to avoid errors, however this can lead to unpredictable results.
Strongly typed languages won’t try to convert data types and so will produce more errors but more predictable results.

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

what is casting used for?

A

it’s used to change the data type

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

programming languages have functions that let you manually convert between data types. What is this known as?

A

casting

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

name 4 commands that can be used in casting

A
  1. int()
  2. float()
  3. bool()
  4. str()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

what does the function ASC( ) do?

A

allow you to find the ASCII number of characters (e.g. ASC(“b”) would convert the character “b” into its ASCII number 98)

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

what does the function CHR( ) do?

A

it allows you to convert an ASCII number into a letter (e.g. CHR(98) would convert the ASCII number 98 into its equivalent character “b”)

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

what do the arithmetic operators do?

A

they take two values and perform a maths function on them

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

what does the DIV operator do?

A

returns the whole number part of a division (not the remainder)

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

what does the MOD operator do?

A

it returns the remainder of a division

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

what is the typical operator to find a quotient?

A

DIV

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

what are the typical operators to perform a remainder (modulus) function?

A

MOD or %

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

what are the two typical operators for exponentiation (powers)?

A

^ or **

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

what is the assignment operator?

A

=

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

what is the assignment operator used for?

A

it’s used to assign values to constants or variables

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

what do comparison operators do?

A

they compare the expression on their left hand side to the expression on their right hand side and produce a Boolean value (either true or false)

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

what is the comparison operator that means ‘is equal to’?

A

==

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

which comparison operators mean ‘is not equal to’?

A

<> or !=

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

is it <= or =< ?

A

<=

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

is it >= or =>?

A

> =

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

is it != or =!

A

!=

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

do you use a double equals sign for assignment or comparison?

A

comparison`

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

which two things can data values be stored as?

A

constants or variables

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

what does the size of the memory location allocated to a constant or variable depend on?

A

the data type

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

when is the value of a constant assigned? can it be changed?

A

a constant is assigned a data value at design time that can’t be changed

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

what happens if you attempt to change the value of a constant in a program?

A

the interpreter or compiler will return an error

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

why are variables more useful than constants?

A

they can change

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

can you change the data type of a variable?

A

no, only the value

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

what is it called when strings are joined together to form new strings? which operator is often used to do this?

A

it is called concatenation, and it’s often done using the + operator

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

if string = “hello”, then what would string[2] be? why?

A

“l”, because it starts from 0

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

what does the function .upper do?

A

changes all characters in a string to upper case (e.g. if x = “Hello” then x.upper would return “HELLO”)

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

what is the function used to change all characters in a string to lower case?

A

.lower (e.g. if x = “HELLO” then x.lower would return “hello”)

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

what is the function used to return the number of characters in a string?

A

variablename.length

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

what function would be used to extract the character in position y from string x?

A

x[y]

51
Q

what would the function x.subString(a, b) do?

A

extract a string starting a position a with length b from string x

52
Q

what is the name for special functions such as upper, lower, length, and subString?

A

methods

53
Q

what do SWITCH-CASE statements do?

A

check if a variable has specific values

54
Q

when are SWITCH-CASE statements used?

A

when you want a program to perform different actions for different values of the same variable

55
Q

what is the drawback of SWITCH-CASE statements compared to IF-ELSEIF statements?

A

they can only check the value of one varable, whereas IF-ELSEIF statements can check if multiple conditions are true

56
Q

give an example of a count-controlled loop

A

FOR loops

57
Q

what will FOR loops do?

A

they will repeat the code inside them a fixed number of times. The number of times that the code repeats will depend on an initial value, end value and the step count

58
Q

in a FOR loop, what would k = 1 to 10 step 3 do?

A

it would count up from 1 to 10 in steps of 3, so k=1, k=4, k=7, k=10

59
Q

what would a FOR loop do if no step count is given?

A

the count will increase by 1 each time

60
Q

what would a “default:” case mean in a SWITCH-CASE statement?

A

it tells the program what to do if none of the other cases are correct - it helps to make the statement more robust

61
Q

which condition controlled loop s a REPEAT UNTIL loop the same as?

A

a DO UNTIL loop

62
Q

what are the features of a DO UNTIL loop?

A
  • controlled by a condition at the end of the loop
  • keep going until the condition is true (i.e. while it is false)
  • they always run the code inside them at least once
  • you get an infinite loop if the condition is never true
63
Q

what are the features of WHILE loops?

A
  • controlled by a condition at the start of the loop
  • keep going while the condition is true (i.e. until it is false)
  • never run the code inside them if the condition is initially false
  • you get an infinite loop if the condition is always true
64
Q

what are the features of DO WHILE loops?

A
  • controlled by a condition at the end of the loop
  • keep going while the condition is true (i.e. until it is false)
  • always run the code inside them at least once
  • you get an infinite loop if the condition is always true
65
Q

when does the boolean operator AND return true?

A

when both inputs are true

66
Q

when does the boolean operator OR return true?

A

when one of the two inputs is true

67
Q

what does the boolean operator NOT do?

A

it reverses the value (an input of 1 would return 0 and an input of 0 would return 1)

68
Q

how might you see the boolean operator AND written in some code?

A

&&

69
Q

how might you see the boolean operator OR written in some code?

A

||

70
Q

how might you see the boolean operator NOT written in some code?

A

!

71
Q

what order are boolean operations carried out in?

A

brackets, NOT, AND, then OR

72
Q

what is an array?

A

a data structure that can store a collection of data values all under one name

73
Q

what is each piece of data in an array called? how can they be accessed?

A

an element - each element can be accessed using its position (or index) in the array

74
Q

when are arrays most helpful?

A

when you have lots of related data that you want to store and it doesn’t make sense to use separate variables - e.g. the names of pupils in a class, etc.

75
Q

what is a data structure?

A

a format for storing data - other data structures include records, files and databases

76
Q

what does combining array functions with FOR loops give you?

A

a systematic way of accessing and changing all of the elements in an array

77
Q

give two examples of how FOR loops can be used with an array

A

FOR loops can be used to search for specific elements, or make a similar change to lots of elements

78
Q

how is the position of an element usually written in a two-dimensional array?

A

the position of an element is usually written as [a,b] or [a][b], where a represents the position of the 1-dimensional list that the element is in and b represents its position within that one-dimensional list. (e.g. print(“Ceara’s favourite tree is “ + trees[2,1])

79
Q

give an example of what two-dimensional arrays can be used for

A

they can be used to store information about a digital image - each pixel’s information can be stored as an element in the array. Programmers can then manipulate the image using array commands, e.g. changing the values of pixels, cutting rows and columns out of the image, etc

80
Q

what is the first thing you need to do when handling files?

A

open the file

81
Q

how do you open files in OCR exam reference language?

A

myFile = open(“sample.txt”)

82
Q

what should you do when you’re finished reading or writing to a file?

A

you should always close it using

83
Q

how do you close a file in OCR exam reference language?

A

myFile.close()

84
Q

how do you add a string to a file in OCR exam reference language?

A

myFile.writeLine(“Hello World”)

85
Q

what is the command to read lines of text from a file?

A

readLine()

86
Q

what does the endOfFile() command do?

A

it returns TRUE when the ‘cursor’ is at the end of the file. Its main use is to signify when a program should stop reading a file.

87
Q

why would data be stored externally in a program?

A

so that it’s not lost when the program is closed. E.g. a computer game will save your progress externally - if it was saved internally you’d lose your progress when the game was closed

88
Q

what is a record?

A

a record is a type of data structure (like an array), which means that it is used to store a collection of data values. In the context of a database table, a record is just a row of data.

89
Q

why can records be more useful than arrays?

A

they can store values with different data types, such as strings, integers and Booleans

90
Q

what is each item in a record called?

A

a field

91
Q

what is each field given when a record is created?

A

a data type and a field name

92
Q

what can the field name help to do in records?

A

it can help to describe the data stored in that field of the record

93
Q

can you add extra fields to records once they have been created?

A

no - they are fixed in length

94
Q

how can you access a record in a computer program?

A

once you’ve created the structure of your record, you can assign it to a variable. You can then use the variable name to access a whole record. Alternatively, you can use the variable name along with a field name to access a particular item of a record
(e.g. variableName = recordName(field1, field2, field3)
print (variableName.field1)

95
Q

what data structure can you use to group records together?

A

arrays

96
Q

what does SQL stand for?

A

Structured Query Language

97
Q

what can SQL be used for?

A

to search tables (usually in a database) for specific data

98
Q

what is a record in a database?

A

a row

99
Q

what is a field in a database?

A

a column

100
Q

what is the SELECT keyword followed by in SQL?

A

the names of the fields (columns) you want to retrieve and display

101
Q

what is the FROM keyword followed by in SQL?

A

the name of the table (or tables) you want to search

102
Q

write an SQL statement to return the fields hotel_name and hotel_rating from the table hotels

A

SELECT hotel_name, hotel_rating FROM hotels

103
Q

write an SQL statement to return all the data about hotels with a rating (hotel_rating) that is greater than or equal to 4.1 from the database ‘hotels’

A

SELECT * FROM hotels WHERE hotel_rating >= 4.1

104
Q

write an SQL statement to return the name (hotel_name) and price (price_in_pounds) of all the hotels that have a name ending in ““Hotel” from the table ‘hotels’

A

SELECT hotel_name, price_in_pounds FROM hotels WHERE hotel_name LIKE “%Hotel”

105
Q

what is the % character used for in SQL?

A

it is used to represent any combination of letters and/or numbers

106
Q

do you use NOT or != in SQL statements?

A

!=

107
Q

what can sub-programs be used for?

A

they can be used to save time and simplify code by avoiding repeating it

108
Q

what are functions and procedures? What’s the difference?

A

procedures are sets of instructions stored under one name - when you want your program to do the whole set of instructions you only need to call the name of the procedure.
Functions are similar to procedures - the main difference is that functions always return a value.

109
Q

when are procedures and functions useful?

A

when you have sets of instructions that you need to repeat in different places within a program. They give your program more structure and readability whilst cutting down on the amount of code you actually need to write

110
Q

what are parameters?

A

parameters are special variables used to pass values into a sub program. For each parameter you can specify a name, a data type and a default value

111
Q

what are arguments?

A

the actual values that the parameters take when the sub program is called

112
Q

do functions return a value?

A

yes

113
Q

do parameters always take values?

A

they can do, but they don’t always

114
Q

do functions always take parameters? do they always return values?

A

functions take at least one parameter and they must always return a value

115
Q

what needs to be done when a function is called? what will happen if this is not done?

A

when a function is called it should be assigned to a variable or used in a statement otherwise the value that it returns will not be stored anywhere and will be lost

116
Q

what does the scope of a variable tell you?

A

which parts of the program the variable can be used in (local or global)

117
Q

where can local variables by used?

A

only within the structure they’re declared in - they have a local scope

118
Q

where can global variables be used?

A

any time after their declaration - they have a global scope

119
Q

what type of variables are variables that are declared inside a sub program?

A

local variables - they are invisible to the rest of the program - this means that they can’t be used outside the function

120
Q

what is the advantage of local variables?

A

their scope only extends to the sub program they’re declared in. They can’t affect and are not affected by anything outside the sub program. It also doesn’t matter if you use the same variable name as a local variable defined elsewhere in the program

121
Q

which variables can be made into global variables?

A

variables in the main body of the program (not sub-programs)

122
Q

how can variables in the main body of a program be made into global variables?

A

using the ‘global’ keyword - these variables can then be used anywhere in the program.

123
Q

what is a disadvantage of global variables?

A

it can be difficult to keep track of the value of global variables in larger programs.