Ilovepdf Merged
Ilovepdf Merged
3.1.1 Programming
Advanced Notes
www.pmt.education
Specification:
www.pmt.education
3.1.1.3 Arithmetic operations
Be familiar with and be able to use:
● addition
● subtraction
● multiplication
● real/float division
● integer division, including remainders
● exponentiation
● rounding
● truncation
www.pmt.education
3.1.1.7 String-handling operations in a programming language
Be familiar with and be able to use:
● length
● position
● substring
● concatenation
● character → character code
● character code → character
● string conversion operations
www.pmt.education
3.1.1.13 Local variables in subroutines
Know that subroutines may declare their own variables, called local
variables, and that local variables:
● exist only while the subroutine is executing
● are accessible only within the subroutine
Be able to use local variables and explain why it is good practice to do
so.
www.pmt.education
Data Types
The way in which data is stored depends on what the data is. A data type is defined by the
values it can take or the operations which can be performed on it.
In some situations, it might be possible to store one piece of data using various different
data types. In this case, the programmer must decide which option is the best suited to
solving a particular problem or which is the most memory-efficient.
For example, if a programmer needs to store a user’s age in years, they could use a string
or an integer. In this situation, using an integer would be the best option, because a
person’s age is only ever going to contain numerical digits.
www.pmt.education
User-defined data types
The way in which you use user-defined data types differs between programming
languages. It’s important that you know how to use them in your chosen language.
Programming Concepts
Programming languages support a variety of different statement types, some of which are
explained in the table below.
Variable declaration Creating a variable for the first time, giving it a name
and sometimes a data type. This allocates a portion of
the computer’s memory to the variable.
www.pmt.education
Definite and indefinite iteration
Iteration is the process of repeating a block of code. Examples of iteration include for
loops and whileloops.
Definite iteration is a type of iteration in which the number of repetitions required is known
before the loop starts.
In contrast to definite iteration, indefinite iteration is used when the number of repetitions
required is not known before the loop starts.
This is an example of definite iteration. The The whileloop above uses indefinite
forloop will run 64 times before finishing. iteration. The number of repetitions is not
known before the loop begins.
Nested Structures
Selection structures and iteration structures can be nested.
www.pmt.education
Meaningful Identifier Names
When declaring a constant, variable or subroutine, it’s
important to give it a sensible and meaningful identifier name.
This makes it easier for others to understand what the
purpose of the named object is within the program.
Addition When two values are added, the result is 128 + 42 = 170
the sum of the two values.
www.pmt.education
Relational Operations
You can make use of relational operators whenever you need to compare two values.
They are used in iterative and selection structures as well as for base cases in recursion.
Operation Example
Equal to 12 = 12
Boolean Operations
As explained earlier in this document, a Boolean data type is one whose value can only
ever be true or false. There are a series of operations that can be performed on Boolean
values.
www.pmt.education
Constants and Variables
When a program needs to store data, it usually does so using one of two types of data
item: constants or variables.
As their name suggests, variables can change their value during the execution of a
program, whereas a constant’s value cannot change once assigned.
The pseudocode examples above show two different approaches to the same problem.
One approach uses hard-coded values whereas the other uses constants.
The code which makes use of constants is easier to understand as it clearly specifies that
14refers to an hourly rate. In the example which uses hard-coded values, it’s difficult to
understand why HoursWorkedis being multiplied by 14.
www.pmt.education
String-handling operations
Function Description
www.pmt.education
Random number generation
It’s important that you make yourself familiar with random number generation in your
chosen programming language.
Exception handling
When an error occurs in program code, an “exception” is said to be thrown. This could be
caused by using the wrong data type, attempting to divide by zero or attempting to access
a non-existent element in an array to name a few examples.
This code will prevent the program from crashing and might inform the user that an error
has occurred. Once the exception has been handled, the program uses the system stack
to restore its previous state before resuming execution.
Subroutines
www.pmt.education
Parameters of subroutines
Parameters are used to pass data between subroutines within programs. Specified within
brackets after a subroutine call, parameters hold pieces of information that the subroutine
requires to run.
Length ← USERINPUT
Width ← USERINPUT
OUTPUT CalculateArea(Length, Width)
SUBROUTINE CalcualteArea(x, y)
RETURN x * y
ENDSUBROUTINE
The actual value passed by a parameter is called an argument. If a rectangle with sides of
height 4 and width 6 was input into CalculateArea , the parameters Lengthand Width
would have arguments 4 and 6 respectively.
A subroutine can return a value. One that always returns a value is called a function, but
don’t think that procedures can’t return a value, they can (but don’t always).
Subroutines that return values can appear in expressions and be assigned to a variable or
parameter.
Length ← USERINPUT
Width ← USERINPUT
Area ← CalculateArea(Length, Width)
OUTPUT Area
SUBROUTINE CalcualteArea(x, y)
RETURN x * y
ENDSUBROUTINE
For example, in the pseudocode above, the variable Areais assigned to the subroutine
CalculateArea . The value taken by the variable will be the value returned by the
subroutine.
www.pmt.education
Local variables in subroutines
A local variable is a variable that can only be accessed from the subroutine within which it
is declared. They only exist in the computer’s memory when their parent subroutine is
executing. This makes local variables a more memory efficient way of storing data than
using global variables, which are discussed below.
Global variables
In contrast to local variables, global variables can be accessed from any part of a program
and exist in memory for the entire duration of the program’s execution.
Local variables can be given the same identifier name as global variables, although this is
generally considered bad practice. When the local variable’s value is changed, the global
variable’s value remains the same.
www.pmt.education
AQA Computer Science A-Level
3.1.2 Procedural-oriented programming
Advanced Notes
www.pmt.education
Specification:
www.pmt.education
The procedural programming paradigm
Most of the programs that you may have written are likely to have been procedural.
When a program is split into modules, testing can be carried out on the individual modules
before they are combined to form the overall solution. Furthermore, development can be
split over a team of developers each of which is assigned a different module to work on.
www.pmt.education
Hierarchy charts
A hierarchy chart graphically represents the structure of a structured program. Each
procedure is displayed as a rectangle which is connected to any other procedures that are
used within it.
Example
These procedures form part of a program that allows a user to play a game.
SUBROUTINE StartFromLevel(number)
IF number = 1 THEN
SUBROUTINE StartGame()
PlayLevelOne()
level ← INPUT
SUBROUTINE BeginNewGame() ELSEIF number = 2 THEN
IF level = 1 THEN
username ← INPUT PlayLevelTwo()
BeginNewGame()
OUTPUT “Hello” + username ELSEIF number = 3 THEN
ELSE
StartFromLevel(1) PlayLevelThree()
StartFromLevel(level)
END SUBROUTINE ELSE
END IF
OUTPUT “No such level”
END SUBROUTINE
END IF
END SUBROUTINE
The three procedures above form a program which could be represented by the hierarchy
chart below.
Each rectangle in the hierarchy chart represents a procedure in the program. The lines
between the rectangles show the relationships that exist between the different procedures.
www.pmt.education
AQA Computer Science AS-Level
3.2.1 Data structures and
abstract data types
Advanced Notes
www.pmt.education
Specification:
www.pmt.education
Data structures
Data structures are used by computers as the containers within which information is
stored. Different data structures exist and some are better suited to different types of data
than others. When storing data, a programmer must decide which of the data structures
available is the best to use.
Arrays
The array shown above is a one-dimensional array which could be visualised with the
following table:
0 1 2
Arrays can be created in many dimensions. For example, a two-dimensional array could
look like this:
Array Maze = { {Wall, Path, Wall}, {Path, Path, Wall}, {Wall, Path, Wall}}
When displayed in a table, the Mazearray starts to make a little more sense:
www.pmt.education
Fields, records and files
It’s important that you make sure you can write to and read from files in your chosen
programming language.
www.pmt.education
Definitions and Concepts for AQA Computer Science AS-level
3.1.1 Analysis
Analysis: The first stage of software development where the problem is defined and the
requirements for the system are identified.
Data Model: An abstract model organising data items and their relations to one another and
to the real-world entities they represent.
3.1.2 Design
Design: The second stage of software development where the algorithms, data structures
and user interfaces are designed. Data input, processing, output and security specifications
are taken into account along with hardware considerations.
3.1.3 Implementation
Implementation: The third stage of software development where the actual code and data
structures are written and developed based on the agreed design specifications to produce
prototypes.
3.1.4 Testing
Boundary Test Data: Test data typically on the edge case of the acceptable range of inputs.
Erroneous Test Data: Test data typically outside of the acceptable range of inputs that is
invalid and should trigger the system to produce an error.
Normal (Typical) Test Data: Test data within the acceptable range for the system. The
expected result should be obtained from the system.
Testing: The fourth stage of software development where the system is tested for errors and
inconsistencies with the analysis and design specifications using a variety of different input
data and scenarios.
https://bit.ly/pmt-cc
https://bit.ly/pmt-edu https://bit.ly/pmt-cc
3.1.5 Evaluation
Evaluation: The final stage of software development where the system is critically reviewed
with the user specification and judged according to the performance objectives and its
usefulness to solving the problem.
https://bit.ly/pmt-cc
https://bit.ly/pmt-edu https://bit.ly/pmt-cc
AQA Computer Science AS Level
3.4.1 Abstraction and automation
Advanced Notes
www.pmt.education
Specification:
3.4.1.1 Problem-solving:
Be able to develop solutions to simple logic problems.
Be able to check solutions to simple logic problems
3.4.1.3 Abstraction:
Be familiar with the concept of abstraction as used in computations and
know that:
● representational abstraction is a representation arrived at by
removing unnecessary details
● abstraction by generalisation or categorisation is a grouping by
common characteristics to arrive at a hierarchical relationship of
the 'is a kind of' type
www.pmt.education
3.4.1.5 Procedural abstraction:
Know that procedural abstraction represents a computational method.
3.4.1.9 Decomposition:
Know that procedural decomposition means breaking a problem into a
number of sub-problems, so that each sub-problem accomplishes an
identifiable task, which might itself be further subdivided.
3.4.1.10 Composition:
Know how to build a composition abstraction by combining procedures
to form compound procedures.
Know how to build data abstractions by combining data objects to form
compound data, for example tree data structure.
3.4.1.11 Automation:
Understand that automation requires putting models (abstraction of real
world objects/ phenomena) into action to solve problems. This is achieved by:
● creating algorithms
● implementing the algorithms in program code (instructions)
● implementing the models in data structures
● executing the code
www.pmt.education
Problem Solving
Problem solving is the process of finding a solution to a difficult or complex issue.
In an exam, you might be given a series of statements from which you have to find the
answer to a question.
George is a student
and
All students like chocolate
All chocolate is eaten This could be true, because we’re not told that
by students
✘ anyone other than students eat chocolate, but we
can’t say for sure.
Exam questions often contain more than two statements, but the process of forming a
reasonable conclusion is the same.
Harder example: Alice, Bob and Charlie are each wearing a hat, cannot see their own hat
and can see the others’ hats. They are then told that each of their hats is either green or
yellow and that they don’t all have the same colour hat. Charlie then says “I know that my
hat is yellow”.
www.pmt.education
Bob’s hat is green.
Charlie can see both Alice and Bob’s hats. For Charlie to be able to say that she knows
the colour of her hat, Alice and Bob must have the same colour hats. Because Charlie has
been told that it’s not possible for all three to have the same colour, she can work out that
her hat is the colour that Alice and Bob’s hats are not. Therefore Charlie works out the
colour of her hat is yellow. This means that Bob’s hat is not yellow, so must be green.
Algorithms
Assignment in pseudocode
Assignment is the process of giving a value to a variable or constant. In pseudocode,
assignment is represented using an arrow pointing towards the variable or constant that is
being given a value.
counter ← 27
name ← “Sarah”
The pseudocode above assigns the value 27 to the variable counterand the value Sarah
to the variable name
.
Sequence in pseudocode
Sequence is the name given to instructions that follow on from one another.
counter ← 18
counter ← counter + 1
remainingIterations ← 20 - counter
In the pseudocode above, the variable counteris set to 18 and then incremented by one.
Following that, the variable remainingIterationsis set to twenty minus the value of
counter . The operations will be executed in the order that they appear.
www.pmt.education
Selection in pseudocode
Selection is the process of choosing an action to take based on the result of a comparison
of values.
The pseudocode above compares the value of the variable name to the value “Brian” and
outputs different values depending on the result of the comparison.
Iteration in pseudocode
Iteration is the process of repeating an operation. Iteration structures include FORand
WHILEloops.
FOR number ← 6 to 12
OUTPUT number / 2
END FOR
www.pmt.education
Abstraction
Abstraction is the name given to the process of omitting unnecessary details from a
problem.
When solving a problem, abstraction can be used to simplify the problem which can in turn
make finding a solution easier.
There are two distinct forms of abstraction: representational abstraction and abstraction by
generalisation / categorisation.
The definitions of these two forms of abstraction are often asked for in exams, so it’s worth
learning them.
Information hiding
Information hiding is defined as the process of hiding all details of an object that do not
contribute to its essential characteristics. For example, if you’re designing a program that
works out how many cars can fit onto a ferry, information about the manufacturer or the
colour of a car can be disregarded and just information about the size and weight of cars
retained.
Procedural abstraction
Procedural abstraction involves breaking down a complex model into a series of reusable
procedures. The actual values used in a computation are abstracted away and a
computational method is achieved.
For example: To calculate the area of a rectangle, this procedure could be used:
CalcualteArea = width * height
Functional abstraction
Procedural abstraction results in a procedure. Abstracting further disregards the particular
method of a procedure and results in just a function.
For example: Abstracting the procedure from the previous example leaves us with a
function: RectangleArea = CalculateArea()
www.pmt.education
Data abstraction
In data abstraction, specific details of how data is actually
represented are abstracted away, allowing new kinds of data
structures to be created from previously defined data
structures. Data abstraction forms the basis of abstract data
types.
Decomposition
When using decomposition, a problem is divided into a series of smaller sub-problems.
These smaller problems can be solved individually or further divided until all parts of the
original problem have been solved.
Composition
When dealing with a complex problem, composition can be used to combine procedures to
form a larger system. Composition is used in abstract data types, where a complex
abstract data type is formed for smaller and simpler data types.
Automation
Automation is the process of putting abstractions of real world phenomena (which are
referred to as models) into action to solve problems. Automation is achieved by creating
algorithms which are later implemented in code, implementing models in data structures
and finally executing the code on the data structures.
www.pmt.education
AQA Computer Science AS Level
3.4.2 Finite state machines (FSMs)
Advanced Notes
www.pmt.education
Specification:
www.pmt.education
Finite State Machines
A finite state machine (or FSM for short) is a computational model for a machine that is
always in a fixed state. Each finite state machine has a finite number of states and can
only ever be in one state at a point in time.
The state of a finite state machine will change depending on the current state and the input
data. If the input data is valid, the finite state machine will terminate in an accepting state.
A finite state machine’s state can change and does so according to transition rules, rules
that describe what a finite state machine should do given certain criteria.
For example, the state transition diagram above has four states: S0, S1, S2 and S3. The
start state is S0 and S3 is an accepting state.
The transition functions are each represented by an arrow (the leading arrow merely
signifies the start state and does not represent a transition function).
The finite state machine represented by the state transition diagram will only accept input
data that starts with 11
. For example: 11
, 110
, 11101and 11001100.
www.pmt.education
State Transition Tables
The transition function between S0 and S1 in the previous diagram could be described in
English as “If the finite state machine is in state S0 and the input is 1, move to state S1. ”
The transition functions in a finite state machine can be notated more formally using a
state transition table, with columns for current state, input and next state, like the one
below.
S0 1 S1
S0 0 S2
S1 1 S3
S1 0 S2
The finite state machine shown by the state transition diagram below represents a parking
machine which requires 50p to be payed. The machine is only designed to take coins
worth 10p or more.
If the customer first pays 10p, the machine moves into the 10p state, from which the
customer can input another 10p or 20p. The 50p state is the accepting state.
www.pmt.education
Example - Parity
The machine has two states, one start state and one
accepting state.
S0 1 S1
S0 0 S0
S1 1 S0
S1 0 S1
www.pmt.education