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
what does the DIV operator do?
returns the whole number part of a division (not the remainder)
26
what does the MOD operator do?
it returns the remainder of a division
27
what is the typical operator to find a quotient?
DIV
28
what are the typical operators to perform a remainder (modulus) function?
MOD or %
29
what are the two typical operators for exponentiation (powers)?
^ or **
30
what is the assignment operator?
=
31
what is the assignment operator used for?
it's used to assign values to constants or variables
32
what do comparison operators do?
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)
33
what is the comparison operator that means 'is equal to'?
==
34
which comparison operators mean 'is not equal to'?
<> or !=
35
is it <= or =< ?
<=
36
is it >= or =>?
>=
37
is it != or =!
!=
38
do you use a double equals sign for assignment or comparison?
comparison`
39
which two things can data values be stored as?
constants or variables
40
what does the size of the memory location allocated to a constant or variable depend on?
the data type
41
when is the value of a constant assigned? can it be changed?
a constant is assigned a data value at design time that can't be changed
42
what happens if you attempt to change the value of a constant in a program?
the interpreter or compiler will return an error
43
why are variables more useful than constants?
they can change
44
can you change the data type of a variable?
no, only the value
45
what is it called when strings are joined together to form new strings? which operator is often used to do this?
it is called concatenation, and it's often done using the + operator
46
if string = "hello", then what would string[2] be? why?
"l", because it starts from 0
47
what does the function .upper do?
changes all characters in a string to upper case (e.g. if x = "Hello" then x.upper would return "HELLO")
48
what is the function used to change all characters in a string to lower case?
.lower (e.g. if x = "HELLO" then x.lower would return "hello")
49
what is the function used to return the number of characters in a string?
variablename.length
50
what function would be used to extract the character in position y from string x?
x[y]
51
what would the function x.subString(a, b) do?
extract a string starting a position a with length b from string x
52
what is the name for special functions such as upper, lower, length, and subString?
methods
53
what do SWITCH-CASE statements do?
check if a variable has specific values
54
when are SWITCH-CASE statements used?
when you want a program to perform different actions for different values of the same variable
55
what is the drawback of SWITCH-CASE statements compared to IF-ELSEIF statements?
they can only check the value of one varable, whereas IF-ELSEIF statements can check if multiple conditions are true
56
give an example of a count-controlled loop
FOR loops
57
what will FOR loops do?
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
in a FOR loop, what would k = 1 to 10 step 3 do?
it would count up from 1 to 10 in steps of 3, so k=1, k=4, k=7, k=10
59
what would a FOR loop do if no step count is given?
the count will increase by 1 each time
60
what would a "default:" case mean in a SWITCH-CASE statement?
it tells the program what to do if none of the other cases are correct - it helps to make the statement more robust
61
which condition controlled loop s a REPEAT UNTIL loop the same as?
a DO UNTIL loop
62
what are the features of a DO UNTIL loop?
- 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
what are the features of WHILE loops?
- 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
what are the features of DO WHILE loops?
- 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
when does the boolean operator AND return true?
when both inputs are true
66
when does the boolean operator OR return true?
when one of the two inputs is true
67
what does the boolean operator NOT do?
it reverses the value (an input of 1 would return 0 and an input of 0 would return 1)
68
how might you see the boolean operator AND written in some code?
&&
69
how might you see the boolean operator OR written in some code?
||
70
how might you see the boolean operator NOT written in some code?
!
71
what order are boolean operations carried out in?
brackets, NOT, AND, then OR
72
what is an array?
a data structure that can store a collection of data values all under one name
73
what is each piece of data in an array called? how can they be accessed?
an element - each element can be accessed using its position (or index) in the array
74
when are arrays most helpful?
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
what is a data structure?
a format for storing data - other data structures include records, files and databases
76
what does combining array functions with FOR loops give you?
a systematic way of accessing and changing all of the elements in an array
77
give two examples of how FOR loops can be used with an array
FOR loops can be used to search for specific elements, or make a similar change to lots of elements
78
how is the position of an element usually written in a two-dimensional array?
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
give an example of what two-dimensional arrays can be used for
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
what is the first thing you need to do when handling files?
open the file
81
how do you open files in OCR exam reference language?
myFile = open("sample.txt")
82
what should you do when you're finished reading or writing to a file?
you should always close it using
83
how do you close a file in OCR exam reference language?
myFile.close()
84
how do you add a string to a file in OCR exam reference language?
myFile.writeLine("Hello World")
85
what is the command to read lines of text from a file?
readLine()
86
what does the endOfFile() command do?
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
why would data be stored externally in a program?
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
what is a record?
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
why can records be more useful than arrays?
they can store values with different data types, such as strings, integers and Booleans
90
what is each item in a record called?
a field
91
what is each field given when a record is created?
a data type and a field name
92
what can the field name help to do in records?
it can help to describe the data stored in that field of the record
93
can you add extra fields to records once they have been created?
no - they are fixed in length
94
how can you access a record in a computer program?
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
what data structure can you use to group records together?
arrays
96
what does SQL stand for?
Structured Query Language
97
what can SQL be used for?
to search tables (usually in a database) for specific data
98
what is a record in a database?
a row
99
what is a field in a database?
a column
100
what is the SELECT keyword followed by in SQL?
the names of the fields (columns) you want to retrieve and display
101
what is the FROM keyword followed by in SQL?
the name of the table (or tables) you want to search
102
write an SQL statement to return the fields hotel_name and hotel_rating from the table hotels
SELECT hotel_name, hotel_rating FROM hotels
103
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'
SELECT * FROM hotels WHERE hotel_rating >= 4.1
104
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'
SELECT hotel_name, price_in_pounds FROM hotels WHERE hotel_name LIKE "%Hotel"
105
what is the % character used for in SQL?
it is used to represent any combination of letters and/or numbers
106
do you use NOT or != in SQL statements?
!=
107
what can sub-programs be used for?
they can be used to save time and simplify code by avoiding repeating it
108
what are functions and procedures? What's the difference?
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
when are procedures and functions useful?
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
what are parameters?
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
what are arguments?
the actual values that the parameters take when the sub program is called
112
do functions return a value?
yes
113
do parameters always take values?
they can do, but they don't always
114
do functions always take parameters? do they always return values?
functions take at least one parameter and they must always return a value
115
what needs to be done when a function is called? what will happen if this is not done?
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
what does the scope of a variable tell you?
which parts of the program the variable can be used in (local or global)
117
where can local variables by used?
only within the structure they're declared in - they have a local scope
118
where can global variables be used?
any time after their declaration - they have a global scope
119
what type of variables are variables that are declared inside a sub program?
local variables - they are invisible to the rest of the program - this means that they can't be used outside the function
120
what is the advantage of local variables?
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
which variables can be made into global variables?
variables in the main body of the program (not sub-programs)
122
how can variables in the main body of a program be made into global variables?
using the 'global' keyword - these variables can then be used anywhere in the program.
123
what is a disadvantage of global variables?
it can be difficult to keep track of the value of global variables in larger programs.