Computer Science 0478 Practical Notes
Computer Science 0478 Practical Notes
Solving
Program Development Life Cycle (PDLC)
Analysis
Design
Coding
Testing
Maintenance
Analysis
Before solving a problem, it is essential to define and document the problem clearly,
The analysis stage involves using tools like abstraction and decomposition to identify
Abstraction focuses on the essential elements needed for the solution while
Daily tasks can be decomposed into constituent parts for easier understanding and
solving.
Design
The program specification derived from the analysis stage is used as a guide for
program development.
1|Page
During the design stage, the programmer should clearly understand the tasks to be
completed, the methods for performing each task, and how the tasks will work
together.
Iterative testing is performed, which involves conducting modular tests, making code
amendments if necessary, and repeating tests until the module meets the required
functionality.
Testing
The completed program or set of programs is executed multiple times using various
This testing process ensures that all the tasks within the program work together as
Running the program with different test data can identify and address potential
The testing phase aims to verify the overall functionality and performance of the
Structure Diagrams
Every computer system is made up of sub-systems, which are in turn made up of
further sub-systems.
2|Page
Structure Diagrams – The breaking down of a computer system into sub-systems,
then breaking each sub-system into smaller sub-systems until each one only
Algorithm: These steps, together with the order, are called an algorithm
3|Page
An example of a flowchart is given below from a past paper question in which all of
4|Page
This flowchart’s task is to check if a rider’s height is more the 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!
Pseudocode
Declaration & Usage of Variables & Constants
o Variable – Store of data which changes during execution of the program (due to user
input)
o Constant – Store of data that remains the same during the execution of the program
5|Page
o String – Multiple Characters (Text) e.g. ZNotes; COOL
Input & Output (READ & PRINT) – Used to receive and display data to the user
INPUT Name
// Alternatively //
READ Name
manner
Array: Array is similar to variable but it can store multiple values of same datatype
Conditional Statements:
IF…THEN…ELSE…ENDIF
6|Page
CASE…OF…OTHERWISE…ENDCASE – Multiple
Loop Structures:
7|Page
REPEAT… UNTIL – Will run at least once till condition is satisfied; Verification is
Note: When using conditions in these loop structures and conditional statement, it
1. use of a Boolean variable that can have the value TRUE or FALSE
IF [BOOLEAN VARIABLE]
THEN
OUTCOME
ELSE
OUTCOME
ENDIF
THEN
OUTCOME
ELSE
OUTCOME
ENDIF
8|Page
Standard methods used in algorithm:
Totalling :Totalling means keeping a total that values are added to
Total ← 0
NEXT Counter
standard method.
PassCount ← 0
INPUT Value
THEN
PassCount ← PassCount + 1
ENDIF
NEXT Counter
Maximum, minimum and average : Finding the largest and smallest values in a list
9|Page
THEN
MaximumValue ← Array[Counter]
ENDIF
THEN
MinimumValue ← Array[Counter]
ENDIF
NEXT Counter
// Average//
Total ← 0
NEXT Counter
Linear Search: In a linear search, each item in the list is inspected sequentially until
INPUT Value
Found ← FALSE
Counter ← 0
REPEAT
IF Value = Array[Counter]
THEN
Found ← TRUE
ELSE
Counter ← Counter + 1
ENDIF
10 | P a g e
UNTIL Found OR Counter > NumberOfValues
IF Found
THEN
OUTPUT Value , " found at position " , Counter, " in the list."
ELSE
ENDIF
Bubble Sort: Iteratively compare and swap adjacent elements in a list to sort them.
Start from the first element and continue until the second-to-last element. After each
pass, the last element is in its correct place. However, other elements may still be
unsorted. Repeat the process, excluding the last element, until only one element
First ← 1
Last ← 10
REPEAT
Swap ← FALSE
THEN
Temp ← Array[Index]
Array[Index] ← Array[Index + 1]
Array[Index + 1] ← Temp
Swap ← TRUE
ENDIF
NEXT Index
Last ← Last - 1
11 | P a g e
To ensure the acceptance of reasonable and accurate data inputs, computer
systems must thoroughly examine each data item before accepting it, and this is
Validation
reasonableness of data before accepting it. If the data is invalid, the system should
provide an explanatory message for rejection and allow another chance to enter the
data.
Range check
A range check verifies that a numerical value falls within specified upper and lower
limits.
REPEAT
INPUT Value
THEN
OUTPUT "The student's mark should be in the range", MinimumValue ," to ", MaximumValue
ENDIF
Length check
This can either ensure that data consists of a precise number of characters.
OUTPUT "Please enter your value of ", Limit , " characters "
REPEAT
INPUT Value
THEN
12 | P a g e
OUTPUT "Your value must be exactly" , Limit ," characters, please re-enter "
ENDIF
It can also check if the data entered is a reasonable number of characters or not
REPEAT
INPUT Value
THEN
ENDIF
Type check
A type check verifies that the entered data corresponds to a specific data type.
REPEAT
INPUT Value
THEN
ENDIF
Presence check
A presence check checks to ensure that some data has been entered and the value
REPEAT
INPUT Value
13 | P a g e
IF Value = ""
THEN
ENDIF
Format Check
A format check checks that the characters entered conform to a pre-defined pattern.
Check Digit
A check digit is the final digit included in a code; it is calculated from all the other
digits.
Check digits are used for barcodes, product codes, International Standard Book
Verification
Verification is checking that data has been accurately copied from one source to
another
There are 2 methods to verify data during entry ( there are other methods during
1. Double Entry
The computer system compares both entries and if they differ, an error message is
2. Screen/Visual check
A screen/visual check involves the user manually reviewing the entered data.
After data entry, the system displays the data on the screen and prompts the user to
14 | P a g e
The user can compare the displayed data against a paper document used as an
Test Data
Test data refers to input values used to evaluate and assess the functionality and
It helps identify errors and assess how the program handles different scenarios
Normal Data
Normal data is the test data which accepts values in acceptible range of values of
the program
Normal data should be used to work through the solution to find the actual result(s)
e.g. in a program where only whole number values ranging from 0 to 100 (inclusive)
are accepted, normal test data will be : 23, 54, 64 , 2 and 100
Abnormal Data
Test data that would be rejected by the solution as not suitable, if the solution is
e.g. in a program where only whole number values ranging from 0 to 100 (inclusive)
are accepted, abnormal data will be: -1, 151, 200, 67.2, “Sixty-Two” and -520
Extreme Data
Extreme data are the largest and smallest values that normal data can take
e.g. in a program where only whole number values ranging from 0 to 100 (inclusive)
Boundary Data
This is used to establish where the largest and smallest values occur
15 | P a g e
At each boundary two values are required: one value is accepted and the other value
is rejected.
e.g. in a program where only whole number values ranging from 0 to 100 (inclusive)
are accepted, one example of boundary data will be: 100 and 101. 100 will be
Trace Table
A trace table is utilized to document the outcomes of every step in an algorithm. It is
A trace table is set up with a column for each variable and a column for any output
e.g.
Test data is employed to execute a dry run of the flowchart and document the
Whenever a variable's value changes, the new value is recorded in the respective
Q: The flowchart below inputs the height of children who want to ride on a
rollercoaster. Children under 1.2 metres are rejected. The ride starts when eight
Rider Heigh
Reject OUTPUT
s t
0 0
1 1.4
2 1.3
1 1.1
3 1.3
2 1.0
4 1.5
3 1.2
5 1.3
6 1.4
7 1.3
4 0.9
17 | P a g e
Rider Heigh
Reject OUTPUT
s t
8 1.5 Ready to go 4
Identifying errors:
Trace tables can be used to trace errors in a program. For example, if the
requirement for the previous question would be to accept riders that are of height 1.2
too, rather than rejecting them, then the error would have been caught in the trace
table as when 1.2 is entered, it would increment rejected which it shouldn’t in our
example
Some key steps/points to be known in-order to write the perfect algorithm are
as follows:
1. Make sure that the problem is clearly understood which includes knowing the
2. Break the problem into smaller problems (e.g. in a program which outputs average
values, divide the problem into multiple ones i.e. how to count the number of
3. Identify the data that is needed to be saved into variables/constants/arrays and what
meaningfull names
4. Decide on how you are going to construct your algorithm, either using a flowchart or
pseudocode. If you are told how to construct your algorithm, then follow the
guidance.
18 | P a g e
5. Construct your algorithm, making sure that it can be easily read and understood by
someone else. Take particular care with syntax e.g. when conditions are used for
6. Use several sets of test data (Normal, Abnormal and Boundary) to dry run your
algorithm and check if the expected results are achieved (a trace table can be used
for this purpose) . If error is found, find the point of error in the trace table and fix it in
the code.
Note: The algorithms that you have looked at so far in these notes were not
designed with readability in mind because you needed to work out what the problem
Programming
Programming Languages
19 | P a g e
There are many high-level programming languages to choose from. We will
this chapter is known as Visual Studio, which is utilised for capturing screenshots.
Programming Concepts
Constructs of a Program
Operators use arithmetic for calculations and logic and Boolean for decisions.
A variable within a computer program refers to a named storage unit with a value
A constant within a computer program represents a named storage unit that holds a
20 | P a g e
variables, it is recommended to assign meaningful names to constants to enhance
Data Types
Different data types are assigned to computer systems for effective processing and
storage.
Data types enable effective manipulation using mathematical operators for numbers
In IGCSE Computer Science, algorithms and programs are designed to take input
Prompting the user with clear instructions for input is necessary for the user to
Input data in programming languages must match the required data type of the
By default, inputs are treated as strings, but commands can convert input to integer
Users should be provided with information about the output/results for a program to
be useful.
or significance.
21 | P a g e
If an output statement has multiple parts, they can be separated by a separator
character.
Basic Concepts
When writing the steps required to solve a problem, the following concepts need to
Sequence
Selection
Iteration
String handling
Use of operators.
Sequence
The ordering of the steps in an algorithm is very important. An incorrect order can
lead to incorrect results and/or extra steps that are not required by the task.
Selection
Selection is a very useful technique, allowing different routes through the steps of a
Iteration
String Handling
Strings are used to store text and can contain various characters.
22 | P a g e
An empty string has no characters, while the programming language specifies the
Characters in a string can be identified by their position number, starting from either
In IGCSE Computer Science, you will need to write algorithms and programs for the
LENGTH("Text Here")
LENGTH(Variable)
// returns the next 7 values starting from the 10th value of the string "Computer Science" i.e. "Science"
UCASE("Text here")
UCASE(Variable)
LCASE("Text Here")
23 | P a g e
LCASE(Variable)
Selection and iteration statements can be nested, meaning one statement can be
Nested statements help reduce code duplication and simplify testing of programs.
Different types of constructs can be nested within each other, such as selection
single name, invoked at any given point in a program to execute a specific task.
Unlike a procedure, a function also has the capability to return a value back to the
main program.
procedure or function. While not all procedures and functions require parameters,
PROCEDURE ProcedureName ()
[Commands]
ENDPROCEDURE
CALL ProcedureName()
24 | P a g e
The procedure with parameters:
[Commands]
ENDPROCEDURE
Function:
DataTypeOfValueReturned
[Commands]
RETURN ValueToBeReturned
ENDFUNCTION
When defining procedures and functions, the header is the first statement in the
definition.
o Parameters passed to the procedure or function, along with their data types.
Function calls are made as part of an expression, typically on the right-hand side.
Any part of a program can use a global variable – its scope covers the whole
program
A local variable can only be used by the part of the program it is declared in – its
25 | P a g e
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,
Library Routines
Programming language development systems often provide library routines that can
Library routines are pre-tested and ready for use, making programming tasks easier.
DIV – returns the quotient (i.e. the whole number part) of a division
Examples:
always use meaningful identifier names for variables, constants, arrays, procedures
and functions
be divided into modules for each task using procedures and functions
26 | P a g e
Commenting in pseudocode:
""
""
Arrays
An array is a data structure containing several elements of the same data type; these
The position of each element in an array is identified using the array’s index.
One-Dimensional Array
Two-Dimensional Array
27 | P a g e
When a two-dimensional array
is declared in pseudocode, the first and last index values for rows and the first and
last index values for columns alongside the data type are included.
Declaring a 2D Array:
FOR ColumnCounter ← 0 TO 2
FOR RowCounter ← 0 TO 9
NEXT RowCounter
NEXT ColumnCounter
File Handling
Computer programs store data that will be needed again in a file.
Data stored in RAM is volatile and will be lost when the computer is powered off.
28 | P a g e
The storage of data in files is a commonly used feature in programming.
Key point: When writing in a file, the program is outputing the data to the file,
and when reading a file, the program in inputing the data from the file
\n There are 3 ways a file can be opened in a program i.e. to write, to read and to
append
Writing in a file
OPENFILE "filename.txt" FOR WRITE
//When opening a file to write, all the data already existing in the file is OVERWRITTEN
// The next command of WRITEFILE would be writen on next line of the file
CLOSEFILE "filename.txt"
Reading a file:
OPENFILE "filename.txt" FOR READ
// The value in the line (which is identified by the number of times this is being run) is stored in the
variable
CLOSEFILE "filename.txt"
// here the line can be outputted or stored in an array. This process will repeat until every line
29 | P a g e
ENDWHILE
30 | P a g e
Databases
A database is a well-organized compilation of data that enables individuals to
within a database can encompass various forms such as text, numerical values,
images, or any other type of digital content that can be stored on a computer system.
consistency.
All users access and utilize the same set of data, promoting uniformity.
e.g. cars. These tables HAVE to be named according to what they contain e.g. a
These tables consist of records (rows). Each record consists of data about a single
These tables also have columns that are knows an fields. These consist of specific
information regarding the entities that are written later in records e.g. car name, car
manufacturer etc.
Note: In this chapter, skills of dealing with a database are also required so
better. You have to be able to define a single-table database from given data
storage requirements, choose a suitable primary key for a database table and also
31 | P a g e
Source: Cambridge IGCSE and O Level Computer Science by Hodder Education
Validation in databases
Database management software automatically provides some validation checks,
is stored, displayed and the operations that can be performed on the stored value.
The datatypes for database are quite similar to original datatypes, however, there
Primary Key
Each record in a table represents a unique item, person, or event.
32 | P a g e
To ensure reliable identification of these items, a field called the primary key is
necessary.
The primary key is a unique field that distinguishes each item within the data.
In order to serve as a primary key, a field must have values that are never repeated
An existing field can serve as a primary key if it is unique, such as the ISBN in the
book table.
In cases where all existing fields may contain repeated data, an additional field, such
By using SQL, we can learn how to retrieve and display specific information needed
from a database.
For instance, someone visiting a patient may only require the ward number and bed
number to locate them in the hospital, while a consultant may need a list of the
names of all the patients under their care. This can be done using SQL
SQL Scripts
An SQL script is a collection of SQL commands that are used to perform a specific
To comprehend SQL and interpret the output of an SQL script, practical experience
Select Statements:
SELECT (fieldsname)
FROM (tablesname)
WHERE (condition)
33 | P a g e
ORDER BY (sortingcondition) ;
FROM (tablesname)
WHERE (condition)
ORDER BY (sortingcondition) ;
Counting the number of records where the field matches a specified condition
FROM (tablesname)
WHERE (condition)
ORDER BY (sortingcondition) ;
Operators
Just like pseudocode, the operators used there can also be used here for conditions,
34 | P a g e
35 | P a g e
Boolean Logic
Logic Gates and their functions
Six types of logic gates
NOT Gate
AND Gate
OR Gate
NAND Gate
NOR Gate
XOR Gate
A Output
0 1
1 0
A B Output
0 0 0
0 1 0
1 0 0
1 1 1
OR gate: 𝐴+𝐵A+B
36 | P a g e
A B Output
0 0 0
0 1 1
1 0 1
1 1 1
A B Output
0 0 1
0 1 1
1 0 1
1 1 0
A B Output
0 0 1
0 1 0
1 0 0
1 1 0
XOR gate: A ⨁ B
A B Output
0 0 0
0 1 1
37 | P a g e
A B Output
1 0 1
1 1 0
circuit.
2. Go from the one output that is being given towards the input
3. Write the last gate ( the first gate you walk through ) in the middle and then, for each
of the value coming into the gate, leave space at the side
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
2. Go from the logic of any 2 inputs at the start, and then keep on going until you are
3. When writing the statement, make sure you show the logic statement where the
output is 1
38 | P a g e
Example of a LOGIC STATEMENT
(B AND C) OR (A NOR (A NAND C)) is the logic statement for the following Logic
Circuit
inputs . Tip: For the first input, write it in the combination of 1,0,1,0 and so on.
For the second, go 1,1,0,0 and so on, and for the third one, go 1,1,1,1,0,0,0,0
going by the powers of 2 for each input. This would guarantee each possible
combination
2. Run through the circuit with the inputs and get the output that will be reached and
write it accordingly
Example
This is the example of a truth table of a logic circuit
39 | P a g e
The circuit:
1. Given the truth table above, take the rows where the output (x) is 1 (Rows 1, 2, 4, 5,
6, 7)
2. Create a logic expression from these rows (example, row 1 will be (NOT A AND NOT
B AND NOT C) = X
40 | P a g e
3. Create logic expressions for all the rows with output 1 and connect them with OR
gate
Exam-Style Question
1. The Conditions are given so make logic statements using the conditions and the
41 | P a g e
42 | P a g e