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
Q

What is the alternate name for SWITCH statements
- What do these do

A

CASE SELECT
- check if a variable has specific values

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

What is written at the end of an IF and SWITCH statement

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

When are SWITCH statements used

A

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

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

What is written to introduce an IF or SWITCH statement

A
  • if … then
  • variable = …
    switch variable:
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What are the benefits and drawbacks of using Switch statements over IF statements

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What do FOR loops do

A

repeat the code inside them a fixed number of times

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

What three values do the number of times a code repeats depend on in a FOR loop

A

initial value, end value and step count

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

If no step count is provided for a for loop, what will it automatically be

A

1 step

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

With what code can the number of times the loop repeats can also be set as the program runs

A

for k = 1 to x

(x is a variable)

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

between which two words is the FOR loop repeated

A

for and next

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

What is a FOR loop concluded with

A

next k

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

What are the 4 differences between DO UNTIL and WHILE loops

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

When does a DO WHILE loop keep going

A

while the condition is true and always runs the code inside at least once

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

What are logic gates
- What are the three steps of what they do

A

special circuits built into computer chips

  • receive binary data
  • apply a Boolean operation
  • output a binary result
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

What is written to show logic gates and circuits

A

logic diagrams

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

What are the three types of logic gate

A

AND, NOT, OR gates

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

How many inputs and outputs are taken and given by each type of logic gate

A

NOT - single input, single output
AND - 2 inputs, 1 output
OR - 2 inputs, 1 output

42
Q

What is outputted through a NOT gate

A

the opposite value - if 1 is inputted, 0 is outputted and vice versa

43
Q

What is outputted through an AND gate

A

if both inputs are 1, the output is 1
else the output is 0

44
Q

What is a truth table

A

a table that shows all possible inputs and their respective outputs

45
Q

What is outputted through an OR gate

A

if one or more inputs are 1, then the output is 1
else the output is 0

46
Q

What are the expressions and notations for each type of logic gate
- What are the alternative notations for each logic gate

A

NOT | NOT A | ¬A
AND | A AND B | A^B
OR | A OR B | A V B

  • NOT !
  • OR ||
    AND &&
47
Q

What is the NOT gate symbol

A

a triangle pointed to the right followed by a small circle

48
Q

Which side of the gate is the input shown

A

left side

49
Q

What is the AND gate symbol

A

D but stretched

50
Q

What is the OR gate symbol

A

similar to an arrowhead - point on the right and 2 points on the left

51
Q

How can multiple logic gates combined be written as a logical statement

A

brackets and NOT, OR and AND
e.g. NOT (A & B)

52
Q

What is a two level logic circuit

A

a logic circuit that requires the inputs to pass through a maximum of 2 logic gates to reach the output

53
Q

How many rows are required for a truth table

A

2^n, where n is the amount of different inputs

54
Q

In what order are Boolean operations carried out

A

brackets, NOT, AND, OR

55
Q

What is the function to generate a random number (OCR Exam Reference Language)

A

random (x, y)

56
Q

How could a game of heads or tails be simulated with code

A

random number generator between 0 and 1, if one then heads, if 0 then tails

57
Q

How does the response of a random number generator depend on the bounds

A

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
Q

How do random number generators useful for arrays

A

a random number can be generated and the element in that position of the array

59
Q

What is an array

A

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

60
Q

What are 4 types of data structure

A

Records
Arrays
Files
Databases

61
Q

What is each piece of data in an array called
- How can they be accessed

A

an element
- using its position / index in the array

62
Q

What are one-dimensional arrays the same as

A

lists

63
Q

What are the lines of code required to create a one-dimensional array of 5 employees

A

array employees [5]
employees [0] = “abc”
employees [1] = “def”
employees [2] = “ghi”
employees [3] = “jkl”
employees [4] = “mno”

64
Q

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

A

print (employees[0])

65
Q

How can you change an element in a one dimensional array

A

reassigning the array position to a different data value
arrayname [position] = “newvalue”

66
Q

What are two dimensional arrays

A

a list of lists - a one-dimensional array where each element is also a one dimensional array

67
Q

How is the position in a one-dimensional array written

A

[a, b] or [a][b] where a is the column and b is the position in the row

68
Q

How can two-dimensional arrays be visualised

A

tables or grids

69
Q

What are the three most common types of text files

A

.txt .csv .dat

70
Q

What is the command for opening a text file and assigning a variable
- What is the command for closing the file

A

file = open(“file.txt”)
- file.close()

71
Q

What is the command for creating a new file

A

newfile(“myFile.txt”)

72
Q

What is the command for writing text to a file
- where is this written

A

file.writeLine()
- at the end

73
Q

What is the command for reading lines of text from a file
- where does it start
- what happens at the end

A

file.readLine()
- at the first line
- keeps its place in the file - like a cursor

74
Q

What does the endOfFile() command do
- How can it be used in code
- What is the code for this

A

signifies the end of the file
- to signify when a program should stop reading the file
- while NOT file.endOfFile()

75
Q

What is a record
- what makes them useful over arrays

A

a type of data structure - a row of data
- they can store values with different data types

76
Q

What is each item in a record called
- what is given to each item when it is created

A

a field
- a name and a data type

77
Q

What is a con of records

A

they are fixed in length

78
Q

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
A

record recipes
int recipeNumber
string recipeName
bool tested
endrecord

recipe1 = recipes (1, “Chocolate Cake”, True, 3)

79
Q

How can records with the same record structures be collected

A

in an array

80
Q

What does SQL stand for
- what is it used for

A

Structured Query Language
- used to search tables, usually in a database, for specific data

81
Q

What is the SELECT command followed by (SQL)

A

SELECT fieldname FROM nameOfTable/Tables

82
Q

What is written as a wildcard to SELECT all the fields (SQL)

A

SELECT *

83
Q

What is WHERE used for (SQL)
- Where is the WHERE statement used

A

filtering the results - specify conditions that a record must satisfy before it is returned
- after the database name

84
Q

What are procedures

A

sets of instructions stored under one name

85
Q

What is the difference between procedures and functions

A

functions always return a value

86
Q

What are the benefits of using programs and functions (2)

A
  • cut down on code needing to be written
  • give the program more structure and readability
87
Q

What are parameters
- What can be specified for each parameter

A

special variables used to pass values into a sub program
- name, data type, default value

88
Q

What are arguments

A

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

89
Q

How are procedures called

A

by typing their name and giving an argument if necessary

90
Q

Do functions and procedures have to take parameters

A

Procedures - no
Functions - yes

91
Q

What should be done to a function once it is called
- what will happen if it isn’t done

A

assigned to a variable or used in a statement
- the value returned will not be stored and will be lost

92
Q

How are procedures begun and ended

A

procedure abc() or procedure abc (parameter)

  • endprocedure
93
Q

How is a function introduced and ended

A

function xyz

endfunction

94
Q

What does the scope of a variable show
- what are the two scopes of a variable

A

which parts of the program the variable can be used in
- local and global

95
Q

What are local variables

A

variables that can only be used within the structure they are declared in

96
Q

What are global variables

A

variables that can be used any time after their declaration

97
Q

What type of variable are ones that are declared inside a sub-programs

A

local variables

98
Q

What are 3 benefits of using local variables

A
  • 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
Q

How are variables in the main body of a program made into global variables

A

with the ‘global’ keyword

100
Q
A