0% found this document useful (0 votes)
28 views

PuppNotes

The document outlines key concepts in computer science, focusing on the Program Development Life Cycle (PDLC), algorithm design, and data validation. It includes detailed explanations of analysis, design, coding, testing, and various programming constructs such as algorithms, data types, and database management. Additionally, it provides examples and best practices for implementing these concepts in programming scenarios.

Uploaded by

nishaaneducation
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)
28 views

PuppNotes

The document outlines key concepts in computer science, focusing on the Program Development Life Cycle (PDLC), algorithm design, and data validation. It includes detailed explanations of analysis, design, coding, testing, and various programming constructs such as algorithms, data types, and database management. Additionally, it provides examples and best practices for implementing these concepts in programming scenarios.

Uploaded by

nishaaneducation
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/ 44

Pupnotes P2 Midlength!

Made by Pup Studies(apuppy. on discord)

Ping me or add me if you are stuck or if anything is wrong with the context

Table of Contents
(You can access this via the outline sidebar as well)
Chapter 7:
●​ 7.1 Understand the program development life cycle, limited to: analysis, design,
coding and testing
●​ 7.2 (all 3 points are combined), it is in the design section of the PDLC
○​ (a) Understand that every computer system is made up of sub-systems,
which are made up of further sub-systems
○​ (b) Understand how a problem can be decomposed into its component
parts
○​ (c) Use different methods to design and construct a solution to a problem
●​ 7.3 Explain the purpose of a given algorithm
●​ 7.4 Understand standard methods of solution
●​ 7.5
○​ (a) Understand the need for validation checks to be made on input data
and the different types of validation check
○​ (b) Understand the need for verification checks to be made on input data
and the different types of verification check
●​ 7.6 Suggest and apply suitable test data
●​ 7.7 Complete a trace table to document a dry-run of an algorithm
●​ 7.8 Identify errors in given algorithms and suggest ways of correcting these
errors
●​ 7.9 Write and amend algorithms for given problems or scenarios, using:
pseudocode, program code and flowcharts
Chapter 8:
●​ Disclaimer for chapter 8
●​ 8.1.1 Declare and use variables and constants
●​ 8.1.2 Understand and use the basic data types
●​ 8.1.3 Understand and use input and output
●​ 8.1.4
○​ (a) Understand and use the concept of sequence
○​ (b) Understand and use the concept of selection
○​ (c) Understand and use the concept of iteration
○​ (d) Understand and use the concepts of totalling and counting
○​ (e) Understand and use the concept of string handling
○​ (f) Understand and use arithmetic, logical and Boolean operators
●​ 8.1.5 Understand and use nested statements
●​ 8.1.6
○​ (a) Understand what is meant by procedures, functions and parameters
○​ (b) Define and use procedures and functions, with or without parameters
○​ (c) Understand and use local and global variables
●​ 8.1.7 Understand and use library routines
●​ 8.2.1 Declare and use one-dimensional (1D) and two-dimensional (2D) arrays
●​ 8.2.2 Understand the use of arrays
●​ 8.2.3 Write values into and read values from an array using iteration
●​ 8.3.1 Understand the purpose of storing data in a file to be used by a program
●​ 8.3.2 Open, close and use a file for reading and writing
Chapter 9:
●​ 9.1 Define a single-table database from given data storage requirements
●​ 9.2 Suggest suitable basic data types
●​ 9.3 Understand the purpose of a primary key and identify a suitable primary key
for a given database table
●​ 9.4 Read, understand and complete structured query language (SQL) scripts to
query data stored in a single database table
Chapter 10:
●​ 10.1 Identify and use the standard symbols for logic gates
●​ 10.2 Define and understand the functions of the logic gates
●​ 10.3 (there are too many scenarios so I will take logic expressions since it is a
good middle ground for all)
○​ (a) Use logic gates to create given logic circuits from a:
■​ (i) problem statement
■​ (ii) logic expression
■​ (iii) truth table
○​ (b) Complete a truth table from a:
■​ (i) problem statement
■​ (ii) logic expression
■​ (iii) logic circuit
○​ (c) Write a logic expression from a:
■​ (i) problem statement
■​ (ii) logic circuit
■​ (iii) truth table
7.1

Program Development Life Cycle (PDLC):


Important note: PDLC is a cycle (meaning it can go back to the start again for
extension) of a program's life.​

Analysis:​
Abstraction – This is the process of getting to the key elements of the problems,
discarding unnecessary information that is not useful for you as a developer.​

Mark scheme description:


●​ Simplifying the problem
●​ Removing unnecessary details from the problem // selecting elements required
●​ Filtering out irrelevant characteristics from those elements

For example, the given scenario is​


"My birthday party is on January 1st, the guests will have to sign up through a website,
inputting their names, age and email. The information of guests will be stored using
MongoDB as the database. This event is very special to me, as most of my school
friends are coming!"​

What we got from abstraction:


●​ Event type: birthday party
●​ Sign up through a website
○​ With names, age and email
●​ MongoDB database

As you can see, we have simplified that chunky paragraph into important details to
work with as a programmer.

Decomposition:
●​ Definition: The process of breaking down the problem, which can be divided
again into smaller parts. This is done to make the problem easier to solve.

Using the same example, this is what we got from decomposition:


●​ Frontend (signup)
○​ Text input
●​ Backend/storage
○​ MongoDB
7.2

Design:​
Structure Diagram – This directly shows the process of decomposition. It has a
hierarchical structure, from the top system to further subsystems.​

Easy formula™
●​ Big system: just give the name of the overall system from the question
(improvise if not explicitly given)
●​ Sub system: typically either input, output, processes and storage; pick one of
those and apply a bit
●​ Further subsystems: name the actual method used to
input/output/process/store (if cie is mean, they might even subdivide further than
this so improvise)​

Example:​

[4]

There is no "perfect" way to make a structure diagram, so examiners are quite lenient
with this – the vagueness of this mark scheme shows it all:
●​ One mark for a hierarchical structure.
●​ One mark for suitable names for the sub-systems.
●​ One mark for identifiable inputs.
●​ One mark for identifiable outputs.
Flowchart – series of flowchart symbols connected by flowlines, forming a
step-by-step idea of an algorithm

Syllabus description of each flowchart symbol:​

Example diagram (contains all symbol):


Pseudocode:
People have developed revision tools way better than me.
●​ Rud's guide – pseudocode + python syntax (reference this when reading chapter
8 notes)
●​ PseudocodePro's resources
○​ Pseudocode interpreter
○​ 15 marker playlist
○​ Entire pseudocode syllabus
●​ Unsigned integer's igcsekit

Coding:
Development of actually used program, done in real programming languages

Testing:
Providing the code with different [combinations of] inputs to check if it's working
properly, then accepting and rejecting appropriate values. 7.6 Suggest and apply
suitable test data​
7.3

Explain the purpose of a given algorithm:


How?
There is no "way" to solve this, only things I can give is

Tips:
●​ Questions typically involve the standard methods of solutions
●​ Try to include key details because that's all the mark schemes care about (e.g.
bubble sorting in ascending order)
7.4

Standard Method of Solution:


Linear search
A linear search is a search algorithm to check if data exists in an array. Imagine it like
having a card in hand and flipping over each card of the deck, one by one, to see if it
matches.

Example code – search to check if Number is in Arr[1:50]

Code:
1 FOR Count ← 1 TO 50
2 IF Number = Arr[Count] THEN
3 OUTPUT "Number found"
4 ENDIF
5 NEXT Count

This programs starts with a for loop for length of array and uses count to change index
of array and compares it with number if it matches it outputs found
Bubble sort
Bubble sort is a sorting algorithm, whether for alphabetical order or numerical values.
This works by going through rounds of the array, seeing if one element is greater than
the next.

Explanation video by me :D
Bubble Sort (Optimisations) | 0478 IGCSE Computer Science
Disclaimer – code here uses Arr[1:5] for simplicity, while the other pieces of code
below uses Arr[1:50]

Example code – Sorting an array: Arr[1:50] that is filled with integers

Version 1: Unoptimised
1 DECLARE Temp : INTEGER
2
3 FOR OuterCount ← 1 TO (50-1)
4 FOR Count ← 1 TO (50-1)
5 IF Arr[Count] > Arr[Count+1] THEN
6 Temp ← Arr[Count]​
7 Arr[Count] ← Arr[Count+1]​
8 Arr[Count+1] ← Temp​
9 ENDIF
10 NEXT Count​
11 NEXT OuterCount

Important notes:
●​ Outer loop: we are looping through the array, to go through swapping 49 times
●​ First 50-1 because, worst case possible, if 50th position has to go to the first
position, it will take 49 swaps
●​ Second 50-1 because we will be accessing the Count+1 index later, which 51
doesn't work, and 49 can already swap with 50
●​ Using Temp variable to swap between card n and n+1 because setting n+1 back
to n will just set n+1 to itself

Next versions are optimisations, increasing difficulty (although concepts should not be
too hard to grasp on)

Version 2: Swap and IndexPassed optimisation


1 DECLARE Temp, IndexPassed : INTEGER
2 DECLARE Swap : BOOLEAN
3
4 IndexPassed ← 0
5 REPEAT
6 Swap ← FALSE
7 FOR Count ← 1 TO 49 - IndexPassed
8 IF Arr[Count] > Arr[Count+1] THEN
9 Temp ← Arr[Count]​
10 Arr[Count] ← Arr[Count+1]​
11 Arr[Count+1] ← Temp
12 Swap ← TRUE​
13 ENDIF
14 NEXT Count​
15 IndexPassed ← IndexPassed + 1​
16 UNTIL NOT Swap

Important notes:
●​ Instead of using an outer for loop and taking the disadvantage of looping 49
times to handle the worse case scenario, you can do the outer loop until there is
no Swaps left (the array has been sorted)
●​ IndexPassed is used to lower the amount of iterations in the inner loop
●​ This works because
○​ with the nature of bubble sort, the highest value will be moved to the last
index by the end of the 1st pass, then the 2nd highest by the end of the 2nd
pass, and so on. This means we can ignore the last [IndexPassed]
values as it is already sorted.

Counting, Totalling, Finding an average (mean), maximum and minimum


●​ Counting is the act of keeping a track of the number of iterations done in a loop.
●​ Totalling is the act of summing values, typically done in loops.
●​ Finding an average is typically the act of finding a mean.
●​ Maximum value – the highest value in an array (can be in number values, or
alphabetical order)
●​ Minimum value – the lowest value in an array (same applies)

Example – a program that takes in prices until stopped, outputting the total, numbers
count and average
1 DECLARE Price, Minimum, Maximum, Price, Count, Total : INTEGER
2 DECLARE Average: REAL
3
4 Total ← 0
5 Count ← 0
6 Maximum ← -99999
7 Minimum ← 99999
8
9 REPEAT
10 OUTPUT "Enter a price, (-1 to quit):"
11 INPUT Number
12 IF Number <> -1 THEN
13 Total ← Total + Number
14 Count ← Count + 1
15 IF Number > Maximum THEN
16 Maximum ← Number
17 ENDIF
18 IF Number < Minimum THEN
19 Minimum ← Number
20 ENDIF
21 ENDIF
22 UNTIL Number = -1
23
24 Average ← Total/Count
25 OUTPUT "Items entered: ", Count
26 OUTPUT "Total: ", Total
27 OUTPUT "Average: ", Average
28 OUTPUT "Cheapest item: ", Minimum
29 OUTPUT "Most expensive item: ", Maximum

Important notes:
●​ Declared the variables Total, Count, Average and Number
●​ Initialised Total to 1 as the last number remove one from the total (last
number is -1 which isn't legitimate)
●​ Initialised Count to to -1 as the last input is not legitimate
●​ REPEAT loop is used to keep on inputting numbers
●​ Total ← Total + Number this is totalling, adding up values to a total
variable
●​ Count ← Count + 1 this is counting, keeping track of the amount of iterations
●​ Average ← Total/Count this is averaging, finding a mean from a total
●​ Maximum ← -99999 – it may seem counterintuitive but we are checking
whether the current value in the list is greater than the maximum, to override it
as a new maximum – the first value would be set as the new maximum. Vice
versa for Minimum
7.5 (a)

Validation checks
Mark scheme description (Describe what is meant by data validation):
●​ Validation is an automated check carried out by a computer
●​ … to make sure the data entered is sensible/acceptable/reasonable
(I would also say suitable could also be in the last one)

Validation checks in the syllabus:


●​ Range check
○​ A specified range of numbers from X to Y (inclusivity depends on the
code/question)
●​ Length check
○​ Retrieving the length of input, comparing it to a pre-set number (i.e.
making sure the input is a certain length)
●​ Type check
○​ Checking the input is a specific data type (e.g. string, integer, real)
●​ Presence check
○​ Checking the input is not empty
●​ Format check
○​ Checking the input is in some specific format (e.g. begins with "AA")
●​ Check digit
○​ Using a predetermined algorithm (you don't need to know any), with the
other digits, to come up with a specific digit before hand, then checking
that digit matches when entered (with recalculation)
7.5 (b)

Verification checks
Mark scheme description (Explain why verification checks are used
when data is input):
●​ To ensure that data has been accurately copied // to ensure that changes have
not been made to the values originally intended when data is copied
●​ … from one source to another
→ to put it simply, making sure no typo/mistake occurred

Verification checks in the syllabus:


●​ Visual check
○​ Make the user re-check their entry by observation
●​ Double entry check
○​ Making the user re-enter their entry, a common example would be the
password repeat
7.6

Suggest and apply suitable test data


The purpose of test data:
This question isn't even in the syllabus, but it was on an exam paper (P22/F/M/23),
mark scheme points:
●​ Check that the program works as expected
●​ Check for logic/runtime errors
●​ Check that the program rejects any invalid data that is input
●​ Check that the program only accepts reasonable data

Examples are with the situation: program accepts integers between 1-10 inclusive
●​ Normal – data that the program should accept.
○​ 2, 4, 8, etc.
●​ Abnormal – data that the program should not accept.
○​ "ABC", 976, -4174
●​ Extreme – data that is at the edge of what is allowed
○​ 1, 10
●​ Boundary – largest/smallest acceptable value and the corresponding
smallest/largest rejected value (i.e. testing the edge)
○​ [0 AND 1], [10 AND 11]
7.7

Trace tables:
Quick definition (you don't need it):
A table to trace the value of variables, outputs and inputs. Each row cell identifies the
value columns (e.g. variable name, input('s variable name), OUTPUT).
Exam question:
Answer:

Easy formula™
●​ Most of the times you get 1 mark automatically for initialisation of variables (like
shown in the first row)
●​ They will mostly be loops, just write the corresponding values for each iteration
(this whole concept should be intuitive enough)
●​ The table will always have too much/extra space, so something might've gone
wrong if you used all
●​ -1 is usually a value that stops the algorithm, watch out for that
7.8

Identify errors in given algorithms and suggest


ways of correcting these errors
Exam question:
Answer:
One mark for each error identified and correction
• Line 05 OUTPUT should be INPUT
• Line 06 OR should be AND
• Line 10 NEXT should be ENDIF

Tips:
●​ Identify syntax errors
●​ Values are also often wrong, so check that (e.g. for validation, comparison,
initialisation)
●​ Nonetheless, these are quite intuitive, it's not really a specification point that you
"revise" for
●​ Just learning pseudocode would be better
7.9

Write and amend algorithms for given problems


or scenarios, using: pseudocode, program code
and flowcharts
Exam questions (because it's intuitive enough):
This one is from the same question as above

Answer:
●​ One mark for checking for < 0 or >= 0
●​ One mark for checking of both inputs
●​ One mark for correct repetition of both inputs e.g. use of REPEAT WHILE or
using existing loop, in separate loops or both in a single loop

For example:
1 REPEAT
2 OUTPUT "Enter cost price "
3 INPUT Cost
4 UNTIL Cost >= 0
5 REPEAT
6 OUTPUT "Enter selling price "
7 INPUT Sell
8 UNTIL Sell >= 0

This type of pseudocode question is the only common "amend" question. Other
questions can just be practised within the flowchart and programming topic.
Disclaimer for chapter 8

Disclaimer for chapter 8


Where is all the code? People have made such great tools to learn programming for
(and not only for) this syllabus. I think referencing other resources would be better.
This means that the notes I make will mostly contain the "theory"/understanding
parts of chapter 8, for syntax you can mostly view rud's guide, and other resources.
8.1.1

Declare and use variables and constants


Quick explanation
●​ Constants are basically variables but you initialise them once and you can't
change them
●​ Why does it even exist? Two reasons
○​ You might think you might as well just write the same value every time –
the value may be hard to write/remember, e.g. π, e, specific codes
○​ Symbolises to a programmer that this value should NEVER change –
because if it does, it might break things

Exam question on the usage difference of variable and constants:

[3]

Mark scheme:
One mark for each point max three
●​ Variables / constants are used to store items of data
●​ The data stored in variables / constants are accessed by an identifier // named
data stores
●​ The value of a variable may change during the execution of a program
●​ The value of a constant will remain the same during the execution of a program
8.1.2

Understand and use the basic data types


What are data types?
These are types of data that a variable/constant could be. Typically, for variables,
languages strictly limit variables to 1 data type.

All data types (specific to pseudocode)


●​ Integer
○​ A mathematical integer ∈ ℤ, number that is not fractional (e.g. -5, 0, 99)
●​ Real
○​ A rational number, expressed with a decimal point (e.g. -5.5, 0.0, 124.25)
●​ Char
○​ A single character (e.g. 'A', 'z', '0', '!', ' ' (space is a valid character))
●​ String
○​ A group of concatenated (joined) characters (e.g. "Hello World", "Puppy is
very cool")
●​ Boolean
○​ Two valid states, TRUE or FALSE

When seamlessly possible, use the simpler data type – integer instead of reals for
integers and char instead of string for single characters
8.1.3

Understand and use input and output


What are inputs?
Inputs are the entry of data by the user, typically done by text through the
console/shell into the program, from a given (outputted) prompt by a program.

Important note about inputs – in pseudocode, INPUT automatically converts the input
into the data type (e.g. INTEGER, CHAR) the variable is declared in. Whereas in most
real programming languages, the input function will return a string value.

What are outputs?


Outputs are the return of data by the program, also typically done through text
through the console/shell.

8.1.4 (a)

Understand and use the concept of sequence


Quick explanation of "sequence"
Code has to be written in order statement by statement, to be executed in that order,
not really that much of a "concept" – just letting us know that we can't just place code
in random places and expect it to work.

Mark scheme description


A set of statements to be executed in order, one line after another
8.1.4 (b)

Understand and use the concept of selection


Quick explanation of "selection"
Different input combinations lead to different "trail of paths" of a program.
E.g. a drink dispenser would dispense different ingredients depending on what drink
you want

Mark scheme description


●​ Branching off to take a course of action depending on the answer to a question.
The word "question" came up in mark schemes twice, idk why but they like it so much
(so use it).

This is done using


●​ IF statements
●​ ELSE statements
●​ CASE statements
8.1.4 (c)

Understand and use the concept of iteration


Quick explanation of "iteration"
It's basically a cool feature to repeat/loop the same lines of code, which means:
●​ You don't have to write it many times
●​ The code becomes more readable

Mark scheme description


●​ Carrying out a set of actions multiple times using a loop structure

This is done using (pseudocode)


●​ Count-controlled loops – FOR (… TO … [STEP] … NEXT) loop
○​ Set amount of iteration
●​ Pre-condition loops – WHILE (… DO … ENDWHILE) loop
○​ Checking a condition before each iteration (TRUE → stay, FALSE → leave)
●​ Post-condition loops – (REPEAT … UNTIL) loop (uncommon in other languages)
○​ Checking a condition is met after each iteration (TRUE → leave, TRUE →
stay)
8.1.4 (d)

Understand and use the concepts of totalling and


counting
Code already shown:
7.4 Standard method of solutions

To explain more in words/examples:


●​ Counting is used in iteration – most of the time when you are looping, you would
likely have to keep track of how many iterations you have done, as one iteration
should probably do something unique to another
●​ Totalling is also used in iteration – you may want to sum up a restaurant bill, etc.
8.1.4 (e)

Understand and use the concept of string


handling
What is the need for string handling?
●​ Let's say you have a book code of PUP0125AB, where the PUP represents the
library ID, the book ID, and the category ID. I would like to separate it into three
variables
●​ What do we have to do?
○​ Validate that the book code has 9 characters
○​ Convert all characters to uppercase
○​ Substring the code into variables

Code:
1 DECLARE BookCode, LibraryID, BookID, CategoryID : STRING
2
3 OUTPUT "Enter book code"
4 INPUT BookCode
5 IF LENGTH(BookCode) = 9 THEN
6 BookCode ← UCASE(BookCode)
7 LibraryID ← SUBSTRING(BookCode, 1, 3)
8 BookID ← SUBSTRING(BookCode, 4, 4)
9 CategoryID ← SUBSTRING(BookCode, 8, 2)
10 // do more stuff here
11 ELSE
12 OUTPUT "Invalid book code"
13 ENDIF

String handling library routines to know:


●​ LENGTH(<identifier>)
○​ Returns the length of the string
●​ SUBSTRING(<identifier>, <start index>, <length>)
○​ Returns the part of the string starting from <start index> with
<length> length
●​ UCASE(<identifier>)
○​ Returns the string in all uppercase
●​ LCASE(<identifier>)
○​ Returns the string in all lowercase
8.1.4 (f)

Understand and use arithmetic, logical and


Boolean operators
Arithmetic operators:

+ - / * ^ MOD DIV
Add Subtract Divide Multiply Raise power Modulus Integer division

What is MOD and DIV?


As you can see
●​ MOD takes the remainder, discarding the quotient
●​ DIV takes the quotient (result of division) discarding the remainder

Logical operators:
●​ =, <, <=, >, >= and <>
○​ Equals to, less than, greater than, less than or equal to, greater than or
equal to, not equals to

Boolean operators:
●​ AND, OR and NOT
○​ NEVER use any other gates in programming – they typically do not exist
in languages
○​ Covered in chapter 10
8.1.5

Understand and use nested statements


Example: nesting selection:
1 DECLARE Age : INTEGER
2
3 OUTPUT "How old are you?"​
4 INPUT Age
5
6 // Based on the UK (may not be 100% accurate)
7 IF Age >= 16 THEN
8 OUTPUT "You can play the National Lottery"
9 IF Age >= 18 THEN
10 OUTPUT "You can vote"
11 ENDIF
12 ELSE
13 OUTPUT "You can't really do much"
14 ENDIF

Important notes:
●​ If their age is 16 or above, they will get into the IF statement
○​ If they are 18 or above, they will get into the second IF statement too
○​ This is useful because if they are 16 or 17, it will say they are able to play
the lottery but they won't get the message of being able to vote
○​ But if they are 18 or older, they will get both messages
●​ If their age is under 16, they will get sent into the ELSE statement being told
they can't really do much
8.1.6 (a)

Understand what is meant by procedures,


functions and parameters
Check
Procedures
●​ They take in parameters/arguments, which are like inputs (don't use the word
input) from the main program, which the procedure/function (both have
parameters) can access those values
●​ They can perform actions like normal, e.g. OUTPUT
●​ They can NOT return a value to the main program
●​ Uses a CALL statement

Functions
●​ (If it helps, you can think of them like mathematical functions as they are very
similar)
●​ Same to procedures
●​ But CAN return – with the specified data type
●​ But also DOESN'T use a CALL statement
○​ As the syllabus puts it – The keyword CALL should NOT be used when
calling a function. Functions should only be called as part of an
expression
Handy gif of how returns work (I made it :D)

(inspired by python discord's gif so access that if you want the python version)

Also look at how that parameter of 7 is passed into the function – that is how
parameters work. Note that any expression that can be evaluated (aka. calculated) into
the same data type can be put there too – i.e. you can put variables and stuff in there
too!

Exam question:

[4]

Mark scheme points


●​ Procedures, max three
○​ To enable the programmer to write a collection of programming
statements under a single identifier
○​ To allow modular programs to be created // to allow procedures to be
re-used within the program or in other programs
○​ To make program creation faster because procedures can be re-used to
enable different programmers to work on different procedures in the
same project
○​ To make programs shorter (than using the repeated code) / using less
duplication of code // to make programs easier to maintain due to being
shorter
●​ Parameters, max three
○​ To pass values from the main program to a procedure / function
■​ …so that they can be used in the procedure / function
○​ Allow the procedure / function to be re-used with different data.
8.1.6 (b)

Define and use procedures and functions, with or


without parameters
Read the README
So you can look at syntax here rud's guide
8.1.6 (c)

Understand and use local and global variables


What are they?
●​ In programming, there is something known as a scope of a variable. It's a range
of places in the code where the variable can be used after it is
declared/initialised
●​ Local variables have a limited scope of the "level" where it is defined, i.e. if it is in
a subroutine (procedures/functions), then you can only access the variable in
subroutine
●​ Whereas global variables are defined in the main program, outside any
subroutine. This means that they can be accessed anywhere in the program

Let's use an example:


Notice how the Result variable, in line 4, is assigned within the function. This means
if you were to use OUTPUT Result instead, it would throw an error because the
variable is assigned locally in the function.
8.1.7

Understand and use library routines


MOD and DIV

ROUND and RANDOM


●​ ROUND(<identifier>, <places>)
○​ Returns a value of that variable rounded to <places> decimal places
●​ RANDOM()
○​ Returns a REAL from 0 to 1 inclusive
8.1.8

Understand how to create a maintainable


program
As for the maintainability of the whole program, the mark scheme points will do the
explanations
Exam question:

[6]

Mark scheme:
One mark for each technique
One mark for a matching description
Max six
●​ Use comments
○​ to explain the purpose of each section of code
○​ for example, logic / syntax
●​ Use meaningful identifier names to
○​ clearly identify the purpose
○​ of variables, constants, arrays, procedures etc
○​ by example
●​ Use procedures and functions
○​ to avoid repeated code
○​ simplify logic
●​ Use indentation and white space …
○​ to make the program readable
8.2.1

Declare and use one-dimensional (1D) and


two-dimensional (2D) arrays
Syntax?
Read the disclaimer so you can look at syntax here rud's guide
8.2.2

Understand the use of arrays


Concept of 1D and 2D arrays
How do we input marks of 20 students without making 20 variables? Well we can use
1D arrays.
1 DECLARE StudentMarks : ARRAY[1:20] OF INTEGER
2 FOR StudentNo ← 1 TO 20
3 OUTPUT "Enter marks of student no. ", StudentNo
4 INPUT StudentMarks[StudentNo]
5 NEXT StudentNo

Now what if each student takes more than one subject? Well instead of making a 1D
array for each subject, we can use 2D arrays.
1 DECLARE StudentMarks : ARRAY[1:20, 1:10] OF INTEGER
2 FOR StudentNo ← 1 TO 20
3 FOR SubjectNo ← 1 TO 10
4 OUTPUT "Enter marks of student no. ", StudentNo
5 OUTPUT "For subject no. ", SubjectNo
6 INPUT StudentMarks[StudentNo, SubjectNo]
7 NEXT SubjectNo
8 NEXT StudentNo

Main points
●​ Arrays are used to store a collection of values, instead of making too many
variables
●​ 1D arrays store values one by one, for a limited length
●​ 2D arrays are more like a table/grid, having rows and columns of where values
can be inserted into
8.2.3

Write values into and read values from an array


using iteration
Writing values
●​ Using INPUT
○​ INPUT ArrayName[Index] for 1D
○​ INPUT ArrayName[Row, Column] for 2D
●​ Using assignment
○​ ArrayName[Index] ← Expression for 1D
○​ ArrayName[Row, Column] ← Expression for 2D

Reading values
You can reference the array by
●​ ArrayName[Index] for 1D
●​ ArrayName[Row, Column] for 2D
Treat it like a normal variable.
8.3.1

Understand the purpose of storing data in a file


to be used by a program
Exam question:

[2]

Answer:
One mark for each point (max two)
●​ Data is stored permanently
●​ Data can be moved to another computer
●​ Another copy of data can be made and stored//accessed elsewhere // backup
copy

To put it simply, you would want to store data in files because you want to keep the
data when you're done using the program and allow other software to access the files
(so then you can move it to another computer, make a backup, etc.).
8.3.2

Open, close and use a file for reading and writing


Only exam question with file handling so far (P23/M/J/23):

Answer:
One mark per mark point, max five
●​ MP1 input a string into Saying
●​ MP2 correct use of OPENFILE to write data
●​ MP3 correct use of WRITEFILE to write Saying
●​ MP4 correct use of CLOSEFILE
●​ MP5 correct use of filename "Quotations.txt" throughout

Example:
1 OUTPUT "Enter the saying"
2 INPUT Saying
3 OPENFILE "Quotations.txt" FOR WRITE
4 WRITEFILE "Quotations.txt", Saying
5 CLOSEFILE "Quotations.txt"

VERY important note regarding file handling:


●​ The syllabus uses this WRONG example for file handling:​

●​ The file names doesn't have double quotes surrounding it, but then in the mark
scheme earlier, they used "Quotations.txt" with double quotes
●​ After contacting an examiner, they said WITH DOUBLE QUOTES is correct, and
the syllabus is wrong – however, they WILL ALLOW BOTH until syllabus is
corrected
●​ (Syllabus hasn't been corrected yet so they are allowing both)
9.1

Define a single-table database from given data


storage requirements
The notes of this specification point says
Including:
●​ Fields
●​ Records
●​ Validation

There hasn't been a single paper that actually makes you create a single-table
database at all.
All you have to know is records are rows (one data entry) and fields are columns. Only
form of "validation" that is in any paper includes knowing the suitable data type for a
field (which is in the next point anyways).
9.2

Suggest suitable basic data types


Data types in the syllabus:
●​ Text/alphanumeric
○​ Text is like a string, being able to store any group of characters (e.g.
"Puppy is very cool"). Whereas alphanumeric only supports the English
alphabet and numbers (e.g. "AB1234"). This difference is VERY
important
●​ Character
○​ A single character (e.g. 'A', 'z')
●​ Boolean
○​ Two valid states, it can be [TRUE or FALSE], [Yes or No] or whatever field
that only needs 2 states. You must stick with whatever the question uses
○​ Furthermore, questions may deceive you with values that look like other
data types. This is an exam question as an example for gender of horses​
The mark scheme says it's boolean, even if it looks like a character
●​ Integer
○​ A number that is not fractional (e.g. -5, 0, 99)
●​ Real
○​ A rational number, expressed with a decimal point (e.g. -5.5, 0.0, 124.25)
●​ Date/time
○​ Date: (e.g. 01/01/2025)
○​ Time: (e.g. 16:00)
○​ These are often interchangeable in mark schemes
9.3

Understand the purpose of a primary key and


identify a suitable primary key for a given
database table
What's the need for a primary key?
Let's say you open a taco shop, you have 3 customers – John Doe, Sarah Johnson and
John Davis. You want to keep track of who orders what

Name Tacos Burritos Quesadillas

John D 2 0 1

Sarah J 3 5 2

John D 1 2 4
Do you see the problem? We have two John D's – how would a program know which
John ordered which food? How would the program individually cater food to their
preferences?

Here comes the solution – we need some identification, which is why a CustomerID
might feel right to you. That same CustomerID is what we call a primary key.

CustomerID Name Tacos Burritos Quesadillas

TC0001 John D 2 0 1

TC0002 Sarah J 3 5 2

TC0003 John D 1 2 4

A bit easier now isn't it?

Now the mark scheme points


●​ The primary key field must be unique/different for each record in the table
○​ If it asks the characteristics of a primary key
●​ (Because) it uniquely identifies a record/item/whatever the case study is
○​ If it asks the purpose of a primary key
9.4

9.4 Read, understand and complete structured


query language (SQL) scripts to query data stored
in a single database table
Basic SQL statements
SQL scripts are a way to query (search) data in a database (all you need to know is
how to do it for a single table). Let's say you have a library's database with multiple
tables. The tables are DogBooks, CompBooks, CatBooks.

As mentioned earlier, we will deal with one table (of books about dogs):
Table name: DogBooks
BookNo Name Description New StockLeft
PUP001 Pomeranians All about these fluffs FALSE 102

PUP002 Golden Retrievers Your best companion TRUE 192

PUP003 Shiba Inu Coolest dogs ever TRUE 374

PUP004 Beagles Cute and playful FALSE 142

We are going to search for the name and description of each book. Using the SELECT
statement, we can choose the fields we want like: SELECT Name, Description
(everything is case sensitive, write these "command words" (e.g. SELECT) in full upper
case. Furthermore, you can do SELECT * to choose all fields.

FROM DogBooks – we don't want to mix search up with cat books.


Now maybe we only want to query for New books. That's where the WHERE clause
comes in, it's basically like an IF statement, you can specify a criteria/condition for your
query. However, note that when comparing text/alphanumeric to a literal, use double
quotes (e.g. "Puppy"), Whereas when comparing a character to a literal, use single
quotes (e.g. 'P').

That becomes
SELECT Name, Description
FROM DogBooks
WHERE New
Just like an IF statement, the condition would already be a TRUE boolean so we don't
have to check if New = TRUE

Output:
Name Description

Golden Retrievers Your best companion

Shiba Inu Coolest dogs ever


These two are left because these are the only new dog books

Now what if you are the librarian, and you want to sort your library by rearranging
these books into alphabetical order? Well you can use the ORDER BY keyword,
specifying the field(s) – it will rearrange the records in the order of that field's values.
This means all the corresponding values within the row will also follow the movement
of that value. You can use ASC or DESC to specify whether it is the ascending or
descending order (by default it is already ASC). If multiple fields are specified, then it
takes left to right priority (e.g. ORDER BY FirstName, LastName)

Sorting books in the alphabetical order:


SELECT Name, Description
FROM DogBooks
ORDER BY Name

Output:
Name Description

Beagles Cute and playful

Golden Retrievers Your best companion

Pomeranians All about these fluffs

Shiba Inu Coolest dogs ever

Maybe you want to see the most available books:


SELECT Name, Description, StockLeft
FROM DogBooks
ORDER BY StockLeft DESC

Output:

Name Description StockLeft

Shiba Inu Coolest dogs ever 374

Golden Retrievers Your best companion 192

Beagles Cute and playful 142

Pomeranians All about these fluffs 102

Now what if we want to see how many books there are in total? Well we can use the
SUM function, selecting which field we want to SUM numbers up – in this case, it would
be StockLeft

This means
SELECT SUM(StockLeft)
FROM DogBooks

Output:
810

Lastly, what if the number of dog books was way bigger, and you want to count the
number of new books that just came into the library? Well you can use the COUNT
function to count the number of records in the table with the specified conditions.
Normally, you would just use COUNT(*), to count the number of records. Otherwise, it
would ignore empty values in those specific fields.

Counting the new books:


SELECT COUNT(*)
FROM DogBooks
WHERE New

Output:
2
(still 2 as we haven't updated the original table)

Summary:
●​ SELECT statement
○​ To choose the field(s) or a function to display
●​ FROM clause
○​ To choose the table in the database (IGCSE you will only have
single-table databases, and the table name will be on the top of the
question most of the time)
●​ WHERE clause
○​ To specify the conditions of the query
●​ ORDER BY keyword
○​ To choose what field to order the query in, and whether it is ASCending or
DESCending
●​ SUM function
○​ To output the sum of all the values of the chosen field
●​ COUNT function
○​ To output the amount of records in the table [that matched the WHERE
clause]

Boolean logic
Truth table
A truth table is a table that shows values of output, corresponding to an input(s),
depending on the condition given. Examples can be seen below for all the different
gates.
10.1

Explanation of all gates


Gate name Description Symbol Truth table

NOT The NOT gate takes in one X = NOT A


input, giving out the
A X
opposite value.
0 1

1 0

AND The AND gate takes in two X = A AND B


inputs, if both of them are 1,
A B X
it gives out 1.
0 0 0

0 1 0

1 0 0

1 1 1
OR The OR gate takes in two X = A OR B
inputs, if either inputs are 1,
A B X
it gives out 1 as output.
0 0 0

0 1 1

1 0 1

1 1 1

NAND The NAND gate takes in two X = A NAND B


inputs, if both inputs are not
A B X
1, it gives out 1 as output
(This is equivalent to NOT(A 0 0 1
AND B)).
0 1 1

1 0 1

1 1 0

NOR The NOR gate takes in two X = A NOR B


inputs, if neither inputs are
A B X
1, it gives out 1 as output
(This is equivalent to NOT(A 0 0 1
OR B)).
0 1 0

1 0 0

1 1 0
XOR The XOR gate takes in two X = A XOR B
inputs, if ONLY one input is
A B X
1, it gives out 1.
Logic symbol: 0 0 0

0 1 1

1 0 1

1 1 0

10.2

Define and understand the functions of the logic gates


●​ Logic gates are elements of a logic expression, taking in one or two input(s),
giving out 1 output.
●​ They are used to control the flow of data, executing the logical operations of
digital circuits (e.g. ALU in the CPU)
●​ (in "why are computer base 2" questions, you can also mention how they take in
two inputs)

Logic circuits
Logic circuits are diagrams which show a logic condition visually, using inputs, outputs,
and gates.

Logic symbols of different gates are shown above.

For example, this is the logic expression


X = (A AND B) OR NOT C​

10.3 (a) (ii)

Exam question - Draw a logic circuit

Easy formula™
●​ Identify all the gates
●​ Draw and connect gates with inputs and outputs
●​ Make sure
○​ Gates only take two inputs (or 1 if it is a NOT gate)
○​ Lines are not too curvy
○​ Examiner can identify what gate you are drawing (e.g. OR gate being too
similar/ambiguous with AND gate)

Answer + working (parts of the answer are labelled):

10.3 (b) (ii)

Exam question - Complete the truth table


Z = (NOT A OR B) AND (B XOR C)

Easy formula™ (for this one, only use if you are uncertain)
●​ Use the working space
●​ Separate each logic gates into different columns, to fill out different rows
●​ After finishing, verify each answer quickly in your head

Answer + working:
A B C D = NOT A E = D OR B F = B XOR C Z = E AND F

0 0 0 1 1 0 0

0 0 1 1 1 1 1

0 1 0 1 1 1 1
0 1 1 1 1 0 0

1 0 0 0 0 0 0

1 0 1 0 0 1 0

1 1 0 0 1 1 1

1 1 1 0 1 0 0

Exam question - Write down the logic expression, from a drawn circuit

Easy formula™
●​ Start from the first two inputs, write down the expression that only requires
those two
●​ After that, see how it interacts with the third input
●​ (This may not work in questions that have very complex circuits with very
different inputs)
Answer + working(in diagram):

X = (NOT A AND B) OR (NOT C)

Mark scheme:

10.3 (c) (iii)

Exam question - write down the logic expression from a given truth
table
●​ As you can see, X is 1 when A, B, C are at certain combinations. If A/B/C is 0, use
a NOT gate. If A/B/C is 1, just write its letter. Then put AND gates in between
because they are at the specific combination.
●​ In the table below, it shows the combinations which make X equal 1

A B C Working

1 0 0 A AND NOT B AND NOT C

1 1 1 A AND B AND C

●​ Then, you put OR gates in between as it can be either of those combinations to


produce X = 1
●​ So, answer: X = (A AND NOT B AND NOT C) OR (A AND B AND C)

You might also like