Unit 2 - J276 Flashcards

1
Q

Computational thinking is all about the ______ taken to find the best ________ to a complex _________.

A

stages, solution, problem

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

Abstraction - Picking out the _________ bits of information from the ________ whilst _______ the specific ______ that don’t matter

A

important, problem, ignoring, details

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

Decomposition - _________ a complex ________ into smaller ________ and ________ each one __________.

A

Splitting/Breaking, problem, problems, solving, individually

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

Algorithmic thinking - using a series of ______ steps to find ________ to a ________. - Algorithms can be ______ and ______ to solve ______ problems in the _______.

A

logical, solutions, problem, reused, adapted, similar, future

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

The 3 types of Computational thinking are

  • __________
  • D_________
  • ___________ thinking
A

Abstraction
Decomposition
Algorithmic Thinking

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

Searches allow a set of ____ to be _______ in order for a specific ____ to be ______.

A

data, examined, item, found

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

The 2 types of searching ________ are

  • ________ search
  • ________ search
A

algorithms

Binary Search
Linear Search

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

Binary search looks for items in an ______ list.

1) Set _______ to the ______ position in the list
2) If the ______ value matches, the search ___
3) Otherwise, if the desired _____ is less than the _______, then the _____-____ of the list is ______ and the search keeps to the _____-___ of the list
4) Or, if the desired _____ is more than the _______, then the _____-____ of the list is ______ and the search keeps to the _____-___ of the list
5) Steps _ to _ are _______ until a ______ is found or there are no more items to be ______.

A

ordered,

counter, midpoint

desired, ends

value, midpoint, upper-half, ignored, lower-half

value, midpoint, lower-half, ignored, upper-half

2-4, repeated, match, found

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

A binary search is much more _______ algorithm than a _______ search - In an ordered list of every number from 0-100, a linear search would take __ steps to find the number 99, whilst a binary search will find it in just 7 steps

Binary search only works for _______ lists tho ;(

A

efficient, linear, 99 steps

ordered

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

A linear search can be used on an ________ list.

Starting at the ________ of the data set, ____ item of data is _______ until a ______ is found or there are no more ______ to find.

A

unordered

beginning, each, examined, match, items

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

A way to describe a linear search would be

1) Find out the _______ of the data ___
2) Set _______ to 0
3) ________ value held in the list at the _______ positon
4) ______ to see if the value at that ________ matches the ______ value
5) If it _______, the value is found and the search is ____.
6) If not, ________ the counter by __ and go back to step 3 until there are no more ____ to ______

A

length, set

counter

Examine, counter

Check, position, desired

matches, ended

increase, 1, items, find

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

Linear searches are ______ to make due to its ________ and they work on both _______ and ________ lists.

Although, they can be quite _______. - Suppose a list contained 100 items, and the 99th item had to be found, 99 steps would have to be taken to find that single item.

A

easy, simplicity, ordered, unordered

inefficient

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

A ______ search in psuedocode might look like this

find = 2
found = Falselength = list.length
counter = 0
while found == False and counter < length
     if list[counter] == find then
          found = True
          print ('Found at position', counter)
     else:
          counter = counter + 1
     endif
endwhile
if found == False then
     print('Item not found')
endif
A

.

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

A _______ search in psuedocode might look like this

find = 11
found = False
length = list.length
lowerBound = 0
upperBound = length
while found == False
     midpoint = int((upperBound + lowerBound))/2
     if list[midPoint] == find then
          print('Found at' , midPoint)
          found = True
     else
          if list[midPoint]> item then
               upperBound = midpoint-1
          else
               lowerBound = midpoint+1
          endif
    endif
endwhile
if found == False then
     print('Not found')
endif
A

.

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

The 3 methods of sorting are

  • B______ Sort
  • M_____ Sort
  • I________ Sort
A

Bubble Sort
Merge Sort
Insertion Sort

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

A bubble sort is the ______ of sorting algorithms. It works like this.

1) Start at the _______ of the list
2) Compare the ____ value in the list with the ____ one up. If the _____ value is bigger, _____ the positions of the ____ values
3) Move on to the ______ value in the list. Again, _______ this value with the next and swap if the value is ______.
4) Keep going until there are no more _____ to ________
5) Go back to the _____ of the list

A

simpliest

beginning

first, next, first, swap, two

second, compare, bigger

items, compare

start

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

Each run through the list, from _____ to ______ is known as a _____.

A bubble sort continues until a ____ is made where no ______ have been _______ - This is when the list is completely ______.

A

start, finish, pass

pass, values, swapped

sorted

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

The advantages of a bubble sort are

  • Easy to ________ due to its simplicity
  • Efficient if the list is in ______
  • Not much _______ is used as all the sorting is done on the ________ list
A

implement

order

memory, original list

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

The disadvantages of bubble sorts are

  • _________ for large list
  • An extra ____ occurs even if the list is in ______.
A

Inefficient

pass, order

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

A psudeocode algorithm for a bubble sort might be

counter = 0
swapped = True
swaps = 0
length = list.length
while swapped == True                   
     while counter < length-1
          if list[counter] > list[counter+1] then
                temp = list[counter]
                list[counter] = list[counter+1]
                list[counter+1] = temp
                swaps = swaps + 1
          endif
          counter = counter + 1
    endwhile
    if swaps == 0 then
         swapped = False
    else:
         swaps = 0
         counter = 0
    endif
endwhile
A

.

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

A merge sort ______ a list apart then ______ it back together in its ______ order. - It is an example of a ______ and _______ algorithm.

A

splits, merges, sorted, divide and conquer

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

A merge sort works like this.

1) Split the list in _____ to form ___-____ ( the second sublist should start with the ______ term for odd no. of items)
2) Keep ______ step 1 until each ___-_____ only contains ____ item
3) Merge pairs of ____-____ so that each ___-____ has _____ as many items. Each time you merge ____-____, ____ the items in the correct ______
4) ______ step 3 until you have _____ all ___-____ together

A

half, sub-lists, middle

repeating, sub-list, one

sub-lists, sub-list, twice, sub-lists, sort, order

Repeat, merged, sub-lists

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

The advantages of merge sorting

  • More _______ and _______ than ______ and insertion for ______ lists
  • Very consistent _______ ____ regardless of how the items in a list are ______
A

efficient, quicker, bubble, large

running time, ordered

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

The disadvantages of merge sorting

  • Slower than other algorithms for _____ lists
  • Still performs the _____ and _____ process even if the list is already _____.
  • Uses more _______ than other algorithms as it creates ________ lists
A

short

split/divide, merge/conquer, sorted

memory, separate additional

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
An Insertion Sort just takes each item __ ____ and put them in the _____ place using the _____ item in the list as a starting point.
in turn, correct, first
26
An Insertion Sort works like this 1) Look at the ______ item in a list 2) Compare it to ___ items ______ it and insert the item in the ______ place 3) _______ step 2 until the ____ number in the list has been inserted into the _______ place
second all, before, correct Repeat, last, correct
27
The advantages of an Insertion Sort are - Can be easily ____ - Efficient for _____ lists - Doesn't use much _______ as all sorting is done on the _______ list - Quick to ___ items to an _______ list - Quick at ________ if the list is already _______.
coded small memory, original add, ordered checking, ordered
28
An algorithm is a ______, ____ by ____ process for _______ a problem.
logical, step by step, solving
29
Algorithms are normally written as one of the following - _________ - _____ diagram Check BBC for more info
Pseudocode | Flow diagram
30
Psudeocode is a method of writing up a set of _______ in plain ______ that also closely resembles _______ languages. It has its own _____, some of which is ______ to _________ languages. Psuedocode itself cannot be ___ by a computer. - They need to be ______ into an actual ______ language
instructions, English, programming syntax, similar, programming run, converted, programming language
31
Here is an example of psuedocode ``` while answer != 'computer science' answer = input ('What is your favourite subject? ') if answer == 'computer science' then print('Good choice!') else print('Really? ') endif endwhile ```
yep
32
Advantages of psuedocode - Can be quickly and easily ______ to _______ language due to them being very ______ - Fairly easy to ________ - Doesn't matter if there are errors in the _____ - - _______ to the design can be made quite _____.
converted, programming, similar understand syntax Changes, easily
33
The disadvantages of pseudocode are - Can be hard to see how the program ____ if there are multiple _____ - _____ consuming to produce
flows, paths Time
34
A flow diagram is a diagram that shows an _______ of a _______. They use standardised ______ to represent the different types of ________. These symbols are used to ________ the flowchart and show the ____-__-____ solution to a ______. Check Bitesize or CGP for the symbols
overview, program symbols, instruction illustrate, step-by-step, problem
35
Advantages of flow diagrams - Easy to see how a program _____ even with multiple _____ - Flow diagrams are an _________ standard - can be understood ________.
flows, paths international, worldwide
36
Disadvantages of flow diagrams - If the program is large, diagrams can become _____ in size and very _____ to follow - Changes are hard to ________ as a lot of the diagram will probably have to be ______.
large, hard incorporate, redrawn
37
The three basic programming constructs are - ________ - the _____ in which instructors occur and are ________ - ________ - determines which ____ a program takes when it is _______ - ________ - the _______ execution of a _______ of code when a program is ________
Sequence, order, executed Selection, path, running Iteration, repeated, section, running
38
The two types of iteration are - _____-________ iteration - ________ - _______ iteration
Count-controlled Condition-controlled
39
Sequence is the _____ in which lines of ____ are executed. In programming, lines of ____ are executed ___ after ______. Sequence is important as running instructions in the _______ order will lead to _____ in the program, causing it to function _______ as well.
order, code, code, one after another incorrect, errors, incorrectly
40
In this pseudocode program designed to find the average of two whole numbers, the instructions are in the wrong sequence: total = 0 average = number1/number2 number1 = int(input("Enter the first number: “)) number2 = int(input("Enter the second number: ")) print("The average is ", average) Running this program would result in an error, because it tries to calculate the average before it knows the values of the numbers.
yh
41
To correct the previous psuedocode, the _______ average should be ______ after the number1 and _______ have been stated. total = 0 number1 = int(input("Enter the first number: “)) number2 = int(input("Enter the second number: ")) average = number1/number2 print("The average is ", average)
yh man
42
Selection is the process of making a ______. The result of the _______ decides which ____ the program will take next.
decision, decision, path
43
For example, a program could tell a user whether they are old enough to learn how to drive a car. If the user's age meets the required driving age, the program would follow one _____ and execute one ___ of ________. Otherwise, it would follow a ________ path and execute a _______ set of _________.
path, set of instructions, different, different, instructions
44
Selection works by testing a _______ - The test gives a _______ result which could either be ____ or _____. If the result is ____, the program follows one ____, otherwise it follows _______.
condition, boolean, TRUE or FALSE TRUE, path, another
45
Selection is implemented using __ ____ ____ statements.
if then else
46
age = int(input("How old are you? ") if age > 16 then print("You are old enough to drive a car!") else print("Come back when you are older!") endif In the above pseudocode program, the path the program takes depends on the _______. A ______, in this case age, is used to ____ the condition. If the value age is greater than 16, the result of the tested condition is ____ and the program follows the ___ path, which follows the statement ____. This path informs the user that they are old enough to drive. If the value of age is less than 16, the result is _____ and the program follows the ______ path, which follows the statement ___. This path informs the user that they are not yet old enough to drive. The statement _____ ends the selection.
condition, variable, test TRUE, first, then FALSE, second, else endif
47
Iteration is the _______ execution of a _______ of ______ within a computer program. Iteration is also often referred to as ______, since the program "loops" back to _______ sections of _____. Sections of code that are iterated are called ______.
repetitive, section of code looping, earlier, code, loops
48
Iteration enables programmers to greatly _______ a _______. - _____ lines of code don't need to be _______ many times, the section can only be written _____, and the program can _______ it _____ times until it is no longer ______.
simplify, program, similar/same, rewritten, once, execute, multiple, needed
49
Count-controlled iteration _______ executes a section of ____ for a fixed ______ of _________ times. It uses statements ____ and _____ to determine what section of _____ is repeated and how many ____.
repeatedly, code, number, predetermined times
50
For example This program would also print out a message six times: for count = 1 to 6 print(“Coding is cool”) next count The first line of the program determines how many _____ the code is to be ______. It uses a ______, in this case count, known as the _______ variable, to keep track of how many _____ the code has been _______ so far. The variable is given a ______ value (in this case one) and an ____ value (in this case six). Every time the code is iterated, the value of count _______ by one. At the end of the iteration, the value of count is _____ to see if it matches the ___ value. If the result is FALSE, the code _____ ____ to the _____ of the iteration and runs again. If it is TRUE, the iteration ____ and the program continues with the next line of code.
times, iterated/executed, variable, condition variable, times, executed, start, end, increased, checked, end, loops back, start, ends
51
By using iteration, a program is simplified, less _____ prone and more ______. This is because - There are fewer ____ of ____, meaning fewer ________ for typing _____ to creep in - to increase or decrease the number of _______, all the programmer has to do is ______ the loop's ___ value
error, flexible lines, code, opportunities, errors iterations, change, end
52
While loops test the ________ at the ________ of the loop. if the condition is met, the ____ within the loop is ______ before the program loops ____ to ____ the condition again.
condition, beginning, code, executed, back, test
53
This program would print out a message six times: ``` count = 0 while count < 6 print(“Coding is cool”) count = count + 1 endwhile ``` The while statement defines the ____ of the loop. The ______ statement declares the ___ of the loop. A ______, in this case count, is used for the _______. The while statement also ____ the condition, in this case to see if the value of count is less than ___. If the result is TRUE, the code within the loop is ______, then the program loops ____ to the condition, which is _____ again. The iteration continues until the condition test result is _____, at which point the loop ____ and the program executes the next line of code in sequence after the loop.
start, endwhile, end, variable, condition, tests, 6, executed, back, tested FALSE, ends
54
Repeat condition-controlled loops works in the same way as while loops, BUT, the _______ is tested at the ____ of the loop (rather than the start like while loops)
condition, end
55
Repeat condition -controlled loop example ``` count = 0 repeat print(“Coding is cool”) count = count + 1 until count = 10 ``` The repeat statement defines the ____ of the loop. The ____ statement tests the condition. Because the condition is tested at the ___, the code within the loop is always executed at least ____, even if the result of the test is ______.
start, until, end, once, FALSE
56
Condition-controlled loops can be written to continue forever. This is known as ______ loop. Infinite loops can be created using either _____ or ______ loops
infinite while, repeat
57
his program would run infinitely: ``` count = 10 repeat print(“Coding is cool”) count = count + 1 until count = 10 ``` At the end of the loop, the value of the variable count will be 11. Because with each iteration the value of count increases by ___, count will never have the value ___, so the loop will run _______.
one, 10, infinitely
58
Nesting occurs when one programming ______ is included within ______. It ______ the amount of _____ needed, whilst making it simple for a programmer to ______ and _____ the program.
construct, another reduces, code, debug, modify
59
Nested selection When using selection, the number of possible ____ at a _______ point can be _______ by including one selection within ______.
paths, decision, increased, another
60
This program uses nested selection: age = int(input("How old are you? ") if age > 16 then print("You are old enough to drive a car and ride a moped!") else if age == 16 then print("You are old enough to ride a moped!") else print("Come back when you are older!") endif Endif Here, there are two ______ that may be tested, resulting in _____ possible paths to follow. The _____ condition is only tested if the result of the first test is ______. Nested selection can be built up over and over to include ____ possibilities and _____ for a program to follow. It allows for ______ decisions to be made.
conditions, three, second, FALSE many, paths, complex decisions
61
This program uses nested selection: age = int(input("How old are you? ") if age > 16 then print("You are old enough to drive a car and ride a moped!") else if age == 16 then print("You are old enough to ride a moped!") else print("Come back when you are older!") endif Endif Here, there are two ______ that may be tested, resulting in _____ possible paths to follow. The _____ condition is only tested if the result of the first test is ______. Nested selection can be built up over and over to include ____ possibilities and _____ for a program to follow. It allows for ______ decisions to be made.
conditions, three, second, FALSE many, paths, complex decisions
62
Iteration can also be nested. This program uses two count-controlled for next 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 print(y, " * ", x, " = ", result) next y next x ``` For every iteration of x, y is iterated ten times.
.
63
This program uses condition-controlled while endwhile loops, one within another, to print out the times table for all numbers from one to ten: ``` x = 1 y = 1 while x < 11: while y < 11: result = y * x print(y, " * ", x, " = ", result) y = y + 1 y = 1 x = x + 1 ``` For every iteration of x, y is iterated ten times.
.
64
A variable is a ______ ______ _______ that holds a value. The value held in the variable can _______ as the program is running
named memory address, change
65
An identifier is a _____ given to a ____ of a program, such as a _______, constant, function etc.
name, part, variable
66
Variables make it easy for a programmer to use _______ locations. The computer keeps _____ of which memory ______ the variable refers to. All the programmer has to do is remember the _______ the variable was given.
memory, track, location, identifier
67
Variables need to be _____ and ______ before a value is assigned to it. - This is known as ________ (ie declaring the variable)
created, identified, declaration
68
Assignment - giving a variable a _____. A variable must be assigned a _____ before it can be ____.
value, value, used
69
A constant allows a _____ to be assigned a _____. The value assigned to a constant can't be _____ when the program is running
value, name, changed
70
Constants are useful because they are _______ and _______ once, but can be ______ to over and over again throughout the program. ``` They are used for values that are unlikely to ______ for example: Pi - const PI = 3.142 ```
declared, assigned, referred change
71
The two types of variables are - G_____ variables - ______ variables
Global variables | Local variables
72
A global variable is one that can be _______ and _______ throughout the program. Usually a programmer has to ______ that the variable is a global. For example: global ID = 75
accessed, changed declare
73
Local variables are confined to a ____ or a _________. This has the advantage of the programmer being able to use the same variable _____ again and again for different ________.
loop, program, name, purposes
74
A local variable should not have the same _____ as a global variable. If this happens, the ______ of the global variable will be _______, causing the program to function _______.
name, value, changed, incorrectly
75
The 5 types of data types are - I______ - F____ - C_______ - S______ - B______
``` Integer Float Character String Boolean ```
76
Integers are ______ ________, Eg 27
whole numbers
77
Floats are _______ _______ Eg 27.5
decimal numbers
78
A character is a single _________ _________. Eg N
single alphanumerical character
79
A string consists of one or more __________ ________. Eg REVISE EDIOT
alphanumerical characters
80
Boolean could either be _____ or ______ Eg heheh not gonna say u tell meh
TRUE, FALSE
81
Different data types have ________ - ______ and ______ cannot be _____ together - numbers held in ______ cannot be subject to _______ operations
limitations Integers, floats, joined strings, mathematical
82
Casting is _______ the data ____ of a ________. str(68) returns “68” int(“54”) returns 54
changing, type, variable
83
String Manipulation It is usually possible to manipulate a string to provide ______ or to alter the ________ of a string
information, contents
84
Length The length of a string can be determined using the ___ statement. This gives the _______ as an _____. ___(wordOne) - would give the answer _____, as there are _____ characters in the word "Computer"
len, length, integer len(wordone), eight, eight
85
Character Position ``` wordOne = "Computer" wordTwo = "Science" ``` It is possible to determine which ________ features at a ________ within a string. wordOne[2] - would give the answer "__, as "__" is the _____ character in the word “Computer” (remember computers start counting at zero) wordOne[0:2] - would give "____", the first _____ characters in the string wordOne[3:3] - would give "____", the three characters starting from position _____.
character/s, position m, m, third com, three put, three
86
Character Position ``` wordOne = "Computer" wordTwo = "Science" ``` It is possible to determine which ________ features at a ________ within a string. wordOne[2] - would give the answer "__, as "__" is the _____ character in the word “Computer” (remember computers start counting at zero) wordOne[0:2] - would give "____", the first _____ characters in the string wordOne[3:3] - would give "____", the three characters starting from position _____.
character/s, position m, m, third com, three put, three
87
To concatenate strings means to ____ them to form another _____. ``` wordOne = "Computer" wordTwo = "Science" ``` For example sentence = wordOne + " " + wordTwo - would give "_____________" Alternatively, a string can be lengthened by ______ more ________. For example: wordOne = wordOne + " Science" - would result in the value of wordOne becoming "__________ ________"
join, string Computer Science adding, characters Computer Science
88
An array a set of data _____ of the same ____, stored in a _______ in a computer ________. Also known as a ____.
values, type, sequence, program list
89
An array is like a collection of boxes, each of which is called an _______. Each element has a _______ in the array, and can hold a _____. The data in an array must all be of the same ____ ____. This way, all data is stored under one ________ (name).
element, position, value, data type identifier
90
Before an array can be used, it must be ______. To declare an array it must be given at least two properties: ``` - an ________ a ____ (the number of _______ it will hold) ``` For example: array score[9] - would declare an array with ___ elements (zero to nine) Once declared, the ______ and ________ of an array cannot be ______.
declared identifier size, elements ten elements name, structure, changed
91
Values are assigned to an element in an array by referring to the element's ________. For example: score[0] = 100 - would assign the value ___ to the ____ element in the array Values in elements can be ________ at any point, simply by assigning another value to that element.
position 100, first overwritten
92
Values are retrieved from an element in the array by again referring to the element's _______. For example: print(score[7]) - would display the _____ value held in the array. In the above example, the value would be ___ - Check bitesize
position, eight, 98
93
A two-dimensional array can hold more than ___ set of ____. This type of array is like a table, with data held in ____ and ________.
one, data, rows, columns
94
A two-dimensional array is declared using ___ values- the _______ of ___ and the ________ of _______. Eg array score = [1,9] - would give an array with ___ rows and ___ columns
two, number of rows, number of columns two, ten
95
Data is _______ or retrieved by referring to an element's ___ and ______ number.
assigned, row, column
96
An operator is a _______, or _______, that determine what ______ is to be performed or considered. The 3 types of operators are; - M________ operators - L______ operators - B______ operators
character, characters, action - Mathematical operators - Logical operators - Boolean operators
97
Mathematical operators allow ________ operations to be performed on ______. Symbol in the middle Addition - _ - x=x+5 Subtraction - _ - x=x-5 Multiplication - __ - nah Division - __ - nah
mathematical, values Addition - + Subtraction _ - Multiplication - * Division - /
98
The 3 hard to remember mathematical operators Power - __ or __ Quotient - ___ Remainder - ___ or __
^ or ** DIV MOD or %
99
The DIV operator returns the _____ _______ part of the division. The MOD operator simply gives the _______ of the division.
whole number remainder
100
Logical operations allow for ________ and for ________ to be made. They are used in ________ testing. Symbol mid, check eg cgp or bitesize ``` Assignment - __ Equivalence - __ or ___ Less than - __ Less than or equal to - __ Greater than - __ Greater than or equal to - __ Does not equal - __ or __ ```
assignment, comparisons, condition testing ``` Assignment - = Equivalence - = or == Less than - < Less than or equal to - <= Greater than - > Greater than or equal to - >= Does not equal - != or <> ```
101
Boolean operators are used to _______ l______ operators to give more _______ d______. And - ____ Or - ___ Not - ___
combine logical, complex decisions AND OR NOT
102
Programs can use ____ to store ____ and sure it is not lost when the program ends, so data can be _______ again later.
files, data, accessed
103
Files have two modes of operation - _____ from - File is opened so data can be ____ from the ___ - _____ to - File is opened so that data can be ______ to the ____.
Read from, data can be read from the file Write to, data can be written to the file
104
Each item of ____ written to or from a file is called a ______.
data, record
105
A file must be open before a ______ can be ____ from or ______ to it.
record, read, written
106
OPENING AND CLOSING FILES To open a file, it must be referred to by its _______ file = openRead("scores.txt") This would ____ the file scores.txt and allow its contents to be _____. file = ________("scores.txt") This would open the file scores.txt and allow it to have data written to it. file.close() - This _____ the file
identifier open, read openWrite("scores.txt") closes
107
READING FROM A FILE Records are read ___ line at a _____ once the file is _____. The data held in this record can be read into a ______ or an ______. file = openRead("scores.txt") score = myFile.readLine() file.close() An array example is shown below. ``` file = openWrite("scores.txt") for x = 0 to 9 scores[x]=myFile.readLine() next x file.close() ```
one, time, opened variable, array
108
``` END OF FILE The __________ () statement checks to see if the last record has already been read. E.g. ``` ``` file = openRead("scores.txt") while NOT file.endOfFile() scores[x]=myFile.readLine() x = x + 1 endwhile file.close() ``` The above code would ___ each record and place it into an array scores. The operation _____ when there are no more ____ to read.
endOfFile() statement - checks to see if the last record has already been read read each record. operation ends - when no more files to read
109
WRITING TO A FILE Data is written to a file ___ ____ at a time, using the _______ statement, for example: ``` file = openWrite("scores.txt") for x = 0 to 9 file.writeLine(scores[x]) next x file.close() ``` The above code would ____ the contents of an array scores to the file scores.txt.
Written one line at a time - Statement writeLine write
110
DATABASES Data is often stored in a _______. A database is a _______ of data, or information that is stored in an _______ way to make _______ data much easier and more _______.
Database - Collection of data - organised - accessing data easier and more efficient
111
DATABASES Data in a database is stored as _______, which in turn is stored as _____.
Stored as records, files
112
An _______ is one item of data.
Attribute - One item of data (categorie)
113
_______ usually consist of one or more attributes. For example, a record holding data about a person might have these attributes: title _______ ______ email address
Records Forename Surname
114
SQL (________ _____ _______) is a ________ ______ used for _________ a _________.
SQL (Structured query language) is a programming language used for interrogating a database.
115
Retrieving data from databases using ____ Data can be retrieved using the commands ______, FROM and ______, for example: BBC
SQL Commands - SELECT, FROM, WHERE
116
* in SQL means ___ records.
* - all records | e. g. Select * means select all
117
The ____ command can be used to find matches for an incomplete word e.g. %com returns any value that contains "___"
LIKE %com returns any value that contains com BBC
118
Boolean operators ____ and ___ can also be used to ______ data in a database.
Boolean operators - AND OR
119
Subprograms Subprograms are small ______ that written within a _____, ____ program. The purpose of a subprogram is to perform a ______ ____. - This task may need to be carried out ______ times at various ____ of a program.
Subprograms - small programs within a larger, main program Purpose - to perform a specific task Carried out multiple times - various areas of a program
120
Subprograms There are two types of subprograms: - p________ - ________
2 types of subprograms - Procedures and functions
121
Benefits of using subprograms - _____ in size - so easier to ____, test and _____. Also easy for someone to ________ it. - Can be saved ________ as _______ and used again in other _______. - Saves ___ because the programmer can use code that has already been written, tested and debugged.
Benefits of subprograms Small in size - easy to write, test & debug. - Easily understandable Saved separately as modules - used again in other programs - Saves time - no need to write, test and debug another piece of code
122
Benefits of using subprograms - Can be used ______ times at various _____ in the main program. - Code only needs to be written ____, so programs are _____ in size.
Benefits of subprograms - Used multiple times at various points - Code written only once - Smaller programs
123
Procedures A procedure is a subprogram that performs a ______ _____. When the task is complete, the subprogram ___ and the main program _______ from where it left off.
Procedure - Subprogram - specific tasks Task complete - Subprogram ends - Main program continues
124
Procedures A procedure is created using the following syntax: procedure identifier (value to be passed) procedure code endprocedure
A procedure is created using the following syntax: procedure identifier (value to be passed) procedure code endprocedure
125
``` procedure clear_screen(x) for i = 1 to x: print(" ") endprocedure ``` This procedure would ____ the screen by printing x ____ lines
clear the screen - prints blank lines
126
Functions A function works in the same way as a procedure, except that it ________ data and returns a _____ back to the main program.
Function - manipulates data - returns a result
127
Example of a function A function might be written to turn Fahrenheit into Celsius: ``` function f_to_c(temperature_in_f) temperature_in_c= (temperature_in_f –32) * 5/9 return temperature_in_c endfunction ```
``` function f_to_c(temperature_in_f) temperature_in_c= (temperature_in_f –32) * 5/9 return temperature_in_c endfunction ```
128
Functions A function is run by ______ it. To call it, a programmer uses the function's _______, the ______ to be passed into the function, and a _______ for the function to return a value into, for example: celsius = f_to_c(32) This would result in the _____ of Celsius being zero.
Function - run by calling it - call by function's identifier (name), - value to be passed - variable for function to return value to value
129
Procedures perform a _______ _____. Functions _________ data and return a _____ to the main program.
Procedures perform a specific task. Functions manipulate data and return a value to the main program.
130
Built-in functions Many languages include built-in, ready-made functions: - int - coverts ______ or _____ into _______ - str - converts a ______ into a _____ - __ - finds the ____ number of a ________
Built in functions int - converts strings or floats into integers str - converts a number into a string asc - finds the ASCII number of a character
131
Defensive design The purpose of defensive design is to ensure that a program ___ correctly and continues to ___ no matter what _______ a user takes. This is done through planning for ________ (all ______) and anticipating ______ (how a user may _____ or misuse a program)
Defensive design - purpose to ensure a program runs correctly - continues to run no matter what actions user do Done via planning for contingencies (all possibilities) and anticipating misuse (how a user may exploit or misuse a program)
132
Planning for contingencies Simply, this is planning for all _______ for a computer _______. e.g. planning the program's response if it crashes. For example, it should give an error message to the user and explain what occurred if it just suddenly crashes - it should not just crash and tell no information to the user.
Planning for contingencies - Planning for all possibilities for a computer program
133
3 areas of focus for Defensive design - Protection against unexpected user _____ or _____, e.g. a user entering a letter instead of a number - Maintainability - ensuring code is _______ and ________ - Minimising/removing ____
- Protection against unexpected inputs or actions - Maintainability - ensuring code is readable and understandable - Minimising/removing bugs
134
Anticipating and protection of program is done via - Input _______ - Input _______ - A___________ - __________ - Testing
``` Input Validation Input Sanitisation Authentication Maintenance Testing ```
135
Input Validation - Checking input data is _______ and in the right _______.
Input Validation - Checking if input data is sensible and in the right format
136
Input validation Validation applies ____ to inputted data. If the data does not follow the rules/criteria, it is ______, reducing the risk that incorrect input data may ____ a program.
Validation - Applies rules to data - Data is rejected if it doesn't follow rules - Reduces risk of program crashing from incorrect inputs
137
Types of Input Validation - R_____ check - L_____ check - P_______ check - F______ check - ______ check
``` Range check Length check Presence check Format check Type check ```
138
TYPES OF INPUT VALID Range check - the input must fall within a specified ______. - Usually applied to numbers and ____, but can be applied to ________. E.g. When making a payment to someone, the amount to be entered might be set to be greater than zero and not greater than the funds available.
Range check - input within a specified range - applied to numbers, dates and maybe also characters
139
TYPES OF INPUT VALID Length check - the input must not be too ____ or to _____. For example, a surname will require at least one letter, but is unlikely to require more than 40.
Length check - Input not too long or too short - Checks if the input is of the correct length
140
TYPES OF INPUT VALID Presence check - Checks if any data has been _______. A data value must be ______. For example, entering a quantity when placing an order.
Presence check - If data has been inputted. Data values must be inputted.
141
TYPES OF INPUT VALID Format check - Checks if the data is in the correct ______. The data must be in the correct ______. e.g. DD/MM/YYYY
Format check - Checks if data is in the correct format. Data must be in the correct format.
142
Many programs use one or more of these validation checks. For example, when signing up for a user account on a website, the validation might include: presence check - a ______ must be entered length check - a password must be at least ____ characters long range check - age restrictions may require the user's date of birth to be before a certain ___ format check - the user's date of birth must be entered in the specified ______ type check - the password may need to have a mixture of _____ and lower case letters, a number and a ______ character
.presence check - a username must be entered length check - a password must be at least eight characters long range check - age restrictions may require the user's date of birth to be before a certain date format check - the user's date of birth must be entered in the specified format type check - the password may need to have a mixture of upper and lower case letters, a number and a special character
143
Validation does not ensure that the data entered is ______, just that it is possible and _______. 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.
Validation - ensure data is possible and sensible, not if it's correct.
144
Validation does not ensure that the data entered is correct, just that it is possible and sensible. To get around this, many programs include ________ checks - they _______ the entered data to the user and ask them to ______ if this data is correct. If the user confirms the data, the program then assumes it to be _______.
Verification checks - Repeat entered data to user - Asks them to confirm it's correct - If yes, program assumes it's correct
145
Validation can be very simple. This program will _____ until the user enters a correct response: response = "" while response != "y" and response != 'n' response = input("Do you want to proceed? y/n") response.lower endwhile print("Okay, let's continue...")
iterate
146
Data sanitisation - The process of ______ or protecting data so it cannot be ____ or ________.
Input sanitisation - Hiding or protecting data so it cannot be seen or disclosed
147
Ways of data sanitisation Masking - Hides _____ data by ________ it with something else. Example - When typing passwords, the characters are replaced by ___ or asterisks, one for each ________ entered. - This prevents the actual password from being revealed to those looking at the _______.
Masking - Hides visible data by replacing it with something else dots, character, screen
148
Input sanitisation - The process of checking data ______ and removing anything that may be _________ and can cause ____ to a program. E.g. Removing malicious SQL commands that is entered into a website, to prevent unauthorised access.
Input sanitisation - Checking inputted data - removes dangerous data. - that could harm a program-------------------------------------------------------------------------------
149
Authentication is the _________ of the ________ of a user. ________ and _________ are commonly used in networks as forms of authentication.
Authentication - Verification of the identity of a user Usernames and passwords - common authentication for networks
150
3 main groups of authentication - Something you ___ - username, bank account no. or anything that identifies the user _________ - Something you ____ - password, ___, secret answer to a question - Something you have - swipe card, ______, any other _______ identifying device
You have - identifies user uniquely (e.g. username) You know - password, pin etc You have - Biometrics - physical identifying devices
151
Maintainability - Process of ensuing a program is easy to u________, _______ and _______.
Maintainability - Ensuring programs are easy to understand, modify and update
152
Why is maintainability important Programmer may need to _____ back to a program to improve it, _____ errors or add new _________. Maintainability ensures it is easy to _______, ______ and _______, so programmers can very ____ understand and perform these actions with minimal _______.
return back, improve performance, debug errors, add new features Maintainability - Easy to understand, modify and update - Programmers can easily understand, perform modifications and updating with minimal struggle and at ease
153
Maintainability methods - C______ - Sensible ________ names - ________
comments sensible variable names indentation
154
Comments - Lines of ___ in programs that provide _______ about what different ____ of a program ___. Are not _______ when program is run - program _____ them and moves to next ___ of code. In python - comments are written using the ____ symbol
Comments - Text that provides info on what different sections of a program does Not executed when program runs - ignored by program - moves to next line of code - Hash symbol - Python
155
Sensible variable names The variable name should reflect the ______ of the variable and the ____ it is intended to _____ e.g. height instead of h This makes the program's and variables easier to _________ and identify its ________
Variable name - reflect purpose of variable - and the data it is intended to hold/store Makes variables and programs easier to understand and identify it's purpose
156
Indentation Code within ________ or _______ should be indented. This allows the programmer to easily see which ____ falls within the _______ or ________, and where it ____.
Selections and indentations - should be intended Easily see which code are selections or indentations - and where it ends
157
Programming errors The two types are - ________ errors - _______ errors
Syntax Errors | Logical Errors
158
Syntax error - Occurs when ____ written does not follow the ____ of the programming _______. The program will not ____ with syntax errors. Good ____ will usually point out syntax errors to the programmer.
Syntax error - When code doesn't follow the rules of the programming language Program no run with syntax errors IDEs point out these errors to programmers (good ones)
159
Syntax errors examples Misspelling a _______, eg writing pint instead of print Using a variable before it has been ________ Missing _______, eg opening a bracket but not closing it
Syntax error examples Misspelling statements Using variables before its declared Missing brackets
160
Logic errors - an error in the way a program _____. The program simply does not do what it is _______ to ___.
An error in the way a program works. The program simply does not do what it is expected to do.
161
Causes of logic errors incorrectly using _____ operators, eg expecting a program to stop when the value of a variable reaches 5, but using <5 instead of <=5 incorrectly using ______ operators unintentionally creating a situation where an ______ loop may occur incorrectly using ________ in calculations unintentionally using the same variable ____ at different points in the program for different _______ referring to an _______ in an array that falls _______ of the scope of the array
Incorrect use of logical and Boolean operators Unintentional infinite loops Incorrect use of brackets in calculations Accidentally using same variable names at different points for different purposes Refer to an elements outside of a scope of the array
162
Syntax and logical error difference Syntax error stops a program _______, logical errors ____. With logical, the program will ___, but not perform or function as _______.
Syntax no run, Logical yes run Logical run - but program no perform or function as intended/expected
163
Testing When first written, programs may contain ____. Syntax errors can easily be _______, but logical errors are harder to ___ and _____. Testing is used to _____ a program for errors - it is used to remove ____ and ensure the program ________ as intended.
Code first written - have bugs Syntax easy to fix, Logical harder to find and solve Testing - Checks program for errors - Purpose to remove bugs, and ensure program functions as intended
164
Types of testing - I_______ testing - F____/________ testing
Iterative testing | Final/terminal testing
165
Iterative testing is carried out while a program is being ________. _______ (sections of code) are written and then _____. The programmer will amend or ___ the code if there are _____, and ____ it again. The process _______ (iterates) until the _______ works as intended.
Iterative testing - testing a program whilst it's developed ``` Modules (sections of code) written and then tested. Code fixed if errors present, and module is tested again ``` Process is repeated until the module works as intended
166
Final/terminal testing is carried out when the program is _______ and is tested as a ____ to ensure that it ________ as it should.
Final/terminal testing - Done when program is completed - tested as a whole - purpose to ensure that it functions as it should
167
Test data is data that is used to ____ whether or not a program is ________ correctly. Test data should cover a range of possible and impossible ____, each designed to prove how a program ____ or highlight any types of _____.
Test data - date used to test whether or not a program is functioning correctly Test data - should have range of possible and impossible inputs - prove how a program works or highlight flaws
168
Types of test data - _____ data - E________ data - _______/_________ data
Types of test data Valid date Extreme data Invalid/erroneous data
169
Valid data - sensible, _______ data that the program should ______ and be able to _______.
Valid data - sensible, possible data that the program should accept and be able to process
170
Extreme data - ____ data that falls at the _______ of any possible _____
Extreme data - valid data that falls at the boundary of any possible ranges
171
invalid (________) data - data that the program cannot ______ and should not ______
invalid (erroneous) data - data that the program cannot process and should not accept
172
Testing requires a ___ plan Test plan - This is a ___ of all the ___ that the programmer intends to use to ensure the program _____ as intended. It should include several examples of ____, extreme and ______ data.
Test plan - List of all tests needed to ensure a program functions as intended Should include multiple valid, invalid and extreme data as part of test.
173
Testing tables Test are laid out in a ________ table, which indicates: - The test ______ - A ________ of what the test intends to _____ - The test ____ being used - The ____ of test (valid, _______ or invalid) - Expected _______ - _____ outcome
Tests - laid out in testing tables --> includes.... ``` Test number Description of what test intend to check Test data being used Type of test (valid, extreme or invalid) Expected Outcome Actual Outcome BBC ```
174
Tests Ideally, a programmer should run as many ____ as is sensible. Many ____ programs, especially games, contain bugs simply because it may not be ______ to test every possible _____ or action.
Run many tests as is sensible. Large programs - contain bugs - coz not possible to test every possible input or action
175
Trace tables Trace tables is a way to test ____ programs. Trace tables are used when _______ a program to record ______ in ______ values as code _______.
Trace tables - test short programs Used when testing program to record changes in variable values as code executes.
176
Trace tables Check BBC Contain all _______ a program has Trace tables records _____ in ______ of the variable.
Trace tables Has all variables Records changes to variable values
177
Benefit of Trace tables Check BBC Helps a programmer determine the _____ in a program where a _____ _____ has occurred.
Helps the programmer determine the point in a program where a logical error has occurred, Finds where logical error has occurred in the program
178
Logic errors - an error in the way a program _____. The program simply does not do what it is _______ to ___.
An error in the way a program works. The program simply does not do what it is expected to do.
179
Benefit of Trace tables continued Extremely useful because they enable a programmer to ______ what the value of each ______ should be against what a program actually produces. Where the two _____ is the point in the program where a _____ error has occurred.
Programmers can compare expected value vs actual value Where the two values differ is the point where logical error has occured.
180
Why data is usually in Binary form A computer is a collection of _______ and circuits. These components have two states: __ - a ______ is flowing through the component ___ - a ______ is not flowing through the ________ These two states can easily be represented in ______. 1 = __ (_____) _ = __ (______)
Computer - collection of transistors and circuits Two states; ON - Current is flowing through the component OFF - Current is not flowing through the component
181
State is the _______ of a circuit. If a circuit has one _____ and one ______, and the input and output each have two states - ___ and ____ - this gives two combinations of state: input off, _______ ___ input on, ______ ___
State - Output of a circuit/logic gate One input and one output - each have two states (on and off) - two combinations of state Input off, Output OFF Input on, Output ON
182
Logic gates A logic gate is a series of _______ connected together to give one or more _______, each output being based on the ____ or ___________ of inputs supplied to it.
Logic gate - Series of transistors connected together to give one or more outputs, each output based on input or combination of inputs
183
The 3 types of logic gates - A___ gate - __ gate - ____ gate Each type of gate can be represented either as a _____, in _______ form, or as a _____ table.
AND gate OR gate NOT gate Gate can be represented by a diagram, algebraic form, or as a truth table
184
Truth table A table to list the _______ for all possible _____ combinations into a _____ gate.
Truth table - table to list the output for all possible input combinations into a logic gate
185
Boolean algebra A form of _____ which only works with ___ values, _____ or _____. It is a notation used to represent _____.
Boolean algebra - Algebra that only works with 2 values - TRUE or FALSE. Notation used to represent logic
186
Boolean algebra ``` Boolean algebra is a notation used to represent logic. For example: Q = A AND B Q = A OR B Q = NOT A This notation can also be represented using symbols: Q = A __ B, or as A_B Q = A __ B, or as A_B Q = _ A ```
A AND B = A/\B or A.B A OR B = A\/B or A+B NOT A = ¬ A
187
AND gates An AND gate, also called a ________, uses ___ inputs to generate one ______. The output is 1 (TRUE) only if both of the _____ are _ (______).
AND Gate - Conjunction - 2 inputs to make one output. | Output is 1 (TRUE) only of both inputs are 1 (TRUE)
188
AND gates Check BBC for diagram This AND gate is represented in Boolean algebra as one of: A AND B A __ B A_B
This AND gate is represented in Boolean algebra as one of: A AND B A /\ B A.B
189
``` AND gate truth table A B Q 0 0 _ 0 1 _ 1 0 _ 1 1 _ ``` A represents ____ input, B is ______ ____, and Q is the _______.
``` AND gate truth table A B Q 0 0 0 0 1 0 1 0 0 1 1 1 A - First input B - Second input Q - Output ```
190
OR gates An OR gate, also called a _______, uses ___ inputs to generate one output. The output is 1 (TRUE) only if either or both of the inputs are 1 (TRUE).
OR OR gate - disjunction - 2 inputs to make one output, Output is 1 TRUE only if either or both inputs are 1 TRUE
191
``` OR gate truth table A B Q 0 0 _ 0 1 _ 1 0 _ 1 1 _ ``` A represents ____ input, B is ______ ____, and Q is the _______.
``` Or gate truth table A B Q 0 0 0 0 1 1 1 0 1 1 1 1 A - First input B - Second input Q - Output ```
192
OR gates Check BBC for diagram This OR gate is represented in Boolean algebra as one of: A OR B A __ B A_B
This OR gate is represented in Boolean algebra as one of: A OR B A \/ B A+B
193
NOT gates A NOT gate, also called the ______, uses ___ input to generate one output. A NOT gate _____ the input - the output is 1 (TRUE) if the input is _ (_____), and the output is 0 (FALSE) if the input is _ (_____).
NOT gates - negation - ONE input to give one output Reverses/inverts the input (output is always opposite of input) Input - 1 Output - 0 Input - 0 Output - 1
194
NOT gate truth table A Q 0 _ 1 _
NOT gate truth table A Q 0 1 1 0
195
NOT gate Check BBC for diagram This NOT gate is represented in Boolean algebra as one of: NOT A _A _A Ā
This NOT gate is represented in Boolean algebra as one of: NOT A ¬ A ~A Ā
196
Combining gates Logic gates can be combined to form more ______ inputs and ______. These combinations are known as _____ _____ AND, ___ and NOT gates can be used in any ________ to generate the desired _____.
Logic gates - combined for more complex inputs and outputs - Logic circuits AND, OR and NOT can be used in any combination to get desired output
197
Combining two AND gates Check BBC for diagram Here, the output Q is 1 (TRUE) only if inputs __ and D are _ (____). D is only 1 (TRUE) if inputs __ and __ are 1 (TRUE).
Here, the output Q is 1 (TRUE) only if inputs C and D are 1 (TRUE). D is only 1 (TRUE) if inputs A and B are 1 (TRUE).
198
``` Truth table for two AND gates A B C D = A /\ B Q 0 0 0 0 _ 0 0 1 0 _ 0 1 0 0 _ 0 1 1 0 _ 1 0 0 0 _ 1 0 1 0 _ 1 1 0 1 _ 1 1 1 1 _ ``` Note - D is not strictly necessary in the table, but it helps in understanding Q.
``` Truth table for two AND gates A B C D = A /\ B Q 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 1 0 1 0 1 1 1 1 1 ```
199
Combining two AND gates In Boolean algebra, this circuit is represented as one of: ``` Q = (________) AND C Q = (A__B) __ C Q = (A_B)_C ```
Combining two AND gates In Boolean algebra, this circuit is represented as one of: ``` Q = (A AND B) AND C Q = (A/\B) /\ C Q = (A.B).C ```
200
Combining OR and NOT gates Check BBC for diagram Here, the output Q is 1 (TRUE) only if inputs __ and __ are both _ (_____).
Combining OR and NOT gates Here, the output Q is 1 (TRUE) only if inputs A and B are both 0 (FALSE).
201
``` Truth table for OR and NOT gates combined A B C Q 0 0 0 _ 0 1 1 _ 1 0 1 _ 1 1 1 _ ```
``` Truth table for OR and NOT gates combined A B C Q 0 0 0 1 0 1 1 0 1 0 1 0 1 1 1 0 ```
202
Combining OR and NOT gates In Boolean algebra, this circuit is represented as one of: ``` Q = NOT (_____) Q = ¬ (A __ B) Q = NOT (A _ B) ``` Note - This is sometimes called the ___ gate, ie a NOT OR gate. In the same way, a NOT AND gate can be referred to as the ____ gate.
Combining OR and NOT gates In Boolean algebra, this circuit is represented as one of: ``` Q = NOT (A OR B) Q = ¬ (A \/ B) Q = NOT (A + B) ``` Note - This is sometimes called the NOR gate, ie a NOT OR gate. In the same way, a NOT AND gate can be referred to as the NAND gate.
203
``` Mathematical operators Addition --> + Subtraction --> - Multiplication --> _ Division --> _ _______ division --> ____ R_______ --> ___ E________ --> _ ```
``` Addition --> + Subtraction --> - Multiplication --> * Division --> / Integer division --> DIV Remainder --> MOD Exponentiation --> ^ ```
204
Mathematical operators allow _______ to be performed on va_____.
Mathematical operators allow arithmetic to be performed on values
205
Addition Addition uses the ‘_’ symbol: 6 + 6 = __ x + y x = x + 2 x = x + y
Addition uses the ‘+’ symbol 6+6=12
206
Subtraction Subtraction uses the ‘_’ symbol: 8 - 6 = 2 x - y x = x - 2 x = x - y
Subtraction uses the '-' symbol 8-6=2
207
Multiplication Multiplication uses the ‘_’ symbol: 5 * 5 x * y x = x * 5 x = x * y
Multiplication uses the ' * ' symbol 5*5 = 25
208
Division Division uses the ‘_’ symbol: 6 / 2 x / y x = x / 2 x = x / y
Division uses the ‘/’ symbol: 6 / 2 = 3
209
Modulus Modulus gives the _______ from a d_____ calculation: 7 MOD 3 = 1 (7 / 3 = 2 remainder 1) Many programming languages, such as Python, use the ‘__’ character to represent modulus: 6 % 2 x % y x = x % 2 x = x % y
Modulus Modulus gives the remainder from a division calculation: 7 MOD 3 = 1 (7 / 3 = 2 remainder 1) Many programming languages, such as Python, use the ‘%’ character to represent modulus
210
``` Integer division Integer division (also known as _____ division) discards the _______: ``` 7 DIV 3 = 2 (7 / 3 = 2 remainder 1 – the remainder is discarded) so it's just __ Some programming languages, such as Python, use ‘__’ to represent integer division: 6 // 3 x // y x = x // 2 x = x // y
``` Integer division Integer division (also known as floor division) discards the remainder: ``` 7 DIV 3 = 2 (7 / 3 = 2 remainder 1 – the remainder is discarded) so the answer is 2 Some programming languages, such as Python, use ‘//’ to represent integer division:
211
Exponentiation Exponentiation uses powers represented by the symbol ‘_’: 2 ^ 3 = _ x _ x _ = _ Some programming languages, such as Python, use ‘__’ to represent integer division: 2 ** 2 x ** 2 x ** y
Exponentiation Exponentiation uses powers represented by the symbol ‘^’ Some programming languages, such as Python, use ‘**’ to represent integer division
212
Use of brackets Calculations within brackets are performed f___. If there are no brackets, ________ is performed first, then division, addition and finally, ________ Where multiple brackets exist, the inside brackets are dealt with first: ((4 / 2) + (3 * 3)) + 2 = (2 + 9) + 2 = 11 + 2 = 13
Use of brackets Calculations within brackets are performed first. If there are no brackets, multiplication is performed first, then division, addition and finally, subtraction
213
High level languages - languages that are close to the _____ and ______ language of the programmer.
High level languages - languages that are close to the spoken and written language of the programmer.
214
Why use high level languages Programmers find machine code difficult to learn, program and ____ in. So they use ___ level languages to ____ code instead These languages are close to the _____ and ______ language of the programmer. For example, Python uses '____', ‘if’, 'input' and '____' statements - all words from the _____ language - to form ________.
Machine code difficult to learn, program and debug in. High level language used instead - close to spoken and written language Python "print" "if" "while" - statements - English words - form instructions
215
Why write in high level languages (Advantages) - Easier to ______ and less ______ than machine code - Allow programmer to focus on the ____, rather than how the computer actually _______.
Advantages of high level languages - Easier to understand and less complex than machine code Allow the programmer to focus on what needs to be done, rather than on how the computer actually works. For example, in many high level languages, to place a message on the screen, a programmer would use the statement 'print'. The programmer might not know how the computer actually generates the message. They just need to know how to use the 'print' statement.
216
Disadvantages of high level languages - _______ to the number of statements built into them. If the programmer wants a program to do something, but a statement does not exist to do so, the task cannot be done.
Disadvantages of high level languages - Restricted to no. of statements built into them
217
Commonly used high level languages Many types of high level language exist and are in common use today, including: ``` Python Java C++ C# Visual Basic JavaScript ```
``` Python Java C++ C# Visual Basic JavaScript ```
218
Source code - The code behind a computer _______, written in a ___- level _______ _______. Source code must be _______ into machine code before the computer can understand and _____ it.
Source code - Code behind a program, written in a high level programming language Must be translated into machine code in order to be executed and understood by computer
219
Each high level _______/instruction is _______ into many ______ ____ instructions. High level languages are known as ___ - ___ - _____ languages because of this.
Each high level instruction/statement is translated into many machine code instructions. High level languages are known as one-to-many languages
220
Low level languages - Programming languages that closely resemble the computer's ________ ___. An instruction set is a set of instructions that the _________ understands.
Low level languages - closely resemble the computer's instruction set Instruction set - set of instructions that the processor understands
221
Low level languages - More difficult to ________ than high-level languages - But, instructions execute _______.
Low level languages Difficult to understand Instructions and code executes faster
222
Examples of low level languages - ________ code - _________ language
Examples of low level languages - Machine code - Assembly language
223
Low level language - Machine code Machine code is the _______ that a _______ understands and can act upon
Low level language - Machine code Machine code is the instructions that a processor understands and can act upon.
224
Advantages of using machine code - More ______ - machine code can do stuff high level languages can't e.g. change screen refresh rate - More _______ - Uses ____ instead of sentences - so they can build their own ______ sentences or keep programs very ____ and ________
Advantages of using machine code - More control - Machine code can do more tasks e.g. change screen refresh rate - More flexibility - Words instead of sentences - Own complex sentences can be made or programs can be kept very short and simple
225
Disadvantages of using machine code - Difficult to ____ in, understand and _____ because it contains _____ or ________ numbers. So instead, when programmers need direct control, thy use another type of low level language called _______ ______.
Disadvantages of using machine code - Difficult to code in, understand and debug coz its in binary or hexadecimal For direct control, assembly language is used instead
226
Assembly language Assembly language uses _______ (short _______) instead of statements. Each mnemonic directly corresponds with a _______ code ________. - So it is a ___-__-___ language
Assembly language ``` Uses mnemonics (short abbreviations) instead of statements. Each mnemonic directly corresponds with a machine code instruction. - One-to-one language ```
227
Assembly language Programs are written as a series of ________. Mnemonics are much easier to ________ and ____ than machine code.
Assembly language Code is a series of mnemonics Mnemonics - easier to understand and debug than machine code
228
Assembly language Writing in mnemonics is ea___ - brief representations of actual _______. Quicker to write than ______ or ________ and is easier to spot ________.
Assembly language Mnemonics - easier to write - brief representations of actual commands Quicker to write than binary or hexadecimal Easier to spot mistakes
229
Many machine code and assembly instructions contain two parts: - Opc___ - The actual ________ - ______ - A _____ that the instruction ____ or ________
Many machine code and assembly instructions contain two parts: - the opcode - this is the actual instruction - the operand - this is a value that the instruction uses or manipulates
230
Both opcode and operand are represented in either ______ or _______
Opcode and operand - represented in either binary or hexadecimal
231
Why Hexadecimal is popular - Represents larger _____ with fewer ______. - Therefore it is easier to ____ and ________ by humans.
Why Hexadecimal is popular - Represents larger values with fewer characters. - Therefore it is easier to read and understand by humans.
232
Consider this simple machine code program: 901 - inputs a value 306 - stores it in memory address 06 5A1 - loads into the accumulator the value held in memory address A1 Each of these instructions has an opcode and an operand: Machine code instruction Opcode Operand 901 9 01 306 3 __ 5A1 5 __
Consider this simple machine code program: 901 - inputs a value 306 - stores it in memory address 06 5A1 - loads into the accumulator the value held in memory address A1 Each of these instructions has an opcode and an operand: Machine code instruction Opcode Operand 901 9 01 306 3 06 5A1 5 A1
233
Need for translators The ___ level language code used to make programs is known as ______ code. Source code can't be ______ by the computer, so it needs to be translated into ______ code which the computer understands.
Source code - High level language code used to make programs Source code no executed So it need to be translated into object code which the computer understands
234
Translator - A program that converts _____ code into ______ code. The three types are... - C______ - I________ - _________
Translator - A program that converts source code to object code 3 types are - Compilers - Interpreters - Assemblers
235
Compilers - Takes all of the source code as a _____ and translates it into ______ go in ___ go. Once converted, the _____ code can run ______ at any time. This process is called _______.
Compiler - Whole source code translated into object code all in one go Converted object code can run unassisted at any time Process called compilation
236
Advantages of compilers - Compiled programs run ______, since they have already been _______. - Compilers _______ code. Optimised code can run _____ and take up less ______ space.
Advantages of compilers Compiled programs run quicker - already translated Compilers optimise code - code runs quicker and takes up less memory.
237
Advantages of compilers continued - A compiled program can be supplied as a ____ file, which is ready to be ______. .exe files cannot be easily ______, so programmers prefer to supply them instead of ______ code.
Advantages of compilers continued - Can be supplied as .exe files - ready to run - preferred over source as they can't easily be modified
238
Disadvantages of compilers - Compilers usually don't spot _____ - the program has to be ______ and ___ before errors are encountered. This makes it ______ to see where the errors lie. - The source code must be __-______ every time the programmer changes the program.
Disadvantages of compilers - Don't usually spot errors, program has to be compiled and run before errors can be found - Hard to find errors - Source code re-complied every time the programmer changes the program