Computer Science: Caie Igcse
Computer Science: Caie Igcse
COMPUTER
SCIENCE
P2
CAIE IGCSE COMPUTER SCIENCE
Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
WWW.ZNOTES.ORG authorised for personal use only by Rafay at Bloomfeild Hall on 23/10/24.
CAIE IGCSE COMPUTER SCIENCE
Pseudocode - Verbal representation of an algorithm (a Declaration & Usage of Variables & Constants
process or set of steps) and owcharts are a Variable – Store of data which changes during
diagrammatic representation. execution of the program (due to user input)
Flowcharts: A owchart shows diagrammatically the Constant – Store of data that remains the same
steps required to complete a task and the order that during the execution of the program
they are to be performed Basic Data Types
Algorithm: These steps, together with the order, are Integer – Whole Number e.g. 2; 8; 100
called an algorithm Real – Decimal Number e.g. 7.00; 5.64
Char – Single Character e.g. a; Y
String – Multiple Characters (Text) e.g. ZNotes; COOL
Boolean – Only 2 Values e.g. True/False; Yes/No; 0/1
Input & Output (READ & PRINT) – Used to receive and
display data to the user respectively. (Itisrecommended
touseinputandoutputcommands)
INPUT Name
OUTPUT "Hello Mr." , Name
// Alternatively //
READ Name
PRINT "Hello Mr," , Name
An example of a owchart is given below from a past paper
question in which all of the functions of a owchart are Declaration of variable - A variable/constant can be
shown: declared by the following manner
Conditional Statements:
This owchart’s task is to check if a rider’s height is more the
IF…THEN…ELSE…ENDIF
requirement (1.2) in this case. It then counts until the
accepted riders are 8. After they are 8, it outputs the
number of rejected riders and tells the rest that they are
ready to go!
2. Pseudocode
Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
WWW.ZNOTES.ORG authorised for personal use only by Rafay at Bloomfeild Hall on 23/10/24.
CAIE IGCSE COMPUTER SCIENCE
Loop Structures:
IF [BOOLEAN VARIABLE]
THEN
OUTCOME
ELSE
OUTCOME
ENDIF
Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
WWW.ZNOTES.ORG authorised for personal use only by Rafay at Bloomfeild Hall on 23/10/24.
CAIE IGCSE COMPUTER SCIENCE
// Average//
Total ← 0
2.2. Standard methods used in FOR Counter ← 1 TO NumberOfValues
algorithm: Total ← Total + StudentMark[Counter]
NEXT Counter
Totalling :Totalling means keeping a total that values are Average ← Total / NumberOfValues
added to
Linear Search: In a linear search, each item in the list is
Total ← 0 inspected sequentially until a match is found or the
FOR Counter ← 1 TO LoopLimit entire list is traversed.
Total ← Total + ValueToBeTotalled
NEXT Counter
INPUT Value
Counting: Keeping a count of the number of times an Found ← FALSE
action is performed is another standard method. Counter ← 0
REPEAT
PassCount ← 0 IF Value = Array[Counter]
FOR Counter ← 1 TO LoopLimit THEN
INPUT Value
Found ← TRUE
IF Value > Range
ELSE
THEN
Counter ← Counter + 1
PassCount ← PassCount + 1
ENDIF
ENDIF UNTIL Found OR Counter > NumberOfValues
NEXT Counter IF Found
THEN
Maximum, minimum and average : Finding the largest
OUTPUT Value , " found at position " , Counter, "
and smallest values in a list are two standard methods
ELSE
that are frequently found in algorithms
OUTPUT Value , " not found."
ENDIF
Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
WWW.ZNOTES.ORG authorised for personal use only by Rafay at Bloomfeild Hall on 23/10/24.
CAIE IGCSE COMPUTER SCIENCE
Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
WWW.ZNOTES.ORG authorised for personal use only by Rafay at Bloomfeild Hall on 23/10/24.
CAIE IGCSE COMPUTER SCIENCE
5. How to write an algorithm? the data is invalid, the system should provide an explanatory
message for rejection and allow another chance to enter the
data.
The ability to write an algorithm is very important for this \n There are many types of it.
syllabus and paper. Some key steps/points to be known in-
order to write the perfect algorithm are as follows:
Range check
Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
WWW.ZNOTES.ORG authorised for personal use only by Rafay at Bloomfeild Hall on 23/10/24.
CAIE IGCSE COMPUTER SCIENCE
Presence check
A presence check checks to ensure that some data has been 5.2. Programming Concepts
entered and the value has not been left blank Constructs of a Program
Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
WWW.ZNOTES.ORG authorised for personal use only by Rafay at Bloomfeild Hall on 23/10/24.
CAIE IGCSE COMPUTER SCIENCE
Data use – variables, constants and arrays Programs require input and output statements to handle
Sequence – order of steps in a task data.
Selection – choosing a path through a program In IGCSE Computer Science, algorithms and programs
Iteration – repetition of a sequence of steps in a program are designed to take input from a keyboard and output
Operators use arithmetic for calculations and logic and to a screen.
Boolean for decisions. Prompting the user with clear instructions for input is
necessary for the user to understand what is expected.
Variables and Constants Input data in programming languages must match the
required data type of the variable where it will be stored.
A variable within a computer program refers to a named By default, inputs are treated as strings, but commands
storage unit with a value that can be modi ed can convert input to integer or real number data types.
throughout the program's execution. To enhance Users should be provided with information about the
comprehension for others, it is advisable to assign output/results for a program to be useful.
signi cant names to variables. Each output should be accompanied by a message
A constant within a computer program represents a explaining the result's meaning or signi cance.
named storage unit that holds a value which remains If an output statement has multiple parts, they can be
unchanged throughout the program's execution. Similar separated by a separator character.
to variables, it is recommended to assign meaningful
names to constants to enhance comprehensibility for
others. 6. File Handling
Data Types Computer programs store data that will be needed again
in a le.
Di erent data types are assigned to computer systems Data stored in RAM is volatile and will be lost when the
for e ective processing and storage. computer is powered o .
Data types allow data, such as numbers or characters, to Data saved to a le is stored permanently, allowing it to
be stored appropriately. be accessed by the same program at a later date or by
Data types enable e ective manipulation using other programs.
mathematical operators for numbers and character Stored data in a le can be transferred and used on
concatenation. other computers.
Some data types provide automatic validation. The storage of data in les is a commonly used feature in
The types of datatypes are told in Chapter 1 already! programming.
Input and Output Key point: When writing in a le, the program is
outputing the data to the le, and when reading a le,
the program in inputing the data from the le
\n There are 3 ways a le can be opened in a program i.e. to
write, to read and to append
6.1. Writing in a le
Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
WWW.ZNOTES.ORG authorised for personal use only by Rafay at Bloomfeild Hall on 23/10/24.
CAIE IGCSE COMPUTER SCIENCE
OPENFILE "filename.txt" FOR WRITE Value1 <--- MOD(10,3) returns the remainder of 10
divided by 3
//When opening a file to write, all the data already Value2 <---- DIV(10,3) returns the quotient of 10 divided
by 3
Value3 <--- ROUND(6.97354, 2) returns the value
WRITEFILE "filename.txt" , Value rounded to 2 decimal places
Value4 <--- RANDOM() returns a random number
// The next command of WRITEFILE would be writen on between 0 and 1 inclusive
Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
WWW.ZNOTES.ORG authorised for personal use only by Rafay at Bloomfeild Hall on 23/10/24.
CAIE IGCSE COMPUTER SCIENCE
LENGTH("Text Here")
7.2. Basic Concepts
When writing the steps required to solve a problem, the LENGTH(Variable)
following concepts need to be used and understood:
Extracting a substring from a string:
Selection LCASE(Variable)
Selection is a very useful technique, allowing di erent routes Arithmetic, Logical and Boolean Operators
through the steps of a program. The code of this is explained in
the notes of previous chapters. As explained in the previous chapter, we already
As explained in the previous chapter, we already Selection and iteration statements can be nested,
meaning one statement can be placed inside another.
Totalling and Counting Nested statements help reduce code duplication and
simplify testing of programs.
As explained in the previous chapter, we already Di erent types of constructs can be nested within each
other, such as selection statements within condition-
String Handling controlled loops or loops within other loops.
Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
WWW.ZNOTES.ORG authorised for personal use only by Rafay at Bloomfeild Hall on 23/10/24.
CAIE IGCSE COMPUTER SCIENCE
Function:
Any part of a program can use a global variable – its FOR ColumnCounter ← 0 TO 2
scope covers the whole program FOR RowCounter ← 0 TO 9
A local variable can only be used by the part of the OUTPUT "Enter next value "
program it is declared in – its scope is restricted to that INPUT ArrayName [RowCounter, ColumnCounter]
part of the program. NEXT RowCounter
NEXT ColumnCounter
Note: Any variables/arrays made in this procedure and
functions will be local and cannot be used out of these.
To be made available all over the program, they must be 8. Boolean Logic
declared globally in the following way.
DECLARE [VariableName] : DataType AS GLOBAL 8.1. Logic Gates and their functions
Six types of logic gates
7.3. Arrays
NOT Gate
An array is a data structure containing several elements
AND Gate
of the same data type; these elements can be accessed
OR Gate
using the same identi er name.
NAND Gate
The position of each element in an array is identi ed
NOR Gate
using the array’s index.
XOR Gate
There are two types of arrays
A Output
Explained in the previous chapter in detail
0 1
Two-Dimensional Array 1 0
Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
WWW.ZNOTES.ORG authorised for personal use only by Rafay at Bloomfeild Hall on 23/10/24.
CAIE IGCSE COMPUTER SCIENCE
A B Output
0 0 0
0
1
1
0
0
0
9. Writing Logic Statements
1 1 1
Logic Statements is a way of showing all the logics that are in
place for a logic circuit.
OR gate: A +B 1. Look at the ciruit and go around the logic gates used
in the circuit
A B Output
2. Go from the one output that is being given towards
the input
0 0 0
3. Write the last gate ( the rst gate you walk through )
0 1 1
in the middle and then, for each of the value coming
1 0 1
into the gate, leave space at the side
1 1 1
4. If the value coming into the gate is coming from
another gate, use a bracket for the gate’s logic
5. Repeat process 3-4 till you are able to reach the input
values fully
place
2. Go from the logic of any 2 inputs at the start, and
then keep on going until you are able to reach the
NOR gate: A + B nal gate which gives the output
3. When writing the statement, make sure you show the
A B Output logic statement where the output is 1
0 0 1
0 1 0
1 0 0
9.4. Example of a LOGIC STATEMENT
(B AND C) OR (A NOR (A NAND C)) is the logic statement for
1 1 0
the following Logic Circuit
XOR gate: A B
A ⨁B Output
0 0 0
0 1 1
1 0 1
1 1 0
Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
WWW.ZNOTES.ORG authorised for personal use only by Rafay at Bloomfeild Hall on 23/10/24.
CAIE IGCSE COMPUTER SCIENCE
The circuit:
1. The Conditions are given so make logic statements
using the conditions and the table. (NOT S AND T) OR
(S AND W) OR (NOT T AND W)
2. Make the logic circuit from the given equation
3. Make the truth table
13. Databases
A database is a well-organized compilation of data that
enables individuals to retrieve information according to their
speci c requirements. The data contained within a database
11. Logic Statements from can encompass various forms such as text, numerical
values, images, or any other type of digital content that can
Truth Tables be stored on a computer system.
Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
WWW.ZNOTES.ORG authorised for personal use only by Rafay at Bloomfeild Hall on 23/10/24.
CAIE IGCSE COMPUTER SCIENCE
Each eld will require a data type to be selected. A data type
To store data about people, things, and events. classi es how the data is stored, displayed and the
Any modi cations or additions need to be made only operations that can be performed on the stored value.
once, ensuring data consistency. The datatypes for database are quite similar to original
All users access and utilize the same set of data, datatypes, however, there are a few di erences.
promoting uniformity.
Relational databases store data in a non-repetitive
manner, eliminating duplication.
Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
WWW.ZNOTES.ORG authorised for personal use only by Rafay at Bloomfeild Hall on 23/10/24.
CAIE IGCSE COMPUTER SCIENCE
Select Statements:
13.7. Operators
Just like pseudocode, the operators used there can also be
used here for conditions, however, a few more are also used
in databases
Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
WWW.ZNOTES.ORG authorised for personal use only by Rafay at Bloomfeild Hall on 23/10/24.