Programming (PAPER 2) Flashcards

1
Q

What are the five main data types
- What are the characteristics of each

A

Integer - Whole Numbers
Float / Real - Numbers with decimals
Boolean - One of two values, usually True or False
Character - A single letter, number or symbol
String - Used to represent text, is a collection of characters

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

How much memory is used for each main data type

A

Integer - 2 or 4 bytes
Float / Real - 4 or 8 bytes
Boolean - 1 bit needed but 1 byte is usually used
Character - 1 byte
String - 1 byte for every character in the string

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

What are the benefits of using the correct data type (3)

A

more memory efficient, robust, predictable

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

What is casting
- What are the five commands that do this

A

using functions to manually convert between data types
- int (), real (), float (), bool (), str ()

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

What function finds the ASCII number of characters (and vice versa)

A

ASC (), CHR ()

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

What are the 7 basic arithmetic operators (programming)
- What are the operators used for each

A

Addition, Subtraction, Division, Multiplication, Exponentiation, Quotient, Modulus
> +, -, /, *, ^ or **, DIV, MOD or %

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

What is the quotient
- What is the Modulus

A

the whole number value after diving a number e.g. 20 DIV 3 = 6
- the remainder e.g. 20 MOD 3 = 2

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

What two data types do Basic Arithmetic Operators work with

A

real or integer (or both)

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

What is the assignment operator
- What does it assign

A

=

  • values to constants or variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What do comparison operators do

A

compare the value on the left to that on their right and produce a True / False value (Boolean)

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

What are the 6 comparison operators
- What do they mean

A

== is equal to
<> or != is not equal to
< is less than
> is greater than
<= is less than / equal to
>= is more than / equal to

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

How can data values be stored

A

as constants or variables

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

Where is the name of a constant or variable linked to
- What does the size of this depend on

A

A memory location
- the data type

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

What is a constant

A

a value which has been assigned at design time and can’t be changed

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

What is a variable

A

can change value at any time

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

What are the standard naming conventions that programmers follow when naming constants and variables (2)

A

lower case first letter
no spaces

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

How are strings written
- What is the name for merging strings
- Which operator is this done with

A
  • double quotes, but occasionally single quotes
  • concatenation
    • operator
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How are the characters in a string usually numbered

A

starting from 0

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

What are the 6 common string manipulations
- What do each of them do
- What are these special functions known as

A

x.upper, x.lower, x.length, x.left(i), x.right(i), x.substring(a, b)
- Changes all characters in string x to upper case,
changes to lower case,
returns number of characters in string x,
Extracts first i characters from string x,
Extracts last i letters,
Extracts a string starting at position a with length b form a

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

What are substring, left and right methods also examples of

A

slicing - part of a string is extracted and returned as a new string

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

What does an IF statement allow for

A

allows you to check if a condition is true or false, and carry out different actions depending on the outcome

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

What is the usual structure for an IF statement

A

IF-THEN-ELSE

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

What is a nested If statement
- What do these allow you to do

A

an IF statement inside another one
- check more conditions once established that the previous one is true

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

What is the difference between IF-ELSEIF and nested IF statements

A

IF-ELSEIF statements only check more conditions if the previous condition is false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the alternate name for SWITCH statements - What do these do
CASE SELECT - check if a variable has specific values
26
What is written at the end of an IF and SWITCH statement
- endif - endswitch
27
When are SWITCH statements used
when you want a program to perform different actions for different values of the same variable
28
What is written to introduce an IF or SWITCH statement
- if ... then - variable = ... switch variable:
29
What are the benefits and drawbacks of using Switch statements over IF statements
- Easier to maintain. neater to test different values of a variable - only check the value of one variable, IF-ELSEIF statements can check if multiple conditions are true
30
What do FOR loops do
repeat the code inside them a fixed number of times
31
What three values do the number of times a code repeats depend on in a FOR loop
initial value, end value and step count
32
If no step count is provided for a for loop, what will it automatically be
1 step
33
With what code can the number of times the loop repeats can also be set as the program runs
for k = 1 to x (x is a variable)
34
between which two words is the FOR loop repeated
for and next
35
What is a FOR loop concluded with
next k
36
What are the 4 differences between DO UNTIL and WHILE loops
DO UNTIL: - controlled by condition at end of loop - keeps going until condition is true - always runs code within at least once - infinite loop if condition is never true WHILE: - controlled by condition at start of loop - keeps going while condition is true - never run code inside if condition is initially false - infinite loop if the condition is always true
37
When does a DO WHILE loop keep going
while the condition is true and always runs the code inside at least once
38
What are logic gates - What are the three steps of what they do
special circuits built into computer chips - receive binary data - apply a Boolean operation - output a binary result
39
What is written to show logic gates and circuits
logic diagrams
40
What are the three types of logic gate
AND, NOT, OR gates
41
How many inputs and outputs are taken and given by each type of logic gate
NOT - single input, single output AND - 2 inputs, 1 output OR - 2 inputs, 1 output
42
What is outputted through a NOT gate
the opposite value - if 1 is inputted, 0 is outputted and vice versa
43
What is outputted through an AND gate
if both inputs are 1, the output is 1 else the output is 0
44
What is a truth table
a table that shows all possible inputs and their respective outputs
45
What is outputted through an OR gate
if one or more inputs are 1, then the output is 1 else the output is 0
46
What are the expressions and notations for each type of logic gate - What are the alternative notations for each logic gate
NOT | NOT A | ¬A AND | A AND B | A^B OR | A OR B | A V B - NOT ! - OR || AND &&
47
What is the NOT gate symbol
a triangle pointed to the right followed by a small circle
48
Which side of the gate is the input shown
left side
49
What is the AND gate symbol
D but stretched
50
What is the OR gate symbol
similar to an arrowhead - point on the right and 2 points on the left
51
How can multiple logic gates combined be written as a logical statement
brackets and NOT, OR and AND e.g. NOT (A & B)
52
What is a two level logic circuit
a logic circuit that requires the inputs to pass through a maximum of 2 logic gates to reach the output
53
How many rows are required for a truth table
2^n, where n is the amount of different inputs
54
In what order are Boolean operations carried out
brackets, NOT, AND, OR
55
What is the function to generate a random number (OCR Exam Reference Language)
random (x, y)
56
How could a game of heads or tails be simulated with code
random number generator between 0 and 1, if one then heads, if 0 then tails
57
How does the response of a random number generator depend on the bounds
if the bounds are integers, then the result will be an integer if the bounds are real numbers then the result will be a real number
58
How do random number generators useful for arrays
a random number can be generated and the element in that position of the array
59
What is an array
a data structure that can store a collection of data values under one name
60
What are 4 types of data structure
Records Arrays Files Databases
61
What is each piece of data in an array called - How can they be accessed
an element - using its position / index in the array
62
What are one-dimensional arrays the same as
lists
63
What are the lines of code required to create a one-dimensional array of 5 employees
array employees [5] employees [0] = "abc" employees [1] = "def" employees [2] = "ghi" employees [3] = "jkl" employees [4] = "mno"
64
What is the line of code required to retrieve the name of the first employee in a list of employees in a one-dimensional array
print (employees[0])
65
How can you change an element in a one dimensional array
reassigning the array position to a different data value arrayname [position] = "newvalue"
66
What are two dimensional arrays
a list of lists - a one-dimensional array where each element is also a one dimensional array
67
How is the position in a one-dimensional array written
[a, b] or [a][b] where a is the column and b is the position in the row
68
How can two-dimensional arrays be visualised
tables or grids
69
What are the three most common types of text files
.txt .csv .dat
70
What is the command for opening a text file and assigning a variable - What is the command for closing the file
file = open("file.txt") - file.close()
71
What is the command for creating a new file
newfile("myFile.txt")
72
What is the command for writing text to a file - where is this written
file.writeLine() - at the end
73
What is the command for reading lines of text from a file - where does it start - what happens at the end
file.readLine() - at the first line - keeps its place in the file - like a cursor
74
What does the endOfFile() command do - How can it be used in code - What is the code for this
signifies the end of the file - to signify when a program should stop reading the file - while NOT file.endOfFile()
75
What is a record - what makes them useful over arrays
a type of data structure - a row of data - they can store values with different data types
76
What is each item in a record called - what is given to each item when it is created
a field - a name and a data type
77
What is a con of records
they are fixed in length
78
What is the command for creating a record structure with the fields: record name recipes - recipe number - recipe name - tested - What is the code for inputting: - number 1 - chocolate cake - tested
record recipes int recipeNumber string recipeName bool tested endrecord recipe1 = recipes (1, "Chocolate Cake", True, 3)
79
How can records with the same record structures be collected
in an array
80
What does SQL stand for - what is it used for
Structured Query Language - used to search tables, usually in a database, for specific data
81
What is the SELECT command followed by (SQL)
SELECT fieldname FROM nameOfTable/Tables
82
What is written as a wildcard to SELECT all the fields (SQL)
SELECT *
83
What is WHERE used for (SQL) - Where is the WHERE statement used
filtering the results - specify conditions that a record must satisfy before it is returned - after the database name
84
What are procedures
sets of instructions stored under one name
85
What is the difference between procedures and functions
functions always return a value
86
What are the benefits of using programs and functions (2)
- cut down on code needing to be written - give the program more structure and readability
87
What are parameters - What can be specified for each parameter
special variables used to pass values into a sub program - name, data type, default value
88
What are arguments
actual values that the parameters take when the sub-program is called
89
How are procedures called
by typing their name and giving an argument if necessary
90
Do functions and procedures have to take parameters
Procedures - no Functions - yes
91
What should be done to a function once it is called - what will happen if it isn't done
assigned to a variable or used in a statement - the value returned will not be stored and will be lost
92
How are procedures begun and ended
procedure abc() or procedure abc (parameter) - endprocedure
93
How is a function introduced and ended
function xyz endfunction
94
What does the scope of a variable show - what are the two scopes of a variable
which parts of the program the variable can be used in - local and global
95
What are local variables
variables that can only be used within the structure they are declared in
96
What are global variables
variables that can be used any time after their declaration
97
What type of variable are ones that are declared inside a sub-programs
local variables
98
What are 3 benefits of using local variables
- can't affect anything outside the sub-program - not affected by anything outside the sub-program - can use the same variable name as a local variable elsewhere in the program
99
How are variables in the main body of a program made into global variables
with the 'global' keyword
100