Comp Science Igcse
Comp Science Igcse
The term is generally accepted to include all aspects of the practice of developing a computer system to
meet a user's requirements.
The Institute of Electrical and Electronics Engineers (IEEE) describes PDLC as "the systematic application
of scientific and technological knowledge, methods, and experience to the design, implementation, testing,
and documentation of software".
PDLC (Program Development Life Cycle)
The following are five steps in the Program Development Life Cycle:
1. Analysis: During this phase, all the relevant information is collected to develop a product as per expectation. This step
is about analyzing the performance of the software at various stages and making notes on additional requirements. The
analysis stage uses abstraction and decomposition tools to identify exactly what is required from the program.
Abstraction is the process of filtering out – ignoring - the characteristics of patterns that
we don't need in order to concentrate on those that we do.
The process instructs us to remove all specific detail, and any patterns that will not help
us solve our problem.
If we don’t abstract we may end up with the wrong solution to the problem
we are trying to solve.
Decomposition :
It involves breaking down a complex problem or system into smaller parts that are more manageable and
easier to understand.
This will help us to simplify complex problems into each step we should analyse.
The smaller parts can then be examined and solved, or designed individually, as they are simpler to work
with.
If you can break down a big problem into smaller problems then you can give them to a computer to solve.
If you can look at a problem and work out the main steps of that problem then you'll stand a much better
chance of solving it.
1. 3.
2.
2. Design: Program design starts by focusing on the main goal that the program is trying to achieve and then breaking
the program into manageable components, each of which contributes to this goal. This approach of program design is
called top-bottom program design or modular programming.
Program Design Tools: Structure Charts, Algorithms, Flowcharts, Decision tables and Pseudocode.
3. Implementation and coding : The actual task of developing the software starts here. Coding the program means
translating an algorithm into specific programming language. Programmer must follow the language rules, violation of
any rule causes error. These errors must be eliminated before going to the next step.
4. Testing: After removal of syntax errors, the program will execute. However, the output of the program may not be
correct. This is because of logical error in the program. The programmer must find and correct logical errors by carefully
examining the program output using Test data. Syntax error and Logical error are collectively known as Bugs. The process
of identifying errors and eliminating them is known as Debugging.
5. Documentation and Maintenance: Once the software passes through all the stages without any issues, the structure
charts, pseudocodes, flowcharts and decision tables developed during the design phase become documentation for
others who are associated with the project. This phase ends by writing a manual that provides an overview of the
program’s functionality, tutorials for the beginner, in-depth explanations of major program features, reference
documentation of all program commands and a thorough description of the error messages generated by the program.
Later it is to undergo a maintenance process wherein it will be maintained and upgraded from time to time to adapt to
changes.
Computational thinking is a set of problem-solving methods that involve expressing problems and their
solutions in ways that a computer system could execute.
A COMPUTER SYSTEM is made up of software, data, hardware, communications and people; each
computer system can be divided up into a set of sub-systems. Each subsystem can be further divided
into sub-systems and so on until each sub-system just performs a single action.
Computational thinking is an approach to problem solving, one that underpins the art of
programming.
It means getting you to think in ways that you can use computers to solve problems.
By decomposing a problem, identifying the variables involved using data representation, and
creating algorithms, a generic solution results.
Computational thinking allows us to take a complex problem, understand what the problem is
and develop possible solutions. We can then present these solutions in a way that a computer,
a human, or both, can understand.
Ex: Finding the shortest route on a map
For example, if you agree to meet your friends somewhere you have never been before, you
would probably plan your route before you step out of your house. You might consider the
routes available and which route is ‘best’ - this might be the route that is the shortest, the
quickest, or the one which goes past your favourite shop on the way.
Top-down design - in which design begins by specifying complex pieces and then dividing them into
successively smaller pieces
A top-down approach (also known as stepwise design) is essentially the breaking down of a system to
gain insight into the sub-systems that make it up.
In a top-down approach an overview of the system is formulated, specifying but not detailing any
first-level subsystems.
Each subsystem is then refined in yet greater detail, sometimes in many additional subsystem levels,
until the entire specification is reduced to base elements.
Once these base elements are recognised then we can build these as computer modules. Once they
are built we can put them together, making the entire system from these individual components.
When large computer systems are being developed this means thatseveral programmers can work
independently to develop and test different subsystems for the same system at the same time. This
reduces the development and testing time.
Structure diagrams / charts
In order to show top-down design in a diagrammatic form, structure diagrams can be
used.
A Structure Chart in software engineering is a chart which shows the breakdown of a system to its
lowest manageable parts.
They are used in structured programming to arrange program modules into a tree. Each module is
represented by a box, which contains the module's name.
The tree structure visualizes the relationships between modules, showing data transfer between
modules using arrows.
Structured Charts are an example of a top-down design where a problem (the program) is broken into
its components.
The tree shows the relationship between modules, showing data transfer between the models.
Alarm app for a smart phone
• What is an algorithm?
Algorithms
• An algorithm is a set of instructions for
solving a problem or completing a task
• The task could be:
• Making a chocolate cake
• Summing the numbers 1 to 1000
• Building a Lego model
This step-by-step program will need planning, and to do this we use an algorithm
Algorithm - a set of instructions independent of any programming language that calculates a function or solves
a problem.
Express the solution to a simple problem as an algorithm using flowcharts, pseudo-code or structured English
and the standard constructs:
• We use “algorithms” every day without even being aware of it
• Have you ever
– Made a cup of tea?
– Followed directions to a destination?
– Taken part in a school play?
Mix
No
No
Stop
Purpose Start
Add flour to
• It is a flowchart for bowl
making bread
Add water
• The flour and water are
mixed together
Mix
• If there is too much flour,
more water is added Yes
Too much
Add water
• If there is too much water, flour?
No
more flour is added
Too much Yes
• Once correct, the dough water?
Add flour
is kneaded No
Start
Flowchart symbols
No
Terminal Input / Output Decision
Ye
s
Start
INPUT Grade
No
Is Count = 10?
Stop OUTPUT Total
Ye
s
Flowchart symbols
Ye
Is this s OUTPUT
ID already in "Choose
use? another ID"
No
Save(ID)
Stop
Counting
Start
• The algorithm shows how it is
possible to count using count 0
a flowchart
• The statement count count + 1 count count + 1
means “Add 1 to the variable called
count”
OUTPUT count
• Explain exactly what the program
will do?
Is count Yes
<
1000?
Is count < No
1000? Stop
Counting
Start
• The program outputs:
• 1 count 0
• 2
count count + 1
• …
• 999
OUTPUT count
Stop
Finding the maximum
• The flowchart shows Start
the algorithm that will
find the maximum of INPUT num1
two numbers
INPUT num2
• Remember when using
a decision symbol that
you must label the different num1 Yes
branches that come out > OUTPUT num1
num2
of it – in this case
“Yes” and “No” No
OUTPUT num2
Stop
Sub programs
• Sub programs are used when you wish to call another procedure or
function
• They use a box
with lines either side Start
findVAT(n)
• In this example,
findVAT is called INPUT total VAT n * 0.2
from the
sub program box total total + Return VAT
• The findVAT sub findVAT(total)
program then runs OUTPUT
and returns the total
answer to where
it was called Stop
total = total + count
Plenary
• What are each of the following symbols?
• Explain to a partner what each one does
Plenary
• What are each of the following symbols?
• Explain to a partner what each one does
Decision –
Input / Output change flow
based on a
Process – Maths decision
operations and
assignment of variables
Sub program –
Line – shows call a different
direction of flow function or
procedure
Terminal – for
start and stop
2. Selection :
1. Sequence : performing or operating each step
Selection is choosing a step
consecutively in the order they arise
If x > 0
then
Print "x is positive“
Else
Print "x equals 0 or less than 0“
End If
3 Repetition : A sequence of steps that loop until a requirement is met
What is the purpose of the following algorithm?
What is the purpose of the following algorithm?
Pseudocode uses a combination of programming terminology and plain English to describe algorithms in a
form that is easier for people to understand than conventional programming language code.
Pseudocode is not an executable program. Pseudo-code is a simple way of describing a set of instructions
in a manner that resembles a programming language.
Psuedocode is used in textbooks and scientific publications to describe various algorithms, and also in
planning of computer program development, for sketching out the structure of the program before the actual
coding takes place. It typically leaves out details that are not essential for human understanding of the
algorithm, such as variable declarations, system-specific code and some subroutines.
Data Type
In computer programming, a data type or simply type is an attribute of data which tells
the compiler or interpreter how the programmer intends to use the data.
• They can only contain letters (A–Z, a–z) and digits (0–9).
• Accented letters and other characters, including the underscore, should not be used.
• You can choose a name for the box (the “variable name”) and change its
contents in your program
Constants : A constant is a type of identifier whose value cannot be changed.
Assignments
Input and output
Arithmetic Operators The integer division operators MOD and DIV
can be used.
The only logic operators (also called relational operators) used are AND, OR and NOT.
The operands and results of these operations are always of data type BOOLEAN.
Relational Operators
The following operators are used to compare two values:
> greater than
>= greater than or equal
< less than
<= less than or equal
= equal (in Python this is written ==)
<> not equal (in Python this is written !=)
Pseudocode constructs
• There are three basic ways of controlling the order in which pseudocode statements
are carried out
• Sequence : The statements are executed in the order they are written
• Selection : The next statement to be executed depends on whether the condition
being tested is true or false
• Iteration
use of a Boolean variable that can have the value
Selection/Conditional TRUE or FALSE
1. IF statements
2. CASE statements
Each case clause is indented by two spaces. They can be seen as continuations of the CASE statement rather than
new statements. Note that the case clauses are tested in sequence. When a case that applies is found, its statement
is executed and the CASE statement is complete. Control is passed to the statement after the ENDCASE. Any
remaining cases are not tested. If present, an OTHERWISE clause must be the last case. Its statement will be executed
if none of the preceding cases apply.
3. Iteration
Iteration means repetition.
There are three types of iteration statement
FOR … END FOR
WHILE … END WHILE
REPEAT … END REPEAT
1. For Loop
2. REPEAT UNTIL Loop
3. WHILE Loop
ARRAYS
• How many variables do we need?
• You could use eight variables. This would work, but there is a better way. It is much simpler to keep all
the related data under one name.
• We do this by using an array.
• Instead of having ten variables, each holding a score, there could be one array that holds all the related
data.
Array is a container which can hold a fix number of items and these items should be of the same type. Most of the data
structures make use of arrays to implement their algorithms.
Following are the important terms to understand the concept of Array.
Naming arrays - Arrays are named like variables. The number in brackets determines how many data items the array can hold.
Index − Each location of an element in an array has a numerical index, which is used to identify the element.
Array Representation
Arrays can be declared in various ways in different languages. Below is an illustration.
arr[10]= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
As per the above illustration, following are the important points to be considered.
• Index starts with 0.
• Array length is 10 which means it can store 10 elements.
• Each element can be accessed via its index. For example, we can fetch an element at index 6 as 7.
Linear Search
This is the simplest kind of searching. It is also called the serial search or sequential search
If you have a list (or array) that is not sorted, then this is the simplest searching algorithm: Searching starts with
the first item, go through the list item by item and compare to the searched item. If a comparison succeeds, the
algorithm has found the item. If all comparisons fail, the item doesn't exist in the array or list.
.
Liner Search
A written description algorithm for a linear search might be:
• Set counter to 0.
• Check to see if the value at that position matches the value searched for.
• If it matches, the value is found. Send a message and end the search.
• If not, increment the counter by 1 and go back to step 3 until there are no more items to search.
• If all the items have been checked and no match is found, send a message.
Linear search can be quite inefficient. Suppose the data set contained 100 items of data, and the item
searched for happens to be the last item in the set. All of the previous 99 items would have to be searched
through first.
Linear searches have the advantage that they will work on any data set, whether it is ordered or unordered.
Bubble Sort
• In Bubble Sort, all we have to do is pick the first two elements of the array and compare them if first
one is greater than the second one then swap them.
• After it, pick next two elements and compare them and so on.
• After travelling the array once, the greatest number will be placed on the last index.
• To sort entire array we have to travel the array (n-1) times where n is the length of the array.
Algorithm
• Start at the beginning of the list.
• Compare the first value in the list with the next one up. If the first value is bigger, swap the positions
of the two values.
• Move to the second value in the list. Again, compare this value with the next and swap if the value is
bigger.
• Keep going until the there are no more items to compare. Note - the last item checked in the list is
now sorted, so ignore this next time.
• Go back to the start of the list.
Each run through the list, from start to finish, is known as a pass. The bubble sort continues until a pass is
made where no values have been swapped. At this point, the list is sorted.
“As after every step the largest element tend to move up into the correct order like
bubbles rising to the surface, that’s why it is called as BUBBLE SORT.”
Let’s consider we have an array: 21,14,18,25,9
Pass-1:
As we know 14 is less than 21 so swap them and pick next
two elements.
An automated system has the benefit of including automatic checks in order to prevent
incorrect data from being recorded .
For example, validation can be utilized to check that only Male or Female is entered in a
gender field.
Validation is a way of trying to lessen the number of errors during the process of data input.
Validation is carried out by the computer when you input data. It is a way of checking the
input data against the set of validation rules.
The purpose of validation is to make sure that data is a) logical, b) rational, and c) complete
and within acceptable limits.
There are many different
types of validation checks
including:
• range checks
• length checks
• type checks
• character checks
• format checks
• presence checks
• check digits.
Database Validation Methods
1. Range Check – Range check is a validation check which can be applied to numeric fields. This is done
to ensure that only numbers within a certain domain can be entered into a field.
Range checks can be programmed using selection to produce an error, or within a loop that
keeps asking you enter a value until it is valid.
Database Validation Methods
2. A LENGTH CHECK checks that data contains an exact number of characters.
This could in a string, for example, the length of “hello world” is 11, the space is also a character.
It could be in a variable, for example, in this example, 8 will be output:
TheData ← "123 ABC!"
OUTPUT(LENGTH(TheData))
Examples include date format, postal codes, and driver’s license numbers.
for example, in Chapter 9 the cub number must be in the form CUB9999.
Database Validation Methods
6. A CHECK DIGIT is the final digit included in a code; it is calculated from all the other digits in the code.
A check digit is calculated from a set of numbers, and is input with the numbers. When the
data has been input, the calculation is performed on the data again and the result is compared with the
final number (the check digit).
Check digits are used for barcodes, product codes, International Standard Book Numbers (ISBN) and
Vehicle Identification Numbers (VIN).
Check digits are used to identify errors in data entry caused by mis-typing or misscanning a barcode.
They can usually detect the following types of error:
• an incorrect digit entered, for example 5327 entered instead of 5307
• transposition errors where two numbers have changed order, for example 5037 instead of 5307
• omitted or extra digits, for example 537 instead of 5307 or 53107 instead of 5307
• phonetic errors, for example 13, thirteen, instead of 30, thirty.
Presence Check and Type check
Need of Verification
There are a few kinds of standard errors that are often experienced when doing data entry.
Two of the most common of these are transcription errors and transposition errors.
1. Transcription Errors
Every time data is manually entered into the system, there’s a possibility that an error will be committed.
Human errors do occur, and there are a variety of different reasons as to why they happen.
One could be that the person misunderstood what was written or what was said.
Another reason for an error was that the person was rushing, and didn’t pay enough attention to detail.
2. Transposition Errors
Transposition errors happen when the encoder accidentally mixed up the order of numbers or letters.
Verification can be done to ensure that the data in the database has as few errors as possible.
Another way to phrase this is by saying that verification is done to make sure that the data entered is equal to
the data from the original source.
Verification means to check that the data from the original source document is exactly the same as the
data that you have entered into the system.
Methods of Verification
1. Double entry – This refers to inputting the data twice and comparing the two entries.
A classic example would be when creating a new password. You are often asked to enter the password twice. This lets
the computer verify that data entry is exactly the same for both instances, and that no error has been committed. The
first entry is verified against the second entry by matching them.
2. screen/visual check / Proofreading data - this method involves someone checking the data entered against the
original document.
A test plan is a document that sets out the
tests that will be carried out during the
formal stages of testing. Tests must be
designed, and data selected, to 'provoke
failure', as well as to show that the system
works as expected.
Test data
Test data is data that is used to test whether or not a program is functioning correctly. The test data is
input, the program is processed and the output is confirmed.
Whenever possible, test data should cover a range of possible and impossible inputs, each designed to
prove a program works or to highlight any flaws.
Test plans should be created before programming starts so that they reflect all the requirements of the
program design.
For example, if you have a form that collects the marks that students have scored in a class test and
there is an input field labelled 'Test mark', you would expect the user to enter a numeric value.
Marks of a student : Normal data: 12, 50,75
Extreme data - valid data that falls at possible ranges. These are values that are at the limits of validity.
If the valid range of test marks was 0 to 100, then 0 would be a boundary value (the lower bound), as
would 100 (the upper bound). Both are valid marks and should be accepted.
Marks of a student : Extreme data : 0 and 100
Boundary data - Test just outside the boundary value to ensure that such a value was not accepted.
At each boundary two values are required: one value is accepted and the other value is rejected.
For example, for percentage marks in the range 0 to 100,
Boundary data for 0 is: -1, 0 and for 100 is 100,101
Expected results: -1/101 is rejected, 0/100 is accepted
i.E if the user entered a test mark of 101 or -1, you would expect an error message informing them that
the value was not a valid mark for that test.
Erroneous data - invalid data that the program cannot process and should not accept.
These are values that should be rejected (if entered).
If the user entered the word "thirty-five" as the mark, you would expect an error message informing the
user that a numeric value must be entered.
Marks of a student : Erroneous/abnormal data: –12, eleven
Consider this simple pseudo-code program, which asks a user to input a number from 1 to 10:
A dry run involves creating a trace table that includes all the variables a program
contains.
Whenever the value of a variable changes, the change is indicated in the trace table.
Trace tables help programmers to determine the point in a program where a logic error
has occurred.
Tracing an algorithm means tracking the values of variables as you dry run the program.
A dry run means that you don’t actually run the code, you work through it on paper.
1. Before you start, identify all the variables that you need to track.
2. Make a trace table on which to record the values, having a column for each variable that
will be traced.
3. every time the value of a variable is changed, the new value is entered in that
column of the trace table
4. every time a value is output, the value is shown in the output column.
Consider the following algorithm.
a Complete the following trace table using the temperature values
14, 17, 23, 27, 29, 30, 32, 26, 18, 12.
b Th e algorithm inputs 10 temperature readings and counts separately those of at least 30
degrees and under 18 degrees. It then outputs the number of low readings and the number of
high readings.
Test data: 9, 7, 3, 12, 6, 4, 15, 2, 8, 5