OL P2 Theory
OL P2 Theory
OL P2 Theory
Logic Gates 10
Database 10
Flowchart/Trace Table 5
Test Data
Validation & Verification
10
Structure Diagram
Program Development Life Cycle
Pseudocode:
• It is a notation resembling a simplified programming language used in program design.
• It uses English key words to describe what an algorithm does.
• The English key words used are similar to those used in a high-level programming language.
Basic Rules of Pseudocode:
1. All keywords and data types are written in capital letters such as DECLARE, CONSTANT,
STRING, REAL, INPUT, PRINT, IF, THEN, FOR, NEXT, WHILE, REPEAT, UNTIL, AND, OR etc.
2. All names given to data items and subroutines start with a capital letter.
3. All identifiers must be declared at the beginning of the code along with their data types.
Algorithm:
• An algorithm is produced when designing a solution to a problem.
• It is used to describe the solution as a sequence of steps/actions.
1
O Levels Paper 2 – Theory
2
O Levels Paper 2 – Theory
Sub-Systems:
Structure Diagram:
• It is an overview of a program or a subroutine.
• It is a modelling tool used to show the hierarchy of different components which make up a
system.
• It is a graphical representation to show how a system is broken into sub-systems.
• It shows the relationship between different components of a system.
Decomposition:
Problem Decomposition:
• It breaks the problem/algorithm (not program/code) into sub-tasks/sub-problems repeatedly
until all sub-problems are small/detailed enough to solve.
• It is used to identify program modules/repeated elements where each sub-task can be
implemented by a program module.
• It is used to identify subroutines.
Reason for use:
1. It makes the problem easier to solve.
2. It makes the solution easier to implement/test/maintain.
Benefits of using sub-tasks/sub-problems:
1. The sub-tasks make the solution more manageable/makes the algorithm easier to follow.
2. A sub-task makes the problem easier to solve/design than the whole task.
3. A sub-task is useful when a part of the algorithm is repeated.
3
O Levels Paper 2 – Theory
Data Types:
1. Integer: It is a whole number that can be positive, negative or zero.
e.g. –10, 999, 12345, 2001, 3, –8765
2. Real: It is a number with a fractional part that can be positive or negative.
e.g. 2.0, –3.142, 999.87
3. String: It is a sequence of characters that may contain letters and/or numbers and/or special
characters.
e.g. Haseeb, lahore123, def@773, #123?Y, IP123.112
4. Char: It is a single character that may contain a single number, symbol or letter.
e.g. A, #, 2, @, x, T
5. Boolean: It is a data type with two possible values, such as TRUE and FALSE.
e.g. TRUE/FALSE, YES/NO, 0/1
NOTE:
The integers are written as normal without any quotations, e.g. 5, –3
The real is written with at least one digit on either side of decimal point, e.g. 4.7, 0.3, 0.0, –4.0
The char is a single character written with single quotations, e.g. ‘x’, ‘c’, ‘@’
The string is a sequence of characters written with double quotations, e.g. “This is a string”
The string may contain no characters (the empty string), e.g. “”
The boolean is written in capital letters without any quotations e.g. TRUE, FALSE
4
O Levels Paper 2 – Theory
Validation:
• It is an automatic check used to test if the data entered is reasonable/possible/sensible.
• It checks that data meets certain criteria.
• Examples include range check, length check, type check, presence check, format check and
check digit.
1) Range Check:
• It checks that the data input is between specified set of values/specified two values (upper
value and a lower value).
Example: if a month has to be input using an integer, it must be between 1 and 12 inclusive.
2) Length Check:
• It checks that the data input is over/under a certain number of specified characters.
Example: an international telephone number can be no longer than 15 digits.
3) Type Check:
• It checks that the data input follows rules related to whether it is numbers or letters etc.
• It checks if the data input is of the correct data type.
Example: if the input is expecting integer(s) to be entered, it will not allow a string to be entered.
4) Presence Check:
• It checks that some data is input/entered and the space is not left empty/blank.
5) Format Check:
• It checks that the characters entered conform to a pre-defined pattern.
Example: an email address must contain ‘@’ symbol.
6) Check Digit:
• It checks that the data input has the correct digits and identification code entered is genuine
or possible.
5
O Levels Paper 2 – Theory
Verification:
• It is used to test if the data input is the same as the data that was intended/meant to be input
(data entered is correct and matches the original input).
• It is used to check that data has not changed during input to a computer or during transfer
between computers/devices.
• Examples include visual check and double entry check.
Double Entry Check:
• It expects each item of data to be entered twice.
• It compares both entries of data to check they are the same.
• It only accepts the data if both entries are same/identical.
Visual Check:
• It displays the data as it is entered.
• The user can then see if errors have been made as the data was entered and then accordingly
correct those errors.
• The user can confirm that the data is correct/same as the original or change it.
Test Data:
1) Normal Test Data:
• It is accepted by a program and is used to show that the program is working as expected.
2) Abnormal Test Data:
• It should be rejected by a program as it is unsuitable or could cause problems.
3) Extreme Test Data:
• It is the largest/smallest acceptable value.
Example: when testing a validation rule such as ‘number >= 12 AND number <= 32’ the extreme
test data would be 12 at the lower limit and 32 at the upper limit.
Both these values should be accepted.
4) Boundary Test Data:
• It is the largest/smallest acceptable value and the corresponding smallest/largest rejected
value.
Example: when testing a validation rule such as ‘number >= 12 AND number <= 32’ the
boundary test data would be 12 and 11 at the lower limit and 32 and 33 at the upper limit.
The values 12 and 32 should be accepted whereas values 11 and 33 should be rejected.
6
O Levels Paper 2 – Theory
=
EXAM TIP:
Whenever a question statement in Paper 2 asks for a reason for why you would use a particular
type of conditional statement or a particular type of loop or any other reason asked for 1 mark
in Paper 2 usually has the following structured answer:
• It is used to simplify pseudocode OR make pseudocode more understandable.
• It is used to simplify programming OR make the code easier etc.
Assignments:
• The assignment operator is ‘’ but we will use ‘=’ throughout the practice and classes.
• The variables must be assigned values of the same data type as the variable itself.
Format of Assignments:
<identifier> = <value>
Example of Assignments:
1. Cost = 10.6
2. Counter = Counter + 1
3. Total = Num1 + Num2
4. Payment = NumberOfHours * HourlyRate
5. Tax = Price * 0.12
6. Gender = “M”
7. Name = “Umaid”
8. Grade = “O3”
9. Chosen = False
7
O Levels Paper 2 – Theory
Variable Declarations:
NOTE:
Format of Variable Declarations:
The data types must be capitalized during
DECLARE <identifier> : <data type> the declaration. The following keywords
Example of Variable Declarations: are used to declare basic data types:
Constant Declarations:
• Only literals can be used as the value of constant.
• A variable, another constant or an expression must never be used.
Format of Constant Declarations:
CONSTANT <identifier> = <value>
Example of Constant Declarations:
1. CONSTANT HourlyRate = 6.50
2. CONSTANT Name = “Haseeb”
3. CONSTANT Number = 999
4. CONSTANT Flag = TRUE
8
O Levels Paper 2 – Theory
Identifiers:
These are the names given to variables, constants, arrays, procedures and functions in mixed case
e.g. FirstName.
Constants:
• The value that cannot be changed accidentally during the execution of the program.
• The value only needs to be changed once if circumstances change or during the initialization
process.
Variables:
• It stores a value that can change during the execution of the program.
• It can use a variable without knowing its value.
Arrays:
• It is a list of items of the same data type stored under a single name.
• It is used to reduce the number of variables.
• Any item can be found using an index number to show its place in the list.
9
O Levels Paper 2 – Theory
Sequence:
• It is the concept of one statement being executed after another.
• An example of sequence could be:
PRINT X
PRINT Y
where the first statement is executed first and the next statement is executed after previous
one.
Selection/Conditional Statements:
Examples of Conditional Statements:
1. IF (...THEN...ELSE...ENDIF)
2. CASE (...OF...OTHERWISE...ENDCASE)
Purpose of Conditional Statements:
• They are used to allow different routes through a program dependent on meeting certain
criteria.
IF Statement:
A conditional statement with different outcomes for true and false.
• It is used for checking a condition that may be complex.
• It is used for checking a condition that uses relational operators.
• It is used for checking for a range of values.
• It is used for checking for only 2 options.
Format of IF Statements:
• The IF Statements may or may not have an ELSE clause.
IF Statements without an ELSE clause are written as follows:
IF <condition>
THEN
<statements>
ENDIF
10
O Levels Paper 2 – Theory
IF <condition>
THEN
<statements>
ELSE
<statements>
ENDIF
CASE Statement:
A conditional statement to deal with many possible outcomes.
• It is used for checking for discrete values.
• It is used for checking more than 2 of values.
Format of CASE Statements:
• The CASE Statements allow one out of several branches of code to be executed, depending
on the value of a variable.
CASE Statements are written as follows:
CASE OF <identifier>
<value 1> : <statement>
<value 2> : <statement>
...
ENDCASE
CASE OF <identifier>
<value 1> : <statement>
<value 2> : <statement>
...
OTHERWISE <statement>
ENDCASE
11
O Levels Paper 2 – Theory
Loops/Repetition/Iteration:
Examples of Loop Structures:
1. FOR (...TO...NEXT)
2. REPEAT (...UNTIL)
3. WHILE (...DO...ENDWHILE)
Description of Loop Structures:
1) FOR Loop (Count-Controlled Loop):
• It has a fixed number of iterations/repetitions.
• It is a loop that will always iterate a set number of times.
REPEAT
INPUT Number
Total = Total + Number
UNTIL Number = 0
12
O Levels Paper 2 – Theory
13
O Levels Paper 2 – Theory
REPEAT
<statements>
UNTIL <condition>
WHILE <condition> DO
<statements>
ENDWHILE
• The condition is tested before the statements, and the statements will only be executed if the
condition evaluates to TRUE.
• After the statements have been executed the condition is tested again.
• The loop terminates when the condition evaluates to FALSE.
• The statements will not be executed if, on the first test, the condition evaluates to FALSE.
14
O Levels Paper 2 – Theory
Library Routines:
• A collection of standard subroutines/programs available for immediate use.
• The use of library routines make writing programs faster and easier as part of the work has
already been done (and debugged).
Library Routine:
• A standard subroutine to include in your own program to carry out a common task which is
available for immediate use.
15
O Levels Paper 2 – Theory
File Handling:
Why a program might need to store data in a file:
• The data is not lost when the computer is switched off/ the data is stored permanently.
• The data can be used by more than one program or reused when a program is run again.
• The data can be backed up or archived.
• The data can be transported from one place/system to another.
16