0% found this document useful (0 votes)
12 views12 pages

J277 - 2022 Revision Booklet - Paper 2

The document outlines key topics in computational thinking, programming fundamentals, and producing robust programs, including algorithms, data types, and testing methods. It covers principles such as abstraction, decomposition, and algorithmic thinking, as well as various searching and sorting algorithms like binary search and bubble sort. Additionally, it emphasizes defensive design, testing strategies, and the importance of using appropriate variable names and comments for maintainability.

Uploaded by

2007.ajaygoswami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views12 pages

J277 - 2022 Revision Booklet - Paper 2

The document outlines key topics in computational thinking, programming fundamentals, and producing robust programs, including algorithms, data types, and testing methods. It covers principles such as abstraction, decomposition, and algorithmic thinking, as well as various searching and sorting algorithms like binary search and bubble sort. Additionally, it emphasizes defensive design, testing strategies, and the importance of using appropriate variable names and comments for maintainability.

Uploaded by

2007.ajaygoswami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Name:______________________

Specification Name of topic Sub part of topic directly assessed


Reference
Topic 2.1 - 2.1.1 - Principles of computational thinking:
Algorithms Computational Abstraction, Decomposition and Algorithmic thinking
thinking
2.1.2 Designing, - Identify the inputs, processes, and outputs for a problem
creating and - Structure diagrams
refining algorithms - Create, interpret, correct, complete, and refine algorithms using:
Pseudocode, Flowcharts, Python
- Identify common errors
- Trace tables

2.1.3 Searching - Standard searching algorithms: Binary Search, Linear Search


and sorting - Standard sorting algorithms: Bubble Sort, Merge Sort, Insertion Sort
algorithms
Topic 2.2 – 2.2.1 Programming - The use of variables, constants, operators, inputs, outputs and assignments
Programming fundamentals - Sequence, Selection, Iteration (Count + Controlled Loops)
fundamentals - The common arithmetic operators
- The common Boolean operators AND, OR and NOT
2.2.2 Data types - The use of data types: Integer, Real/Float, Boolean, Character and String, Casting
2.2.3 Additional - The use of basic string manipulation
programming - The use of basic file handling operations:
techniques - Open, Read, Write, Close
- The use of records to store data
- The use of SQL to search for data
- The use of arrays, 1 and 2 dimensional
- How to use sub programs (functions and procedures) Random number generation

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

2.3.2 Testing - The purpose of testing


- Types of testing:
- Iterative
- Final/terminal
- Identify syntax and logic errors
- Selecting and using suitable test data: Normal, Boundary, Invalid, Erroneous
- Refining algorithms

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

2.1.1 Computational Thinking


Abstraction: Removing of unnecessary information help solve the problem easier. For
example if you are writing a car route planner the height of buildings or
what they look like isn't important.
Decomposition: Breaking down a problem into small tasks to make it easier to solve.
Algorithm: Is a list of instructions that, when followed, will solve a problem. It should
also be repeatable.
Algorithmic Thinking: Thinking about how a problem can be solved using an
algorithm. Identifying the steps that need to be solved.
Computational Thinking: Thinking about how a problem can be solved using a computer.

2.1.2 Designing, creating and refining algorithms


Flowcharts:
What does it mean? Symbol Example

Start/End End

Input / Output Output Age

Yes
Is Age>=18?
Decision
No

Process X = X + 10

Sub Program Calculate

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

AvgGrade (g1, g2)


END

No
IF av>=60? Output av, “Fail”

SUBROUTINE: Just like in Python we can


Yes
have subroutines (functions) which
return a value. Here we create a sub
Output av, “Pass” routine that takes two parameters grade
1 (g1) and grade 2 (g2). We return the
average called av in this instance.

END

Exam question: What would be outputted given the following inputs:

A). 30 35 Answer: 32.5 Fail


Notes:
B). 50 60 Answer: 55 Fail
• Remember in subroutines to
C). 60 60 Answer: 60 Pass have return if needed before
D). 100 10 Answer: 55 Fail you END

E). 57 66 Answer: 61.5 Pass • Be careful for >= (greater than


equal to) rather than just >
(greater than). The same with
less than.
• Any file saving or reading will
be done via the Input / Output
box.
Trace Tables

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

Output(A+B) 6 Here A is > 2 so we carry on

A=A-B 4

B=B+1 2

Output(A+B) 6 Here A is > 2 so we carry on

A=A-B 2

B=B+1 3

Output(A+B) 5 Here A is not > 2 so we stop

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

Look at middle item (or middle left if no exact middle)


Adam Karl Lucy Penelope Rhianna Wania Zayna
It is not Adam and Adam comes before Penelope
Repeat: Look at middle item (or middle left if no exact middle)
Adam Karl Lucy Penelope
It is not Adam and Adam comes before Karl
Adam

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.

Linear Search: Can be used on any data but it is a slow search.


Example: We are searching for 29
7 5 14 29 34 22 17
Look at first element: Not 29 so we move on
7 5 14 29 34 22 17
Next element: Not 29 so we move on
7 5 14 29 34 22 17
Next element: Not 29 so we move on
7 5 14 29 34 22 17
Next element: 29 Found
7 5 14 29 34 22 17

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

Move along list until we find a number 9 6 21 8 4 8


equal to or greater than 6 and then put 6
behind it.

Then go to next number. So here we 6 9 21 8 4 8


check 6 then 9 and find the end of sorted
list so we add 21 to the end.

We check 6 then find 9 (it’s greater than


6 9 21 8 4 8
or equal to 8) so we put 8 before 9.

This gets repeated until all numbers


6 8 9 21 4 8
done. (Not shown here)

Topic 2.2 – Programming fundamentals

2.2.1 Programming fundamentals

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.

Ways we can check entered data is valid:


2.3.2 Testing
Testing: It is very important that you look for errors in bugs when creating a program. So we test the
product both as we go along and at the end.
Iterative testing Final or Terminal

• 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.

Example Code: Test Type Test Data


W=input(“Enter a number Normal 10
between 7 and 14 inclusive”)
w=w*2
print(w) Boundary 7 and 14

Invalid 21

Erroneous “Hello”
Types of errors

There are 3 types of errors that can occur in a program:

Error Description Example


Syntax You basically typed something wrong. The pint(Age)
most common error and easy to fix.
Logical The programs runs and doesn’t crash but Age=18
if Age>18:
isn’t doing what you want. Here we want to
print(“Entry allowed”)
check if someone is 18 or over but it actually else:
checks only over 18. Print(“Not 18 yet”)

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:

1st Level –Machine Code 2nd Level—Assembly Code


•Directly executable by the processor •Uses mnemonics
•The generation that ‘computers •Easier to program but still difficult and very hard to
understand’ debug
•Difficult to program in, hard to •One Assembly Language instruction translates to one
understand, hard to find errors (hard to Machine Code Instruction (1-1 relationship)
debug) •Needs to be translated into Machine Code for the
computer to be able to execute it
•Commonly used to make device drivers

The process of translating it into machine code is called


assembling and is done an assembler.

High Level—More Human Like:


3rd Level—High Level (JAVA, Python, C++) 4th Level– Declarative Languages (SQL, Alexa)
•Easier to understand (programmer) •Facts and Rules are stated
•Easier to find errors, easier to de-bug •Describes what computation should be
performed and not how to perform it
•Uses English-Like Keywords
•Examples include:
•One instruction translates into many machine
code instructions •SQL
•Expert Systems
•Artificial Intelligence

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:

Things and IDE can do:


•Auto-completion: It will help to complete a function or code
•Bracket matching: It will colour brackets to show the () pairs
•Syntax checks: It will recognise the incorrect use of syntax and highlights any errors.
•Breakpoints: These allow you to set a point where the program will pause allowing you to
look at the current variables etc..
•Error Reporting: It will show errors found when executing the program in a window and
often highlight the line the error was on.

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>

This table is called tblProducts:

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.

SELECT Product_Code, Price SELECT *


FROM tblProducts FROM tblProducts
Where Price_Paid>=1
WHERE Price>=1.99 AND Price<=2.99

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy