Year 12

AQA A level Computer Science [P2] Theory Notes

Paper 2 Theory

— Computer Science · A Level (9618) · Part A: Concepts, Program Development & Testing —
★ Exam Tip: Theory on Paper 2 is "free marks" (definitions, lists, 2–5 mark questions) — but the examiner has cut theory down and now asks more 7–9 mark pseudocode questions. Learn this part fast (2–3 days max) and spend your real time on pseudocode (Part C).
Sir's rule for theory answers: first write the points you are sure are in the mark scheme, then add extra points / an example. If you don't know whether a point scores — write more, not less. Always check how many marks → that many points.

1. Data Types

Type What it stores Examples
INTEGER whole number, no decimal 95 94 93 21 (even −5)
REAL number with decimal part 95.1 101.0 9.3 1.6
STRING alphabets, numbers, symbols (text in " ") "Computer Science"
CHAR single character in ' ' 'P' 'p' 'A'
BOOLEAN only 2 values (result of a comparison) TRUE FALSE
Trick: a single character could also be called a STRING — but the most suitable / appropriate type is CHAR. Exam says "appropriate" ⇒ pick CHAR.
past paper 20185 free marks

Give the data type for: Mark = 60 · Subject = "Computer Science" · Grade = 'B' · CourseCompleted = TRUE · AverageMark = 49.5

Mark → INTEGER (number, no decimal) Subject → STRING (text in double quotes) Grade → CHAR (single character in single quotes) CourseCompleted → BOOLEAN (TRUE/FALSE) AverageMark → REAL (has a decimal)

5 / 5

Sir's warning: exam questions on theory are "somewhat tricky" — you must practise 9618 past papers properly. For definitions, learn the exact wording; the examiner can ask any of them. Questions on definitions like these are quick marks.

2. Data Identifier Table

Definition: a table that lists the variables a program uses. (LOV = List Of Variables)

LOV (identifier) Description Datatype
ProjectCompleted tells the status of the project (True or False) BOOLEAN
What does an identifier table contain? ① list of variable names ② explanation of what each variable does ③ datatype of that variable.

3. Algorithm, Source Code, Object Code…

Algorithm: a sequence of steps / instructions to implement a task / a solution to a problem. (anything can have one — washing a car, studying!)

Stages of an algorithm (IPO)

① InputInput N1, N2 ② ProcessN1 + N2 = Answer ③ OutputPrint Answer
every problem needs data → processing → output
Term Meaning
Source code a solution / design / algorithm expressed in a high-level language
Object code produced by the compiler during the translation stage, by translating the source code. NOT produced by an interpreter.
Pseudocode using keywords and identifiers to describe an algorithm without following the syntax of a particular programming language
Flowchart pictorial / graphical representation of a program in a flow
Careful: definitions like "describe source code / object code" come as 2–3 mark questions — you can't "show" them, just learn the wording. Pseudocode ≠ Structured English (see Part B).

Features that make a program easier to read & understand

  1. Indentation
  2. Blank lines (white space)
  3. Capitalisation of keywords
  4. Sensible (meaningful) variable names
  5. Comments
  6. Pretty print
Why indentation? The examiner gives your marks. If he can't read the structure of your code he can't award marks — so indent loops / IFs.
"Explain why comments / indentation are useful" (2 marks): Comments explain what a section of code does, so the program is easier to understand and maintain. Indentation shows the structure of loops and selection (what is inside what), so the code is easier to read and follow.
★ Mark-scheme version (past paper): "State three features" ⇒ indentation · white space · comments · sensible/meaningful variable names (camelCase) · capitalised keywords (max 3).

4. Four Basic Constructs (building blocks of programming)

Construct Meaning Example / keywords
① Assignment a value is given a name (identifier) or the value of an identifier is changed Flag = True
Number = 5 → Number = Number − 1 → Number = 4
② Sequence steps performed one after the other statements run top → bottom
③ Selection under certain conditions some steps are performed, otherwise none / different steps IF … THEN … ELSE … ENDIF
CASE OF … OTHERWISE … ENDCASE
④ Repetition / Iteration steps performed a number of times (= looping) FOR…TO…NEXT (count-controlled)
WHILE…DO…ENDWHILE (pre-condition)
REPEAT…UNTIL (post-condition)
past paperidentify the construct · 6 marks

Tick Selection / Repetition / Assignment for each statement:

WHILE Count < 20 → Repetition Count ← Count + 1 → Assignment IF MyGrade <> 'C' THEN → Selection Mark[Count] ← GetMark(StudentID) → Assignment ELSE OUTPUT "Fail" → Selection ENDFOR → Repetition (easy to miss!)

6 / 6

5. Identifiers: Constant · Variable · Array

Constant Variable Array
fixed, not changeable
value cannot be changed accidentally during execution
temporary memory
stores a value that can change during execution
temporary memory
list of items of the same data type under a single name

6. Verification vs Validation

Verification

Computer AComputer Breached B ✓

Checking data has not changed during transfer / input to a computer. (same data arrived)

  • Double entry
  • Parity check
  • Checksum

Validation

Checking data meets certain criteria (is sensible). It does not prove data is correct.

  • Range check
  • Presence check
  • Length check
  • Format check
  • Character check
  • Type check
Pick the check: numbers / age ⇒ range · must not be empty ⇒ presence · password size ⇒ length · text expected ⇒ type.

Scenario e.g. "under-18s must sit in this class" ⇒ range check. Names can't be range-checked — only numbers / dates.

7. Types of Test Data (example: accepted range 5 ≤ x ≤ 10)

510 −2 abnormal12 · 14 abnormal 7 normal 4 (boundary, rejected)11 (boundary, rejected) 5 extreme10 extreme
green zone = accepted · red = rejected · 4 & 11 are the rejected edge values
Type Meaning Example
① Normal within range (accepted) 5 ≤ x ≤ 10 → 7
② Abnormal out of range (rejected) −2, 12, 14
③ Extreme in range — the largest and smallest accepted value 5 and 10
④ Boundary at the edge: one accepted + one rejected pair 5, 10 accepted · 4, 11 rejected
Note: the board's boundary example shows "accepted: 5, 10 | rejected: 11, 4" (my reading of the handwriting).

8. Features of a Program & the IDE

Features of a program: function / procedure · sequence ✓ · iteration ✓ · selection ✓ · parameters · variable ✓ · logic operation (mark schemes vary; input/output & comparison operators can also appear — write extra if unsure).

IDE (Integrated Development Environment): a software application that combines all the features and tools needed by a software developer.

Sir's note: IDE feature questions are mostly Paper 1. In Paper 2 the IDE appears through testing: "what tools does an IDE give you while testing a program?" (breakpoint, stepping, watch / report window).

Features of an IDE

  • Pretty print ✓
  • Automatic indentation ✓
  • Syntax checking ✓
  • Highlights any undeclared variable ✓
  • Type checking

Help in "initial error detection"

  • Dynamic syntax checking
  • Type checking
  • Identification of unused variables
Methods to find errors (debugging):
  • Dry run / trace table
  • Breakpoint — run the code up to a set point to find the error
  • Variable watch (report window) — checks the content of variables at specific points
  • Stepping — execute the code line by line
past paper q1(a)IDE debug · 4 marks

Function Calculate() returns an unexpected value. Describe how an IDE helps find the error.

✓ Breakpoint — stop the program at a particular line/instruction✓ Report / watch window — check value of variables at that point✓ Single stepping — run one statement / line at a time

1 mark for each underlined term + 1 mark for explaining it (max 4).

term + explanation × 2 = 4

9. Program Development Cycle

6 stages (books)

  1. Problem solving
  2. Design
  3. Coding
  4. Translating
  5. Execution
  6. Testing

5 stages ✓ (your mark scheme!)

  1. Analysis
  2. Design
  3. Coding
  4. Testing
  5. Maintenance
Remember: themark scheme follows the 5-stage version. Write that one.
Tool What it does
Editor produces the source code in a high-level language
Translator converts source code into object code
Debugger used to test the program / detect errors

10. Development Models

Three models: Waterfall · Iterative · Rapid Application Development (RAD).

① Waterfall model

AnalysisDesignCodingTestingMaintenance
each stage finished before the next starts
Principles: linear — each stage completed before the next begins · well documented · low customer involvement (only at start and end of the process)
Benefit Drawback
• easy to manage, understand and use
• stages don't overlap — completed one at a time
• works well for smaller programs
• difficult to change requirements at a later stage
• not suitable if the program is subject to change
• working program produced late in the life cycle
• not suitable for complex projects

② Iterative model

FirstwaterfallExtendedwaterfallFurtherextendedFinalwaterfall
if the first waterfall is successful it moves further — each pass extends the program
Principles: incremental development as the life cycle is repeated · high customer involvement — system shown to the customer after every iteration
Benefit Drawback
• easier to test and debug
• more flexible — easier to alter requirements
• customer involved each iteration ⇒ no surprises at the end
• whole system needs to be defined at the start
• needs good planning overall and at every stage
• not suitable for short, simple projects

③ Rapid Application Development (RAD)

TEAM 1TEAM 2TEAM 3 own waterfallown waterfallown waterfall A→D→C→T→MA→D→C→T→MA→D→C→T→M
program split into modules; each module = one team + its own waterfall
Principles: minimal planning · uses previously written code where possible · high customer involvement
Benefit Drawback
• reduced overall development time
• rapid feedback informs the development
• very flexible — requirements evolve from feedback
• modification easier because each part must work independently
• system under development needs to be modular
• needs a strong team of skilled developers
• not suitable for short, simple projects
past paper q5choose a model · 3+1+3 marks

Games-console website; requirements likely to change as more info about the console appears. A company chose waterfall.

(a)(i) Why NOT waterfall (any 2): no working software until late (slow to market; no early prototypes) · harder / slower to cope with requirement changes · needs high customer/stakeholder involvement (a)(ii) More appropriate: Iterative or RAD (b) Final test stage before release: Beta testing — small group of potential users test it in the real world, find errors, give feedback / suggestions; problems fixed before it is sold

11. Transferable Skills

Definition: skills a person has in one language that can be used in another language.

You should be able to recognise / understand in another language: declaration · assignment · sequence · selection · repetition / iteration · subroutines · parameters passed between modules · input / output (also variables, logic operations, comparison operators).

exam style2–3 marks

An algorithm is implemented in a high-level language and given to Albert, an experienced programmer unfamiliar with that language. Explain why Albert can still understand the program.

1 He uses his transferable skills to understand the new program.2 He can recognise basic control structures — loops, selection statements, declarations.3 He can read the comments / meaningful variable names.

12. Types of Maintenance (of a program — so it keeps running correctly)

① Corrective② Perfective③ Adaptive④ Preventive
Type Meaning Reason / key words
Corrective occurs when testing reveals a fault / error — it is found and fixed to amend the algorithm to eliminate errors
Perfective implements new or changed user requirements; functional enhancement — improves function and efficiency of the code "improve speed of response" ⇒ perfective
Adaptive changes made in response to specification changes — changed requirements or available technology changes to business rules or environment
Preventive activities to prevent the occurrence of errors —

13. Types of Error

Error Meaning Example
Syntax small grammatical mistakes, sometimes a single character — program won't compile / run missing semi-colon at end of a line; extra bracket at end of a function; "This is basketball very new"
Logic program runs but does not perform as expected — error in the logic wrong formula / wrong comparison; AVERAGE displayed wrongly
Run-time program executes an invalid instruction and crashes out-of-bounds array index; divide by zero
Link to past paper: the sqrt program had a design (logic) error — it compiled without errors because "the rules of the language have not been broken" (no syntax errors). A compiler cannot find logic errors.

14. Software Testing

Test Key points
Black-box match expected answer to actual answer (e.g. 5 + 3 → expect 8, got 8 ✓) · tester does not need to know the code structure · chooses normal, boundary and erroneous data
White-box test every possible logic path through the code · a trace table is often used
Alpha in-house testing — done by other developers in the software house (not the one who built it)
Beta out-of-house testing — a group of people assigned to find bugs; real users before release
Stub a simple / dummy module written to stand in for a module that is missing or faulty so testing can continue
Integration testing separately written modules to ensure they work together
Acceptance on the completed program, to prove to the customer / client it works as required · end-user testing
Board wording to fix: the board says stub testing is "carried out all the modules have been written" — it is carried out when some modules are NOT yet written (or are faulty), i.e. before they are all complete. Dummy returns a known value / prints a message to show it was called.
AbdullahAhmarAli Module 1Module 2 (missing ✗)Module 3 ✓ Big project — modules written by different people
Integration testing = combine modules, then test. If a module is missing → stub testing (dummy for Module 2, e.g. just "Display").
past paperstesting methods · 1–3 marks each
Q8(c)(i) Modules tested individually, then added to the program and further testing → Integration testing Q8(c)(ii) Module doesn't work when added → Stub testing: replace with a dummy / simple module that returns a known result or outputs a message to show it has been called Q5(a) Walkthrough needs: the program code / specification and a test plan (inputs + expected outputs). Why: the structure / algorithm must be known so all paths can be tested. Q5(b) Changes made to improve speed of response → Perfective maintenance

15. Stepwise Refinement & Subroutines

Stepwise refinement: breaking down an algorithm, to a level of sufficient detail, into smaller parts, from which it can be programmed.

Train Management System(one big problem)sub-tasks = modules (one team each)
big problem → many small sub-tasks, each refined separately

Note: each sub-task can be a module refined separately. A module / subroutine is either a function or a procedure.

Wording trap (sir): "decomposition of the code / breaking down into sub-problems" = stepwise refinement. Don't freeze — de-composing just means breaking down.
Procedure Function
sequence of steps with an identifier, called to perform a sub-task — does NOT return a value same, but RETURNS a value

Uses of a subroutine

  • perform a frequently used operation within a program
  • can be called when needed
  • can be reused by another program

Why use modules?

  • more manageable / understandable solution
  • module can be tested independently
  • program easier to maintain
Advantages of sub-routines (5): called from multiple places ✓ · tested independently ✓ · if task changes, change made only once ✓ · reduces unnecessary duplication ✓ · allows a team to work on different parts of the solution.

Passing parameters between modules

Values passed between modules are called parameters. Board example: Module A passes x to Module C; Module C passes z back to Module B — so x and z are parameters.

By value By reference
a copy of the variable is passed — original value is NOT changed the address of the variable is passed — original value IS changed
Past paper q5: DisplaySqrt(BYREF ThisNum) changed ThisNum, so the loop's Num was modified → unexpected results. It should have been passed BYVAL. (Compiler didn't flag it — no syntax rule broken. IDE: breakpoint + stepping + watch Num.)
How does structured programming support sub-tasks? subroutines · functions · procedures · parameters.

16. More Past-Paper Questions (with answers)

q1(b)spot the error · 3 marks
S1 Index ← STR_TO_NUM(("27") + 2) — brackets mismatch: STR_TO_NUM gets a string + number sum; "adding a string and number is invalid"; 2 should be added after the brackets / function S2 Index ← STR_TO_NUM(MID("CPE1704TKS", 4, 2)) — no error S3 IF MONTH(ThisDate) > '6' — MONTH() returns an integer but it is compared with a char/string; 6 should not be in quotes
q1(c)evaluate expressions · Active=TRUE, Points=75, Exempt=FALSE
(Points > 99) OR Active → TRUE(Points MOD 2 = 0) OR Exempt → FALSE (75 is odd)(Points <= 75) AND (Active OR Exempt) → TRUE(Active OR NOT Active) AND NOT Exempt → TRUE

Expression 4 in simplest form: NOT Exempt (Active OR NOT Active is always TRUE)

q3 points systemrecord / array of records · 4+2+5 marks

Customer: Name (String), Number of points (Integer), Date of birth (Date).

(a)(i) Structure: RECORD — a set of data related to one customer, of different types, held under a single identifier. (a)(ii) A (1D) array of records stores all customers.

(b) Stepwise refinement into 5 steps (bands: <$10 → 5 pts/$ · $10–$100 → 7 pts/$ · >$100 → 10 pts/$; e.g. $99.77 → band 2 → 7 × 99 = 693):

  1. use constants / variables for the thresholds 10 and 100; input amount spent
  2. work out which band the amount is in
  3. work out the rounded (whole-dollar) part of the amount
  4. points = rounded amount × points-per-dollar of the band
  5. output the number of points
q1 postal costconstants · 1+3+3+3 marks
(a)(i) Represent postal costs as constants.(a)(ii) Rates entered once · avoids accidental change · changed once only (easier to maintain) · easier to understand (max 3).(b) Features: indentation · white space · comments · sensible variable names · capitalised keywords.(c) ValidAddress = BOOLEAN · ItemPostalCost = REAL · ItemStatus = STRING
q1 Sheet4 (2D array)array facts · 3+2+1+4 marks

10 DECLARE Sheet4 : ARRAY[1:2, 1:50] OF INTEGER … 100 FOR PCount ← 0 TO 49 … Sheet4[1, PCount] ← 0 · Sheet4[2, PCount] ← 47 … 103 NEXT PCount

(a) dimension = 2 · index variable = PCount · number of elements = 2 × 50 = 100 (b) Error: array declared 1 to 50 but loop runs 0 to 49 (line 10 / 100 / 101 / 102). PCount was also not declared → INTEGER. (d) INPUT MyChoice → Input · OUTPUT FirstName & LastName → Process + Output · WRITEFILE OutputFile, TextLine → Output · READFILE MyFile, TextLine → Input · Result ← SQRT(NextNum) → Process
q5(d)1 mark

Make a complex statement ignored by the compiler without deleting it → change it into a comment (or into a string literal assigned/output).

q8(d),(e)file mode / efficiency
AddItem() adds info to Stock.txt → file mode APPENDFindItem() on file sorted ascending by ItemNum → the search can stop as soon as the current value read is greater than the value searched for (no need to read the whole file).
q7 shop emailswhat data does a module need? · 3+2 marks
Needed (any 3 + justification): customer name (personalise) · email address (deliver) · product-category preference (check interest) · contact preference (accepts email) · order history (similar products) · new product information (put in email) NOT needed (any 2): postal address (sending email not a letter) · payment details (nothing bought at this stage) · order history (preference decides relevance)
✓ Quick Recap — Part A
  • Types: INTEGER (no dp) · REAL (dp) · STRING " " · CHAR ' ' · BOOLEAN
  • 4 constructs: assignment · sequence · selection · iteration (FOR / WHILE pre / REPEAT post)
  • Validation = sensible (range, presence, length, format, character, type) · Verification = not changed (double entry, parity, checksum)
  • Test data: normal · abnormal · extreme · boundary
  • 5 stages: analysis · design · coding · testing · maintenance — Waterfall / Iterative / RAD
  • Maintenance: corrective · perfective · adaptive · preventive
  • Errors: syntax · logic · run-time — Tests: black · white · alpha · beta · stub · integration · acceptance
  • Procedure = no return · Function = returns · By value = copy · By reference = address (original changes)