You are on page 1of 16

O Levels Paper 2 – Theory

Estimated Marks Breakdown – Topic Wise:

Topic Average Marks

Pseudocode (most important) 40

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

Program Development Life Cycle:


Stages in a Program Development Life Cycle:
1. Analysis/Problem Definition
2. Design
3. Coding/Programming/Implementation
4. Testing
Program Development Life Cycle activities with reference to editor, translator & debugger:
• An editor is used to produce/write/modify the source code/high-level language code.
• An editor provides features such as context-sensitive prompts/dynamic syntax checking etc.
• A translator (compiler) is used to translate/convert the source code into object code/machine
code/executable file.
• A translator (interpreter) is used to translate the source code line by line.
• A debugger is used to test the program.
• A debugger is used to detect errors and correct errors in the program.
Tasks/activities performed during Analysis Stage:
1. Abstraction
2. Decomposition of the problem (problem definition)
3. Identification of the problem (problem investigation)
4. Identification of the requirement specifications
5. Feasibility study
Tasks/activities performed during Design Stage:
1. Create/produce/define data structures/data types
2. Create/produce/define identifier table
3. Decomposing the problem into sub-problems
4. Create algorithms/pseudocode/flowchart
5. Create structure charts
6. Create/produce/define test plan/strategy
7. Use of library routines/program structure (modules)
8. Identify inputs/outputs/processes
9. Choose a suitable programming language/program environment

2
O Levels Paper 2 – Theory

Tasks/activities performed during Coding Stage:


1. Write program code/coding the algorithms from design
2. Iterative testing (initial debugging/testing)
3. Define data structures
4. Use a translator to check and run the code
Tasks/activities performed during Testing Stage:
1. Testing program code with use of different test data

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:

1. DECLARE Counter : INTEGER INTEGER


2. DECLARE Name : STRING REAL
3. DECLARE Payment : REAL CHAR
4. DECLARE Choice : BOOLEAN STRING
5. DECLARE Initial : CHAR BOOLEAN

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.

Rules for Identifiers:


1) They should have meaningful names (they describe the variable, constant, or array to which
they refer).
2) The keywords should never be used as identifier names.
3) They can only contain letters (A–Z, a–z) and digits (0-9).
4) They must start with a capital letter and not a digit.
5) They should never start with a digit but they can end with a digit.
6) The accented letters (á, é, î, ô, Ã, Ñ, ÿ, Ä etc.) and other characters (@, $, #, ^, %, * etc.),
including the underscore, should not be used.
7) The single letters may be used where these are conventional (such as i and j when dealing
with array indices, or X and Y when dealing with coordinates).
The identifiers should be considered case insensitive, for example, Countdown and CountDown
should not be used as separate variables.

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 Statements with an ELSE clause are written as follows:

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

An OTHERWISE clause can be the last case:

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.

FOR Count = 1 TO 100


INPUT Number
Total = Total + Number
NEXT Count

2) REPEAT Loop (Post-Condition Loop):


• It is always executed and the condition is tested at end.
• It is a loop that will always iterate/run atleast once.
• It is used where at least one repeat is required.
It uses > and = operators.

REPEAT
INPUT Number
Total = Total + Number
UNTIL Number = 0

12
O Levels Paper 2 – Theory

3) WHILE Loop (Pre-Condition Loop):


• It may never be executed/run and the condition is tested at beginning.
• It is a loop that will not be executed on the first test if the condition is false.
It uses < and <> operators.

WHILE Number <> -1 DO


INPUT Number
Total = Total + Number
ENDWHILE

13
O Levels Paper 2 – Theory

Count-Controlled Loop (FOR Loop):


Format of FOR Loops:

FOR count = 1 TO 100


<statements>
NEXT count

• The identifier must be a variable of data type INTEGER.


• The value2 must be greater than value1 for the statements to execute.

Post-Condition Loop (REPEAT Loop):


Format of REPEAT Loops:

REPEAT
<statements>
UNTIL <condition>

• The statements in the loop will be executed at least once.


• The condition is tested after the statements are executed and if it evaluates to TRUE the loop
terminates, otherwise the statements are executed again.

Pre-Condition Loop (WHILE Loop):


Format of WHILE Loops:

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.

Sub Routines (Functions & Procedures):


• It is called from within a program.
• It is not a complete program.
• It is a self-contained piece of code.
Function:
• The function is a subroutine that always returns a value.
• It can be used in an assignment statement.
Procedure:
• The procedure is a subroutine that does not have to return a value.
Use of Subroutine in a program:
1. It allows the subroutine code to be called from many/multiple places.
2. It is used to perform a frequently used operation within a program.
3. It can be called when needed and can be reused by another program.
4. The subroutine code may be independently tested and debugged.
5. If the subroutine task changes, the change needs to be made only once.
6. It reduces unnecessary duplication/program lines.
7. It enables the sharing of development between programmers.
Why Parameters are used with Subroutines:
• It is used to pass values to/from the subroutine.
• It is used to produce re-usable code.
• It is used to avoid global variables.

15
O Levels Paper 2 – Theory

One-Dimensional (1D) 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.
Dimension:
• The dimension is the number of indexes required to access an element.
Index:
• The index is the position of the element in an array.
• For example, A[25] is the 25th element of a one-dimensional array..
Reason for using 1D Arrays:
1. It is used to simplify programming.
2. It makes programs shorter.
3. The index can be used to identify the same elements across the arrays.

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

You might also like