J277 - 2022 Revision Booklet - Paper 2
J277 - 2022 Revision Booklet - Paper 2
Topic 2.3 - 2.3.1 Defensive - Defensive design considerations: Anticipating misuse, Authentication
Producing design - Input validation
robust programs - Maintainability: Use of sub programs, Naming conventions, Indentation, Commenting
Topic 2.4 – 2.4.1 Boolean Logic - Simple logic diagrams using the operators AND, OR and NOT
Boolean logic - Truth tables
- Combining Boolean operators using AND, OR and NOT
- Applying logical operators in truth tables to solve problems
Topic 2.5 - 2.5.1 Languages - Characteristics and purpose of different levels of programming languages:
Programming High-level languages/Low-level languages
languages and - The purpose of translators
IDE - The characteristics of a compiler and an interpreter
2.5.2 The Common tools and facilities available in an Integrated Development Environment:
Integrated - Editors
Development - Error diagnostics
Environment - Run-time environment
- Translators
Topic 2.1 - Algorithms
Start/End End
Yes
Is Age>=18?
Decision
No
Process X = X + 10
START
Example:
Input x Here is what would be outputted given
the numbers show.
x = x * 10
20 Fail
Yes
35 Fail
Is x >= 400? Output x
40 400
No
52 520
Output “Fail”
End
60 600
END AvgGrade (g1, g2)
Input g1
av = (g1+g2) / 2
Input g2
RETURN av
No
IF av>=60? Output av, “Fail”
END
A trace table shows a person going through the steps of a program and A=5
writing down the values of any outputs and variable updates. It can help with
B=0
debugging errors.
While A>2
Let’s take this simple program:
A=A-B
Step 1). Write out a table with all the variable names and output. Put in the
B=B+1
starting variables values.
Output (A+B)
Step 2). Go through the program and as a variable is set or you give an output on a new line write the value.
You don’t write the code or notes as I have here, I am just doing it to help you see
what I am looking at. You just write the table out!
A B Output
Starting Values 5 0 Here A is > 2 so we enter loop
A=A-B 5
B=B+1 1
A=A-B 4
B=B+1 2
A=A-B 2
B=B+1 3
Another Example that the exam board give: Note that here the print command is outside the loop so it hap-
pens after the loop ends.
2.1.3 - Searching and sorting algorithms
Binary Search: The data must be ordered (sorted) for this type of search.
Example: We are searching for Adam.
Adam Karl Lucy Penelope Rhianna Wania Zayna
Adam found, if this was not Adam then we say no more elements and not in list.
Why is a binary search fast? Because it halves the items to search each time to find what we are looking
for.
What type of data do we need for a binary search? Sorted/ordered data.
Why is a linear search considered slow? Because it has to go through each element to find out if
something is in the data.
What type of data do we need for a linear search? Any data is acceptable.
Bubble Sort: Sorts data by looking at pairs of data and swapping them into the correct order.
Starting Data: 9 6 21 8 4 8
One cycle example:
We Look at first pair and swap if needed. 6 9 21 8 4 8
Next pair no swap needed. 6 9 21 8 4 8
6 9 8 21 4 8
6 9 8 4 21 8
6 9 8 4 8 21
One cycle completed.
How do you know when the data is sorted using a bubble sort? You keep repeating cycles of going
through the data, preforming swaps if needed, until you didn't do a single swap in that cycle and then you
know the data is in order.
Why is bubble sort considered slow? Because data in the wrong place only moves one position per cycle.
So if the first sorted element was actually at the end it would take a lot of cycles to get to the front.
Merge Sort: Breaks down the data into small chunks to sort them then puts them back together.
Starting Data: 9 6 21 8 4 8 22
Break it down into single pieces of data:
9 6 21 8 4 8 22
9 6 21 8 4 8 22
Then into pairs sorted: If you have an odd number just have the last one be on its own.
6 9 8 21 4 8 22
Then into quads sorted: If you have an odd number just have the last ones be on their own. Always do
full ones and just have what’s left. So if we had 9 elements it would be two 4s then a single.
6 8 9 21 4 8 22
Then into full list (or 8 if more elements it double each time)
4 6 8 8 9 21 22
Insertion Sort: Breaks the data into sorted an unsorted and moves data into the correct position from on
side to the other.
Starting Data: 9 6 21 8 4 8
9 6 21 8 4 8
Sorted Unsorted
Variables: A piece of information in a computer program that can change. Score=50 is an example of a variables.
Constants: Similar to a variable except it cannot be changed, think of PI in a computer program.
Sequence: In a computer program things are performed in an order called a sequence.
Selection: Programs can ask question and perform some code based on the result of the question. Think of using an
IF statement.
Iteration: Programs can loop and there are two main loops:
Count Controlled Loop: A FOR loop is count controlled as it loops a certain number of times.
Condition Controlled Loop: A WHILE loop is condition controlled as it loops while a condition is true.
The common arithmetic operators:
% MOD Modular Gives the reminder of a division.
+ Addition Example: 9%4 gives 1 as the it is
- Subtraction 2 remainder 1.
* Multiplication // DIV Division Gives the division of a number
/ Divide
Boolean operators: Program can use AND, OR and NOT to perform multiple checks or check if something isn’t true.
Topic 2.3 - Producing robust programs 2.3.1 Defensive design
This is all about making a program safe and also about making it easy to improve and
maintain.
Here are some things you can do (common exam question):
Variable Names: Giving suitable variable names helps to maintain the program.
Comments: Adding comment sin the code to help other programs or yourself
remember what it does.
Naming Conventions: Having a system that all programmers follow when naming
variables for example they could all use _ as a space so all variables look like
First_Name Player_Score etc..
Sub programs: Breaking a program down into smaller parts (decomposition) makes it
easier to maintain and improve.
• Testing the code as you create it. Testing is carried out at the end of the program
•This could be completed line by line or a section at when it has been written.
a time. •This is more similar to a GCSE.
•Once tested and feedback is received you then •It is used as a final check to make sure a program
alter your code as required. is working properly.
•You could consider this type of testing similar to
tuning a guitar.
–You keep playing the string and adjusting the
tension until the note is the correct pitch.
Test Data: Selecting good test data is essential and these are the types of data you can use:
Type Explanation
Normal Just data that should be accepted so for an Age input you would try 56.
Boundary This is where you check the range of accepted values. For example if we have a
program where a user enters a number between 1 and 100. We would test 1 and
100.
Invalid This is data that is of the correct data type but it outside a range. So in the above
example we would enter 101 (or nay number outside the range) and this should
be rejected.
Erroneous This is where we enter incorrect data types into the field. We might enter “Dave”
for the age value.
Invalid 21
Erroneous “Hello”
Types of errors
Run Time This is an error that can only occur when the Data= [ 4, 6, 7 ]
program is running, it will crash the program print( Data[5] )
if not handled. Common examples: ------------------------------
• Trying to read from a file that doesn’t
exist.
• Trying to access an array element that
isn’t there. So a list of 3 items but you
try to access the 6th (see example)
• Dividing by 0 causes a runtime error.
2.5.1 Languages
Whilst all computer cans execute is machine code we can write programs in other languages and
convert them into machine code for execution. There are different levels of languages that start
machine like and get more human like as they go up.
Low Level—Closer to the computer language:
Language Translators are used to translate a language into a form that the computer will be able
to directly execute. For 3rd Level languages there are 2 ways to do:
Compiler Translator
Translate entire source code all in one go into Translate and execute source code.
Machine Code. Line by line, statement by statement.
Optimise code. Source code is checked for syntax – if correct,
Used at the end of development (ready for code is executed. If incorrect interpreting is
shipping). stopped.
Error Reports created along with Object Code. Used for development (aid debugging).
Source code is safer
2.5.2 The Integrated Development Environment / IDE
Integrated Development Environment are used to help you develop your code for a
program. The IDE itself is a program that will assist you with the features listed below:
2.2.3 SQL
SQL is a language designed to work with databases. In the exam they will most likely ask you to
do a search on a table.
SELECT <What data do we want back (a list of field names or * meaning all)>
FROM <Table Name>
WHERE <Search Criteria>
Note: Can use OR and NOT in the search criteria. WHERE NOT Name=“Pen” would return
everything apart from the Pen. WHERE Name=“Binder” OR Name=“Pencil” would return both
those items.
Question 1 Question 2
Write an SQL search that returns the Write SQL code that will return all the data
Product_Code and Price of all products about every Product between the Price of
where the Price_Paid is £1 or more. 1.99 and 2.99 inclusive.