o Level Igcse Computer p2 Workbook by Inqilab Patel
o Level Igcse Computer p2 Workbook by Inqilab Patel
Contents
Syllabus content & assessment at a glance ............................................................................................3
About the developer of this workbook .....................................................................................................5
2.1.1 Problem-solving and design .............................................................................................................7
2.1.2 Pseudocode ..................................................................................................................................... 13
Finding and correcting errors in pseudocode algorithm...................................................................... 21
Examination Questions ............................................................................................................................ 23
Marking Scheme (error detection) .......................................................................................................... 28
Finding output from pseudocode ............................................................................................................ 29
Marking Scheme ...................................................................................................................................... 31
Writing Algorithm ........................................................................................................................................ 32
2.1.2 Flowchart ........................................................................................................................................... 70
Finding Output from flowchart ................................................................................................................ 70
Marking Schemes ................................................................................................................................... 105
Fill in missing statements ................................................................................................................... 109
Marking Scheme .................................................................................................................................... 127
2.2 Programming .................................................................................................................................... 129
VB.NET – ENVIRONMENT ................................................................................................................. 130
PRE-RELEASE MATERIAL MAY/JUNE 2016 ................................................................................. 143
Sample Questions ............................................................................................................................ 151
His entire career path revolves around computer science; either he was a student
or a teacher. He got a chance to polish his skills of teaching and studying more
about computers at various levels which has given him great confidence in
presenting himself for any senior level position of transferring his knowledge to the
youth.
He has not stopped, he is continuing with his education at the higher levels. It is his
second semester of MPhil computer studies from a well-know university of
Pakistan; The Institute of Business & Technology.
Inqilab Patel knows a lot of methods of teaching computers and has developed
tutorial notes, worksheets and assignments for my students. He also maintains a
website (www.ruknuddin.com) which is specifically designed for the support of
those who want to excel in GCSE computer science. He also regularly contributes
material to CIE teacher support website, for which he receives appreciation from
different people across the world.
Paper 2
Practical Problem-solving and Programming
7|Page
2.1.1 Problem-solving and design
• Show understanding that every computer system is made up of sub-systems, which in turn
aremade up of further sub-systems
• Use top-down design, structure diagrams, flowcharts, pseudocode, library routines and
subroutines
• Work out the purpose of a given algorithm
• Explain standard methods of solution
• Suggest and apply suitable test data
• Understand the need for validation and verification checks to be made on input data (validation
could include range checks, length checks, type checks and check digits)
• Use trace tables to find the value of variables at each step in an algorithm
• Identify errors in given algorithms and suggest ways of removing these errors
• Produce an algorithm for a given problem (either in the form of pseudocode or flowchart)
• Comment on the effectiveness of a given solution
Computer System
A system which is made up of software, data, hardware, communications and
people is considered as computer system.
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 justperforms a
single action.
Computer system is often divided up into sub-systems. This division can be shown using
top-down design to produce structure diagrams that demonstrate the modular
construction of the system.Each sub-system can be developed by a programmer as sub-
routine or an existing library routine may be already available for use. How each sub-
routine works can be shown by using flowcharts or pseudocode.
Top-down design
Structure diagrams
Flowcharts
Pseudocode
Library routines
Sub-routines
1. Top-Down Design
Top-down design is the breaking down of a computer system into a set of subsystems,
then breaking each sub-system down into a set of smaller sub-systems, until each sub-
system just performs a single action.
This is an effective way of designing a computer system to provide a solution to a
problem, since each part of the problem is broken down into smaller more manageable
problems. The process of breaking down into smaller sub-systems is called ‘stepwise
refinement’.
This structured approach works for the development of both large and small computer
systems. When large computer systems are being developed this means that several
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.
8|Page
2. Structure Diagrams
The STRUCTURE DIAGRAM shows the design of a computer system in a hierarchical
way, with each level giving a more detailed breakdown of the system into sub-systems.
3. Flowcharts
A FLOWCHART shows diagrammatically the steps required for a task (sub-system) and
the order that they are to be performed. These steps together with the order are called
an ALGORITHM. Flowcharts are an effective way to communicate the algorithm that
shows how a system or sub-system works.
4. Pseudocode
PSEUDOCODE is a simple method of showing an algorithm, using English-like words
and mathematical operators that are set out to look like a program.
5. Library routines
A LIBRARY ROUTINE is a set of programming instructions for a given task that is
already available for use. It is pre-tested and usually performs a task that is frequently
required. For example, the task ‘get time’ in the checking-for-the-alarm time algorithm
would probably be readily available as a library routine.
6. Sub-routines
A SUB-ROUTINE is a set of programming instructions for a given task that forms a
subsystem, not the whole system. Sub-routines written in high-level programming
languages are called ‘procedures’ or ‘functions’ depending on how they are used.
Test Data
Test data is the data that is used in tests of a software system.
In order to test a software application we need to enter some data for testing most of the
features. Any such specifically identified data which is used in tests is known as test
data.
There are following three types of test data:
1. Normal Data
2. Abnormal Data
3. Extreme Data
1. Normal Data
This is the data a computer system should work on.Testing needs to be done to prove
that the solution works correctly. In order to do this a set of test data should be used
together with the result(s) that are expected from that data. The type of test data used to
do this is called NORMAL DATA, this should be used to work through the solution to find
the actual result(s) and see if these are the same as the expected result(s).
For example, here is a set of normal test data for an algorithm to record the percentage
marks from 10 end-of-term examinations for a student and find their average mark:
Normal test data: 50, 50, 50, 50, 50, 50, 50, 50, 50, 50
Expected result: 50
9|Page
2. Abnormal Data
This is data that should cause the system to tell the user that there is a problem with
data entered into the system. Testing also needs to be done to prove that the solution
does not give incorrect results. In order to do this, test data should be used that will be
rejected as the values are not suitable. This type of test data is called ERRONEOUS or
ABNORMAL TESTDATA; it should be rejected by the solution.
For example erroneous/abnormal data for an algorithm to record the percentage marks
from 10 end-of-term examinations for a student and find their average mark could be:
Erroneous/abnormal data:–12, eleven
Expected results: these values should be rejected
3. Extreme Data
When testing algorithms with numerical values, sometimes only a given range of values
should be allowed. For example, percentage marks should only be in the range 0 to 100.
The algorithm should be tested with EXTREME DATA, which, in this case, are the
largest and smallest marks that should be accepted. Extreme data are the largest and
smallest values that normal data can take.
Extreme data: 0, 100
Expected results: these values should be accepted
Rogue Values
A sequence of inputs may continue until a specific value is input. This value is called
a rogue value and must be a value which would not normally arise.
A rogue value lets the computer know that a sequence of input values has come to an
end.
Example
A number of marks are to be input (terminated by a rogue value of -1). How many of
them are over 50?
Counter 0
INPUT Marks
REPEAT
IF Marks >50 THEN Above50 Above50 +1
INPUT Marks
UNTIL Marks=-1
OUTPUT Above50
10 | P a g e
Validation and Verification
Validation and verification are two ways to check that the data entered into a computer is
correct. Data entered incorrectly is of little use.
Data verification
Verification is performed to ensure that the data entered exactly matches the original
source. Verification means checking the input data with the original data to make sure
that there have been no transcription errors (transcription means copying the data). The
standard way to do this is to input the data twice to the computer system. The computer
then checks the two data values (which should be the same) and, if they are different,
the computer knows that one of the inputs is wrong. E.g. entering password twice during
sig-up. Verification methods include:
double entry
screen/visual check (proof reading)
parity check
Checksum.
Validation is an automatic computer check to ensure that the data entered is sensible
and reasonable. It does not check the accuracy of data.
For example, a secondary school student is likely to be aged between 11 and 16. The
computer can be programmed only to accept numbers between 11 and 16. This is a
range check.
However, this does not guarantee that the number typed in is correct. For example, a
student's age might be 14, but if 11 are entered it will be valid but incorrect.
Types of validation
There are a number of validation types that can be used to check the data that is being
entered.
Validation
How it works Example usage
type
Range Checks that a value falls within the Number of hours worked must be
check specified range less than 50 and more than 0
Length Checks the data isn't too short or too A password which needs to be six
check long. Values must be a specific length. letters long
>=0 means reject negative
Similar to Range Check but the rule
Limit Check numbers. Date of birth must not
involves only one limit.
be later than a date.
Number of brothers or sisters
Checks that the data entered is of a
Type Check would be an integer (whole
given data type,
number).
A name would not contain
Checks that when a string of characters
Character characters such as %, and a
is entered it does not contain any invalid
Check telephone number would only
characters or symbols,
contain digits or (,), and+.
11 | P a g e
Validation
How it works Example usage
type
Checks the data is in the right format.
A National Insurance number is in
Format Values must conform to a specific
the form LL 99 99 99 L where L is
Check pattern, for example, two letters followed
any letter and 9 is any number
by six digits followed by a single letter
Presence Checks that data has been entered into In most databases a key field
check a field cannot be left blank
The last one in a code are used to Bar code readers in supermarkets
Check digit
check the other digits are correct use check digits
2) What validation type would make sure a post code was entered in the correct format?
a) Length check b) Format Check c) Presence check
3) What validation type would you use to check that numbers fell within a certain range?
a) Range check b) Presence Check c) Check digit
5) What validation type uses the last one or two digits to check the other digits are
correct?
a) Length check b) Format check c) Check digit
6) What validation type checks a minimum number of characters have been entered?
a) Length check b) Format check c) Range check
7) Data is to be entered into a computer in the format YYMMDD. Which of the following
is not a valid date?
a) 310921 b) 211113 c) 21st June 2004
patient’s height
patient ID
Contact telephone
number
2.1.2 Pseudocode
• understand and use pseudocode for assignment, using ←
• understand and use pseudocode, using the following conditional statements:
IF … THEN … ELSE … ENDIF
CASE … OF … OTHERWISE … ENDCASE
• understand and use pseudocode, using the following loop structures:
FOR … TO … NEXT
REPEAT … UNTIL
WHILE … DO … ENDWHILE
• understand and use pseudocode, using the following commands and statements:
INPUT and OUTPUT (e.g. READ and PRINT)
totalling (e.g. Sum ← Sum + Number)
counting (e.g. Count ← Count + 1)
(Candidates are advised to try out solutions to a variety of different problems on a
computer using a language of their choice; no particular programming language will
be assumed in this syllabus.)
Introduction to Algorithm
An algorithm is a sequence of steps for solving a problem.
In general, an 'algorithm' is the name given to a defined set of steps used to complete a
task.
For instance you could define an algorithm to make a cup of tea. You start by filling the
kettle, and then place a tea bag in the cup and so on.
In computer terms, an algorithm describes the set of steps needed to carry out a
software task. This mini-web takes you through the topic of algorithm
The concept of a program
A program is a sequence of instructions or programming language statements written to
make a computer perform certain tasks.
Well-structured programs require a programming language to support the following
program constructs:
sequence
selection
iteration
A computer’s processor can only run a computer program in the form of a file of machine
code, which is a sequence of binary codes representing instructions for the processor.
The instruction set for a family of processors is the machine language in which machine
code is written for that family of processors.
When machine code runs, the processor repeatedly:
Fetches an instruction from internal memory
Decodes the instruction
Executes the instruction.
14 | P a g e
Pseudocode
Pseudocode uses keywords commonly found in high-level languages and mathematical
notation. It describes an algorithm’s steps like program statements, without being bound
by the strict rules of vocabulary and syntax of any particular language, together with
ordinary English.
Arithmetic operations
Standard arithmetic operator symbols are used:
+ Addition
- Subtraction
* Multiplication
/ Division
Care should be taken with the division operation: the resulting value should be of data
type REAL, even if the operands are integers.
The integer division operators MOD and DIV can be used. However, their use should be
explained explicitly and not assumed.
INT function is also used in algorithm.
Relational operations
The following symbols are used for relational operators (also known as comparison
operators):
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
= Equal to
<> Not equal to
Logic operators
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.
Assignment
Assignment is the process of writing a value into a variable (a named memory location).
For example, Count ← 1 can be read as ‘Count is assigned the value 1’, ‘Count is made
equal to 1’ or ‘Count becomes 1’. Another way of indicating assignment is a pseudocode
statement such as:
Set Swapped to False
Initialisation:
If an algorithm needs to read the value of a variable before it assigns input data or a
calculated value to the variable, the algorithm should assign an appropriate initial value
to the variable, known as Initialisation.
15 | P a g e
Input
We indicate input by words such as INPUT, READ or ENTER, followed by the name of a
variable to which we wish to assign the input value.
Output
We indicate output by words such as OUTPUT, WRITE or PRINT, followed by a comma-
separated list of expressions.
Totalling
To keep a running total, we can use a variable such as Total or Sum to hold the running
total and assignment statements such as:
Total ← Total + Number
ADD Number to Total
Counting
It is sometimes necessary to count how many times something happens.
To count up or increment by 1, we can use statements such as:
Count ← Count + 1
INCREMENT Count by 1
Variable:
Variable is memory location where a value can be stored. The values stored in a variable
are changed during execution.
Variable declarations
It is good practice to declare variables explicitly in pseudocode.
Declarations are made as follows:
DECLARE<identifier> : <data type>
Example
DECLARE Surname : STRING
DECLARE FirstName : STRING
DECLARE DateOfBirth : DATE
DECLARE Section : CHAR
DECLARE Counter : INTEGER
DECLARE TotalToPay : REAL
DECLARE GameOver : BOOLEAN
16 | P a g e
Constant:
Constant is memory location where a value can be stored but the stored value remaining
same during execution.
It is good practice to use constants if this makes the pseudocode more readable, as an
identifier is more meaningful in many cases than a literal. It also makes the pseudocode
easier to update if the value of the constant changes.
Constant declaration
Constants are normally declared at the beginning of a piece of pseudocode (unless it is
desirable to restrict the scope of the constant).
Constants are declared by stating the identifier and the literal value in the following
format:
CONSTANT<identifier> = <value>
Example
CONSTANT HourlyRate = 6.50
CONSTANT DefaultText = “N/A”
Only literals can be used as the value of a constant. A variable, another constant or an
expression must never be used.
Declaring arrays
Arrays are considered to be fixed-length structures of elements of identical data type,
accessible by consecutive index (subscript) numbers. It is good practice to explicitly state
what the lower bound of the array (i.e. the index of the first element) is because this
defaults to either 0 or 1 in different systems. Generally, a lower bound of 1 will be used.
Square brackets are used to indicate the array indices.
One- and two-dimensional arrays are declared as follows (where l, l1, l2 are lower
bounds and u, u1, u2 are upper bounds):
DECLARE <identifier>: ARRAY[<l>:<u>] OF <data type>
DECLARE <identifier>: ARRAY[<l1>:<u1>,<l2>:<u2>] OF <data type>
Example
DECLARE StudentNames : ARRAY[1:30] OF STRING
DECLARE NoughtsAndCrosses : ARRAY[1:3,1:3] OF CHAR
Using arrays
In the main pseudocode statements, only one index value is used for each dimension in
the square brackets.
Example
StudentNames[1] “Ali”
NoughtsAndCrosses[2,3] ‘X’
StudentNames[n+1] StudentNames[n]
17 | P a g e
Iteration (Repetition, Loop)
The identifier must be a variable of data type INTEGER, and the values should be
expressions that evaluate to integers.
The increment must be an expression that evaluates to an integer. In this case the
identifier will be assigned the values from value1 in successive increments of increment
until it reaches value2. If it goes past value2, the loop terminates. The increment can be
negative.
Example
Total = 0
FOR Count = 1 TO 10
INPUT Number
Total Total + Number
NEXT Count
OUTPUT “The grand total is ”, Total
Selection:
For selection following statements are used:
IF
CASE
IF statements
IF statements may or may not have an ELSE clause.
IF statements without an ELSE clause is written as follows:
IF<condition>THEN
<statements if true>
ENDIF
IF statements with an else clause is written as follows:
IF <condition>THEN
<statements if true>
ELSE
<statements if false>
ENDIF
Note that the THEN and ELSE clauses are only indented by two spaces. (They are, in a
sense, a continuation of the IF statement rather than separate statements).
When IF statements are nested, the nesting should continue the indentation of two
spaces. In particular, run-on THENIF and ELSE IF lines should be avoided.
Example
IF Number>Largest THEN
LargestNumber
ENDIF
19 | P a g e
CASE statements
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
Trace Table
Trace tables are used to dry run of algorithm for testing.
Trace Table has columns for all variables, logical expressions and output.
Exponent Result OUTPUT Description
0 Initialisation of variable
1 1 2^0=1 1st iteration
2 2 2^1=2 2nditeration
3 4 2^2=4 3rditeration
4 8 2^3=8 4thiteration
5 16 2^4=16 5th iteration
6 32 2^5=32 6thiteration
7 64 2^6=64 7thiteration
8 128 2^7=128 8thiteration
Example interpretation
The purpose of the algorithm is to print a list of the powers of 2 starting at 20 until it
reaches the first one over 100.
Finding and correcting errors in pseudocode algorithms
It is important to be able to identify errors and suggest corrections in a pseudocode
algorithm.
21 | P a g e
Finding and correcting error
rrors in pseudocode algorithm
There are 8 types of errors in pseudo code:
If Final Output like greatest value or average is required it should be after loop.
IF running output is required it should be inside loop.
Examination Questions
Q1) Winter 2014 P13
The following pseudocode algorithm should:
• input up to 20 numbers
• stop if the sum of the input numbers exceeds 50
• output the final sum
10 count = 0
20 REPEAT
30 INPUT n
40 n + sum = sum
50 IF sum = 50 THEN count = 20
60 count = count + 1
70 UNTIL count = 20
80 OUTPUT n
There are five errors in this algorithm.
Locate these errors and suggest a correction.
error 1 .......................................................................................................................................
correction ..................................................................................................................................
...................................................................................................................................................
error 2 .......................................................................................................................................
correction ..................................................................................................................................
...................................................................................................................................................
error 3 .......................................................................................................................................
correction ..................................................................................................................................
...................................................................................................................................................
error 4 .......................................................................................................................................
correction ..................................................................................................................................
...................................................................................................................................................
error 5 .......................................................................................................................................
correction ..................................................................................................................................
...............................................................................................................................................[5]
24 | P a g e
Q2) Summer 2005
The following algorithm contains an error.
1. SET X = 1
2. REPEAT
3. X = X + 2
4. Print X
5. UNTIL X = 10
(a) Trace the algorithm and explain what the error is.
.............................................................................................................................
.............................................................................................................................................
......................................................................
.......................................................................................................................................
................................................................. [2]
INPUT OUTPUT
0
5
99
(b) Write down two instructions which could be inserted between lines 1 and 2 to allow
the algorithm to deal with marks out of 100. [2]
Q6) (b) Write an algorithm which uses a While..Do..Endwhile loop and outputs the
numbers 2, 4, 6 and 8[3]
Marking Scheme
Q1)a
Input Output
0 Fail Grade
5 Pass Grade
99 Not a valid mark
b) For example(1 mark per line)
mark = mark/10
mark= INT(Mark)
or mark = mark DIV 10 is worth 2 marks on its
own
32 | P a g e
Writing Algorithm
Producing algorithms in pseudocode
Writing an algorithm in pseudocode is no longer graphical like a program flowchart, but is
one step closer to writing program code in a high-level language.
Producing an algorithm for a solution in pseudocode typically includes:
Declaring variables using data types.
Initialising any variables for totalling, highest, Lowest and counting
o Count 0 [Count starts with 0, like Count_Integer, Count_Above]
o Highest 0 [The lowest possible value]
o Lowest 999 [The highest possible value]
o Total 0
o Lowest 0
INPUT Number
IF Number<Lowest THEN Highest Number
Input
We indicate input by words such as INPUT, READ or ENTER, followed by the name of a
variable to which we wish to assign the input value.
Output
We indicate output by words such as OUTPUT, WRITE or PRINT, followed by a comma-
separated list of expressions.
Totalling
To keep a running total, we can use a variable such as Total or Sum to hold the running
total and assignment statements such as:
Total ← Total + Number [ADD Number to Total]
Counting
It is sometimes necessary to count how many times something happens.
To count up or increment by 1, we can use statements such as:
Count ← Count + 1 [INCREMENT Count by 1]
33 | P a g e
34 | P a g e
Q1) Using pseudo code or otherwise, write an algorithm which will output following
sequence of numbers:
a. 1, 2, 3, 4, 5, 6,7,8,9,10
b. 1,3,5,7,9,11,13
c. 2,4,6,8,10,12,14,16,18,20
d. 10,9,8,7,6,5,4,3,2,1
e. 2,6,10,14,18,22,26,30
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
35 | P a g e
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
..........................................................................................................................................................
............................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
..........................................................................................................................................................
............................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
36 | P a g e
Q2)Using pseudo code or otherwise, write an algorithm which will output following
sequence of numbers:
1, 2, 3, 4, 5 1,1,1,1,1 1 *****
1, 2, 3, 4, 5 2,2,2,2,2 1,2 ****
1, 2, 3, 4, 5 3,3,3,3,3 1,2,3 ***
1, 2, 3, 4, 5 4,4,4,4,4 1,2,3,4 **
1, 2, 3, 4, 5 5,5,5,5,5 1,2,3,4,5 *
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
..........................................................................................................................................................
............................................................................................................................................
37 | P a g e
Q3) Winter 2003
(a) Write an algorithm, using pseudocode or otherwise, which;
• inputs 50 numbers
• checks whether each number is in the range 1000 to 9999
• outputs how many of the input numbers were out of range
• outputs the percentage of input numbers which were out of range.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
38 | P a g e
Q4) Summer 2004
(b) Using pseudocode, or otherwise, write an algorithm that will input the hourly
temperatures for one day in Centigrade and print out in Fahrenheit
• the maximum temperature
• the minimum temperature
• the average temperature for that day.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
39 | P a g e
Q5) Winter 2004
The following diagram shows a rail network.
The rail network consists of 10 stations. The fare between each station is $2. There is a
10% discount when 3 or more passengers travel together. Tickets can be purchased at
any station using automated terminals.
Using pseudocode, or otherwise, write an algorithm for the automated terminals to:
• input the starting station number, the destination station number and the number of
passengers
• calculate the total fare and output the amount to be paid
• calculate the change (if any)
• issue the rail ticket(s) and change
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
40 | P a g e
Q6) Summer 2005
Using pseudocode or otherwise, write an algorithm that will input 25 marks and output
the number of DISTINCTION, MERIT, PASS or FAIL grades.
A mark greater than 69 will get a DISTINCTION, a mark between 69 and 60 (inclusive)
will get a MERIT and a mark between 59 and 50 (inclusive) will get a PASS.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
41 | P a g e
Q 7) Winter 2005
A school uses a computer to store student marks obtained in an end of term
mathematics exam. There are 150 students doing the exam and the maximum mark is
100.
Write an algorithm, using pseudocode or otherwise, which
• inputs the marks for all students
• checks if each mark is in the correct range and, if not, the mark is re-input
• outputs the smallest mark
• outputs the highest mark
• outputs the average mark for the exam.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
42 | P a g e
Q8) Summer 2006
(a) A formula for calculating the body mass index (BMI) is:
Calculate the BMI for a person whose weight is 80kg and height is 2 meters.
(b) Using pseudocode or otherwise, write an algorithm that will input the ID, weight (kg)
and height (m) of 30 students, calculate their body mass index (BMI) and output their ID,
BMI and a comment as follows:
A BMI greater than 25 will get the comment ‘OVER WEIGHT’, a BMI between 25 and 19
(inclusive) will get ‘NORMAL’ and a BMI less than 19 will get ‘UNDER WEIGHT’.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
43 | P a g e
Q9) Winter 2006
Temperatures (°C) are being collected in an experiment every hour over a 200 hour
period.
Write an algorithm, using pseudocode or otherwise, which inputs each temperature and
outputs
• how many of the temperatures were above 20°C
• how many of the temperatures were below 10°C
• the lowest temperature that was input
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
44 | P a g e
Q10) Summer 2007
A company has 5000 CDs, DVDs, videos and books in stock. Each item has a unique 5-
digit code with the first digit identifying the type of item, i.e.
1 = CD
2 = DVD
3 = video
4 = book
For example, for the code 15642 the 1 identifies that it is a CD, and for the code 30055
the 3 identifies that it is a video.
Write an algorithm, using pseudocode or otherwise, that
• Inputs the codes for all 5000 items
• Validates the input code
• Calculates how many CDs, DVDs, videos and books are in stock
• Outputs the four totals.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
45 | P a g e
Q11) Winter 2007
(a) Fuel economy for a car is found using the formula:
Trace the flow chart using the numbers 2 and 3. Write down each of the values of N in
the orderthat they are printed out.
(a) 2 ................................................................................................................................[1]
(b) 3 ....................................................................................................................................[2]
71 | P a g e
Q2: Summer 2007
Study the following flowchart very carefully.
(a) Complete the following table showing the expected output from the flowchart for
the three sets of input data: [3]
INPUT X OUTPUT S
48
9170
- 800
(a) What output would be produced from the following input? [2]
Input Output
place hours (H) minutes (M) H M
Tokyo 11 15
Mumbai 15 10
73 | P a g e
(b) What problem would occur if place = Mumbai and H = 15 and M = 30?
………………………………………………………………………………………… [1]
(c) What problem would occur if place = Washington and H = 4 and M = 0?
………………………………………………………………………………………… [1]
Q4:Summer 2008
The following flowchart inputs two numbers, carries out a calculation and then outputs
the result.
(a)Complete the following table for the three sets of input data. [3]
INPUT OUTPUT
U V
5 5
6 -6
12 4
(b) The above algorithm has been placed in a library of routines. Give one advantage of
doing this.
………………………………………………………………………………………….……………
……………………………………………………………………………………………[1]
74 | P a g e
Q5: Summer 2009
Study the flowchart very carefully.
(a) Complete the table to show what outputs you would expect for the two inputs.[2]
Input N Output T
5
1
(b) Write down a possible LOOP construct for the section A to B in the flowchart using
pseudocode.
………………………………………………………………………………………………………
………………………………………………………………………………………………………
…………………………………………………………………………………………………... [2]
75 | P a g e
Q6: Winter 2009. P11
Study the flowchart.
Complete the table to show what outputs you would expect for the three inputs. [3]
INPUT N OUTPUT C
55
2100
1
76 | P a g e
Q7: Summer 2010 P12
Study the following flowchart very carefully:
What output would you expect if the following data was input into the flowchart? [3]
X OUTPUT
-150
540
0
`
77 | P a g e
Q8:Summer 2011 P11
Study the following flowchart very carefully:
78 | P a g e
(a) Complete the trace table for the following data set:
15, -2, 0, 8, 0, 21, -8, -12, 1, 25 [4]
Count Number Total X Average OUTPUT
(b) What values is output from the flowchart using given test data?
__________________________________________________________ [1]
81 | P a g e
Q 10:Winter 2011 P13
The following flowchart inputs the size of a number of car engines; a value of -1 stops
the input.
The following information is output: average engine size and number of engines with
size>5.
82 | P a g e
Complete the trace table for the following input data:
1.8, 2.0, 1.0, 1.3, 1.0, 2.5, 2.0, 1.3, 1.8, 1.3, -1
C L N S T A B
[6]
L = _________________
S = _________________
T = _________________ [2]
85 | P a g e
Q12:Winter 2012 P12
Study the following flowchart very carefully.
86 | P a g e
Complete the trace table for the following data:
15, 8, 251, 35, 60, 3, 2, 1516, 19, 55
S C N T OUTPUT
[5]
87 | P a g e
Q13: Winter 2012 P13
Study this flowchart very carefully.
88 | P a g e
Complete the trace table for the following data:
1500, 1000, 100, 10, 999, 99, 2000, 5, -3, 0
C H T1 T2 T3 Number OUTPUT
89 | P a g e
Q14:Summer 2012. P12
Carefully study the following flowchart:
90 | P a g e
(a) Complete the trace table for the following data: [4]
1, 0, 1, 1, 0, 1
M T S C D
b) What values are outputs from the following flowchart using the above test data?
.............................................................................................................................................
(c) What function is this flowchart carrying out?
.............................................................................................................................................
.............................................................................................................................................
(d) What would happen if the value X wasn’t set to 0 in the return loop of the flowchart?
.............................................................................................................................................
.............................................................................................................................................
95 | P a g e
Q17: Summer 2014. P11
Study the following flowchart very carefully.
96 | P a g e
becomes:
(b) Use the information in the flowchart to show which input message produced the
following encrypted message:
(b) This flowchart does not give correct answers for certain sets of test data.
Suggest a data set that would give an incorrect answer.
Give a reason for your choice.
data set
.............................................................................................................................................
..............................................................................................................................
reason
.............................................................................................................................................
......................................................................................................................... [2]
103 | P a g e
Q21: Winter 2014 P12
Study the following flowchart very carefully.
104 | P a g e
Complete the trace table for this flowchart using the following data:
4, 3, 2, 0, 0, 8
5, 0, 1, 2, 3, 4
0, 0, 0, 0, 0, 0
sum1 sum2 total a b c d e f OUTPUT
X=X+1
Marking Schemes UNTIL X = N + 1
Q1) (a) 1 [1](b) 10,5,16,8,4,2,1 one mark one mark [2] OR
Q2)(a) 2, 4, 1 [3] WHILE X<> N + 1 DO
(b) (i) Any one point from:
(T = T * X)
computer check on input data check data is wrong/correct = 0
X=X+1
detects any data which is incomplete or not reasonable
(ii) Any one point from: ENDWHILE
length check – e.g. only 30 characters in name field (1 mark for correct first line of loop construct)
character check – e.g. name doesn’t contain numeric chars (1 mark for correct loop control and last line of loop construct) [2]
range check – e.g. day of month in date is between 1 and 31 Q6) 2
format check – e.g. date in the form xx/yy/zz 4
check digit – e.g. end digit on bar code to check if it is valid 1 [3]
type check – e.g. integer, real Q7) Expected output:
(presence check = 0) [2] 1
Q3) (a) H M 2
18 15 Error
18 40 [2] Q8)
(b) Any one point from: Count Number Total X Average OUTPUT
M would become 60 and should be 0 for correct time 1 0 0
H would become 18 and should be 19 for correct time [1] 2 15 15 1
(c) Would get a negative answer for H [1] 3 -2
Q4)9 (a) 2.5, Error, 3 [3 4 0
(b) Any one from: 5 8 23 2
would be fully tested 6 0
doesn't need to be re-written each time section of program needed [1] 7 21 44 3
8 -8
Q5) (a) 120 9 -12
1 [2] 10 1 45 4
(b) FOR X = 1 TO N + 1 11 25 70 5 14 14
(T = T * X) (b) Find the average of all positive numbers entered [1]
NEXT X
OR
REPEAT
(T = T * X)
106 | P a g e
Q14) Q17)
M T S C D Number Product Value OUTPUT
5 1 5
32 1 0 1 1 (5) 5 4
16 32 32 2 (5) 20 3
(5) 60 2
8 0 32 3 0
(5) 120 1
4 8 40 4 1 (5) (120) 0
5, 120
2 4 44 5 1
1 0 44 5 1 Q18) (NOTES: Additional 0s in any column (UNLESS THEY ARE JUST THE
REPEAT OF 0 VALUES) lose the mark for that column.
1 45 7 1 If columns 1 to 7 are wrong there can be one mark for initialisation (0 0 0 0 0
(b) converting binary number into equivalent base 10 number [1] 1) and a mark forthe correct output -3, 6).
(c) 60 [1] negcou poscou neg pos zero co X negavge posavge
Q16) nt nt unt
A B C D E K X 0 0 0 0 0 1
3 5 1 4 8 0 0 1 2 0
5 3 3 1 1 3 3 3
4 1 1 1 2 8 4 5
8 1 1 1 3 14 5 6
0 1 -4 6 -4
4 3 3 1 2 -5 7 -1
8 3 3 1 2 8 0
0 3 9 0
8 4 4 1 3 -9 10 -4
0 4 24 11 1
8 5 5 1 0
0 -3 6
(b) 8, 5, 4, 3, 1 [1]
(c) SORT/ORDER (descending) routine [1]
(d) – would continue looping round even when sorting complete
– loop would never end/infinite loop [1]
108 | P a g e
Q19) If no marks are awarded for the columns then 1 mark can be given for
correct initialisation ofT1, T2 & T3 as shown in the first row above. [5]
(b) – any data set (except 0, 0, 0) where 2/3 of the numbers are the same e.g.
2, 8, 8
– flowchart does not allow for numbers which have the same value [2]
Q21) NOTE: sum1, sum2 and total MUST be initialised for all three inputs
to get the mark; allow repetition in any of the columns EXCEPT the
(c) Any three from: OUTPUT column (e.g. sum1 can be 0, 47, 47, 47, 47, 47, 47);
– customers need a password / PIN sum1 sum2 total a b c d e f OUTPUT
– use of card readers / use of Transaction Authentication Number (TAN) 0 0 0 4 3 2 0 0 8
47 8 55
– only certain characters from password / PIN requested…
44
– …the requested characters change each time user logs on 33
– card security code requested 22
– use of drop down boxes 11
– use of a customer reference number 0 Data are
ok
– inform customer when they last logged on to the website 0 0 0 5 0 1 2 3 4
– use of image verification code e.g. CAPTCHA 34 16 50
– make reference to something unique to the customer e.g. their mobile 39
phone number 28
17
– use of secure protocol e.g. https, padlock symbol[3]
6
Q20) -5 Error
T1 T2 T3 A B C OUTPUT 0 0 0 0 0 0 0 0 0
0 0 0
3 2 1
1
1 4 8 7
2 6 0 3
1 5 6 9
2 4 11 3
0 0 0
2, 2, 1
Fill in missing statements
Questions are most commonly set from steps of bar code reading, sensors,
operating ATM machine etc.
Steps of bar code reading:
When barcode has been read, then what happens?
• The barcode number is looked up in the stock database (the barcode is known as the
KEY FIELD in the stock item record); this key field uniquely identifies each stock item.
• When the barcode number is found, the stock item record is looked up.
• The price and other stock item details are sent back to the checkout (or POINT
OFSALE TERMINAL (POS)).
• The number of stock items in the record is reduced by one each time the barcode is
read.
• This new value for number of stock items is written back to the stock item record.
• The number of stock items is compared to the re-order level; if it is less than or equal to
this value, more stock items are automatically ordered.
• Once an order for more stock items is generated, a flag is added to the record to stop
re-ordering every time the stock item barcode is read.
• When new stock items arrive, the stock levels are updated in the database.
110 | P a g e
Q1: Winter 2006
The following flowchart shows how the bar code written on an item is used to find the
price, do stock control and produce an itemised bill. Select statements from the list below
to complete the flowchart.
111 | P a g e
Q2: Winter2011 P11
The following flowchart shows how barcodes are used at the point of sale in an
automatic stock control system.
Select statements from the list below, using numbers only, to complete the flowchart.
112 | P a g e
Q3: Winter 2008
The following flowchart shows how sensors (which can be analogue or digital) and a
computer are used to control the temperature of a greenhouse for plants. Complete the
flowchart using the items from the list below.
113 | P a g e
Q 4Summer 2009
The following flowchart shows what happens when a customer uses a credit card to pay
forgoods at a supermarket. Ten of the boxes are blank.
Using the items from the list, insert the ten missing statements using the
appropriatenumber only. Each statement may be used once only.
114 | P a g e
Q5: Winter 2010. P11
(a)To log on to a computer, a user needs to type in a user id followed by a password;
these should match up. Only three attempts are allowed.
The flowchart below shows the log on procedure. Several boxes have been left blank.
Complete the flowchart using items from the list.
115 | P a g e
Q 6: Summer 2012. P11
A car park uses sensors and a microprocessor to monitor cars leaving and entering. The
car park is open 24 hours every day. The park fee is $10 per day.
The following flowchart shows how the IN and OUT barriers are controlled. Some of the
statements are missing.
Using item numbers only, insert the correct item number into the flow chart from the item
list.
116 | P a g e
List of statements
Number Description
1 activate motor to raise IN barrier
2 activate motor to raise OUT barrier
3 any signal received from OUT sensor?
4 decrease number of cars in car park by 1
5 increase number of cars in car park by 1
6 is car park full?
7 is the car park fee paid?
8 OUTPUT “car park full”
9 OUTPUT “please pay car park fee at pay machine”
10 use ADC to convert IN sensor signal to digital
11 use ADC to convert OUT sensor signal to digital
12 use DAC to convert computer signal to analogue signal to operate IN barrier
13 use DAC to convert computer signal to analogue signal to operate OUT barrier
14 wait 30 seconds and then close barrier [6]
117 | P a g e
Q7:
118 | P a g e
Q8:Summer 2013 P11
A customer uses Internet banking. To gain access to their account they need:
• an 8-digit ID
• a 4-digit PIN
• a 10-character password
They will be asked to type in their ID, then 3 digits from their PIN and finally 3 characters
from their password. Three attempts at the ID are allowed, but only one attempt at the
PIN and at the password.
The flowchart on the next page shows the access process described above. However,
most of the stages have been omitted.
Complete the flowchart, using item number only, from the list of items given.
119 | P a g e
Q9: Summer 2013. P12
120 | P a g e
Q10: Winter 2013. P13
A microprocessor controls the opening and closing of automatic doors to a
supermarket.Customers are detected using pressure sensors.
The flowchart on the next page shows how the sensors and microprocessor
interacttocontrol the opening and closing of the doors. However, several of the stages in
the processhave been missed out.
Using item number only, complete the flowchart using items from the following list:
121 | P a g e
Q11 :Summer 2014. P11
A heating system is being controlled by sensors and a computer. The temperature must
be keptbetween 15°C and 25°C. If 30°C is exceeded a warning message is generated
and the systemshutsdown.A flowchart of the process is shown below. Some of the items
are missing.Complete the flowchart, using item number only, from the list of items given.
122 | P a g e
Q12: Summer 2014
An algorithm has been written to check that code numbers are valid on input. They must
be in therange 1000 to 9999.
Five hundred codes are being entered and the percentage of entered codes which are
incorrectis output.
There is a flowchart on the opposite page. It has some statements missing.
Complete the flowchart. Use statement numbers only, chosen from the list below.
123 | P a g e
(b) Two devices used by the supermarket Point-Of-Sale (POS) terminal are a barcode
reader and a keyboard.
Name two other input/output devices used at the POS and give a use for each device.
device 1 .............................................................................................................................
use.......................................................................................................................................
............................................................................................................................................
device 2 ...............................................................................................................................
use ......................................................................................................................................
............................................................................................................................................
.........................................................................................................................................[4]
124 | P a g e
Q14: Summer 2014 P11
A heating system is being controlled by sensors and a computer. The temperature must
be kept between 15°C and 25°C. If 30°C is exceeded a warning message is generated
and the system shuts down.
A flowchart of the process is shown below. Some of the items are missing.
Complete the flowchart, using item number only, from the list of items given.
125 | P a g e
Q15:
An algorithm has been written to check that code numbers are valid on input. They must
be in the range 1000 to 9999.
Five hundred codes are being entered and the percentage of entered codes which are
incorrect is output.
There is a flowchart on the opposite page. It has some statements missing.
Complete the flowchart. Use statement numbers only, chosen from the list below.
126 | P a g e
Q16
An algorithm has been written to input six temperatures for every day of the year (365 days). The
outputs are:
• the average daily temperature for each day
• the highest recorded temperature for the whole year
The algorithm is in the form of a flowchart on the next page. However, several of the statements
are missing.
Using instruction number only, complete the flowchart using the following list of instructions:
Marking Scheme
Q1)
128 | P a g e
Q13
Q14)
2.2 Programming
Visual Basic .NET (VB.NET) is an object-oriented computer programming language
implemented on the .NET Framework. Although it is an evolution of classic Visual Basic
language, it is not backwards-compatible with VB6, and any code written in the old
version does not compile under VB.NET. Like all other .NET languages, VB.NET has
complete support for object-oriented concepts. Everything in VB.NET is an object,
including all of the primitive types (Short, Integer, Long, String, Boolean, etc.) and user
defined types, events, and even assemblies. All objects inherit from the base class
Object.
VB.NET is implemented of Microsoft's .NET framework. Therefore it has full access all
the libraries in the .Net Framework. It's also possible to run VB.NET programs on Mono,
the open-source alternative to .NET, not only under Windows, but even Linux or Mac
OSX.
The following reasons make VB.Net a widely used professional language:
Modern, general purpose.
Object oriented.
Component oriented.
Easy to learn.
Structured language.
It produces efficient programs.
It can be compiled on a variety of computer platforms.
Part of .Net Framework.
Strong Programming Features VB.Net
VB.Net has numerous strong programming features that make it endearing to multitude
of programmers worldwide. Let us mention some of these features:
Boolean Conditions
Automatic Garbage Collection
Standard Library
Assembly Versioning
Properties and Events
Delegates and Events Management
Easy to use Generics
Indexers
Conditional Compilation
Simple Multithreading
130 | P a g e
VB.NET – ENVIRONMENT
Integrated Development Environment (IDE) For VB.Net
Microsoft provides the following development tools for VB.Net programming:
Visual Studio 2010 (VS)
Visual Basic 2010 Express (VBE)
Visual Web Developer
The last two are free. Using these tools you can write all kinds of VB.Net programs from
simple command-line applications to more complex applications. Visual Basic Express
and Visual Web Developer Express edition are trimmed down versions of Visual Studio
and has the same look and feel. They retain most features of Visual Studio. In this
tutorial, we have used Visual Basic 2010 Express and Visual Web Developer
If you don’t run Windows as your operating system you can try using Mono
http://www.go-mono.com/mono-downloads/download.html
Console Application
A VB.NET console application uses a command line window for its user interface.
Because there is no opportunity for the user to provide inputs other than those asked for
by the program, a console application is not “event driven”. The actions performed in the
program must follow in a linear fashion, and are completely defined by the program, and
thus the programmer. This “procedural” programming is limiting, but makes a good
introduction since the complexity of the user interface is eliminated.
1. Start Microsoft Visual Studio.NET. Note that it is not listed as Visual Basic.NET. Visual
Studio.NET supports other programming languages other than VB. A Start Screen is
displayed to help you open new or existing VB projects.
5. Enter ConsoleTut as the name of the project. All the files associated with the project
will be stored in a folder as indicated in the Location text box (note this so you can find it
later). Click OK to create the project.
6. The VS (Visual Studio) IDE (Integrated Development Environment) is where you build
your program. You can actually create any VB program in Notepad, but the IDE provides
a large number of tools that greatly simplifies the process of creating a Windows
program.
132 | P a g e
7. For this tutorial, you can ignore most of the windows and tools in the IDE. The Solution
Explorer in the top right corner of the IDE shows the files associated with the project. The
console application template provides the required files. The Module1.vb file is the active
file, and its contents are shown in the editor window.
8. The code contained within the Module1.vb file is listed between the two statements:
Module Module1
End Module
The module currently contains a single subroutine (don’t worry too much about terms just
yet) called Main. The code inside the Main subroutine is automatically “run” when the
program starts. You will add all the code for this tutorial in between the Sub Main() and
End Sub statements.
133 | P a g e
Tools: (Console.ReadLine for Input, Console.WriteLine for Output)
The console application simplifies input and output in that the user interface is essentially
text based. The user types in the input, and the output is posted to the same text
window. This text window is referenced in your program code by using the keyword
Console. Three “actions” associated with the Console object enable you to receive input
(ReadLine) and output (Write and WriteLine) text characters to the console window.
Basic data types
In order for a computer system to process and store data effectively, different kinds of
data are formally given different types. This enables:
data to be stored in an appropriate way, for example, as numbers or characters
data to be manipulated effectively, for example numbers with mathematical
operators and characters with concatenation
automatic validation in some cases.
INTEGER
An INTEGER is a positive or negative whole number that can be used with mathematical
operators.
SINGLE
A Single is a positive or negative number with a fractional part. Single numbers can be
used with mathematical operators. (In pseudocode REAL data type is used for numbers
with fractional part)
CHAR
A variable or constant of type CHAR is a single character.
Gender = 'F'
STRING
A variable or constant of type STRING is several characters in length. Strings vary in
length and may even have no characters: an empty string. The characters can be letters
and/or digits and/or any other printable symbol.
BOOLEAN
A BOOLEAN variable can have only two values: TRUE or FALSE.
Variables:
A variable is a named location in the computer’s memory that stores a certain type of
data (character, string of characters, integer, real number, and so on). The variable is
identified in the program by a unique name.
The values stored in any variable are changed during execution of program.
By storing each of the inputs in memory (in a variable), you can use them again and
again within the program without requiring that the user re-input them.
134 | P a g e
Variable Declaration:
Before variables can be used to store data, they must be “Declared”. These reserves the
appropriate amount of memory to store the value assigned to the variable.
In the editor window, below Sub Main() but above End Sub, type:
Constant:
A constant is a memory location in which stored values remain unchanged during
execution of program.
Array:
Data stored in a computer is stored at any location in memory that the computer decides
to use, which means that similar pieces of data can be scattered all over memory. This,
in itself, doesn’t matter to the user, except that to find each piece of data it has to be
referred to by a name (known as a “variable name”). For example, if we want to store the
20 names of students in a group then each location would have to be given a different
variable name. The first, “Abdullah”, might be stored in location Name1, the second,
“Rumaisa”, might be stored inName2 , the third, “Rashid”, could be stored in
Name3.Creating the 20 different variable names is possible but these names are
separate (as far as the computer is concerned) and do not relate to each other in any
way. It would be far more sensible to force the computer to store them all together using
the same variable name. However, this doesn’t let me identify individual names. If I call
the first one, Name(1) , the second one Name(2) and so on, it is obvious that they are all
people’s names and that they are distinguishable by their position in the list. A list like
this is called an array.
135 | P a g e
Each element in the array is identified using its subscript or index number. The largest
and smallest index numbers are called the upper bound and lower bound of the array.
Name
1 Abdullah
2 Rumaisa
3 Rashid
4 Muzna
5 Laiba
6 Patel
7 Smith
19 Mani
20 Ghayas
Declaring an array
It is important declare the arrays before assigning values in it so that program can
reserve that amount of space in its memory; otherwise, there may not be enough space
when the program uses the data.
Declaration consists of telling the computer program:
the identifier name of the array
the sort of data that is going to be stored in the array, i.e. its data type
Howmany items of data are going to be stored, so that it knows how much space to
reserve.
Different programming languages have different statements for initialising the array but
they all do the same thing. In Visual Basic, the statement is:
Dim Name(20) As String
This Dim statement declares:
● the identifier name: Name
● the upper bound: 20
● the data type: String.
The upper bound of 20 specifies that there can be a maximum of 21 data items,
since Visual Basic starts with a subscript of zero. We do not have to fill the array;
the upper bound of 20 indicates the maximum size.
The array that has been described in one dimension array so far is really only a list of
single data items. It is possible to have an array which can be visualised as a two-
dimensional table with rows and columns and a data value in each cell.
136 | P a g e
Reading data into an array
To assign data values to the elements of the array, we do this with assignment
statements such as:
Name(6) = “Patel”
This places the string “Allan” at index position 6 in the array.
Similarly, the following statement places the string “Rashid” at index position 3 in the
array.
Name(19) = “Mani”
First program
Start a new Project and select Console Application. Type the following code:
module module1
sub main()
console. writeline("In the name of Allah”)
Console.writeline(“Hello World!")
console. readKey()
end sub
end module
(Press F5 to run the code)
Tasks
0.1 – Write a program that displays the message “Asslam-o-Alaikum”
0.2 – Write a program that displays the message “My name is Muhammad and I live in
Brussels” (replace Dave and Brussels with your own information)
0.3 – Write a program that displays the lyrics to your national anthem. Each line of the
song should be on a fresh line.
Example Program 1 - Assignment - Integer, byte, real, Boolean, character, string,
date/time.
Module Module1
Sub Main()
Dim theNumber As Integer
Dim theWord As String
theWord = "Bird"
theNumber = 9
Console.ReadKey()
theWord = "Cat"
Console.WriteLine("Enter a number>")
theNumber = Int(Console.ReadLine())
Console.WriteLine("Now " &theWord& " is the word and the number is " &
theNumber)
Console.ReadKey()
137 | P a g e
End Sub
End Module
Module Module1
Sub Main()
Dim number1, number2, total As Integer
Console.ReadKey()
End Sub
End Module
Tasks
3.1) Write a program that divides a number entered by the user by 2
3.2) Write a program that displays the 7 times table
3.3) Write a program that displays any times table the user requests
System.Console.WriteLine("Enter an integer…")
intInput = Val(System. Console.ReadLine())
If intInput = 1 Then
System.Console.WriteLine("Thank you.")
ElseIfintInput = 2 Then
System.Console.WriteLine("That's fine.")
ElseIfintInput = 3 Then
System.Console.WriteLine("Too big.")
Else
System.Console.WriteLine("Not a number I know.")
End If
Console.ReadKey()
Tasks
1. Write a program to ask the user what 24+9 is. Say “Excellent” if they get it right.
2. Write a program to ask the user “how many in a baker’s dozen?” and say
“mostexcellent” if they get it right.
3. Write a program to ask the user to enter their age. If their age is under 18 then
say“Sorry, this film is not for you”.
138 | P a g e
4. Write a program to ask the user for two numbers. Compare the first with the second
and then print out one of three messages. Either the numbers are equal, the first
isbigger, or the second is bigger. You will need more than one IF to solve this one.
5. Write a program which asks the user to enter their password. If they enter the
word“PASSWORD” then display the message “Welcome to the treasure”,
otherwisedisplay a message which says “go away, it’s all mine”.
6. Write a program which asks the user to enter a number between 1 and 10. If
thenumber entered is out with this range then display a message “Sorry…out of range”.
Example Program 4 - Relational operators - =, <, >, <>, <=, >=
Module Module1
Sub Main()
Dim age As Integer
Console.WriteLine("What is your age?")
age = Int(Console.ReadLine())
If age > 16 Then
Console.WriteLine("You can drive!")
Else
Console.WriteLine("You are too young to drive")
End If
Console.ReadKey()
End Sub
End Module
The symbols we can use to test for conditions are as follows:
< Less than
<= Less Than or Equal To
> Greater than
>= Greater Than or Equal To
== IS Equal To
!= or <> Not Equal To
Module Module1
Sub Main()
Dim age, points As Integer
Console.WriteLine("What is your age?")
age = Int(Console.ReadLine())
Console.WriteLine("How many points do you have on your licence?")
points = Int(Console.ReadLine())
If age > 16 And points < 9 Then
Console.WriteLine("You can drive!")
Else
Console.WriteLine("You are not eligible for a driving licence")
End If
Console.ReadKey()
139 | P a g e
End Sub
End Module
Console.ReadKey()
Tasks
1) Write a program that asks for 5 numbers, calculates the mean average and then rounds it
down. Display the result on screen.
Tasks
1. Write a program that checks a username against a stored value. How the user enters the
username should NOT be case sensitive.
2. Adapt program 1 so that it also takes in a password. If the user enters spaces after the
password the computer will trim them out automatically.
3. Write a program that will check a phone number is of the correct length.
4. Write a program that asks for a user’s full name in one inputbox/textbox but then stores the
first and second names in different variables.
Example Program 8 – Repetition
140 | P a g e
Module Module1
Sub Main()
Dim theNumber As Integer
theNumber = 7
'a loop
For x = 1 To 10
Console.WriteLine("7 x " & x & " = " & (7 * x))
Next
'the end of the loop
Console.ReadKey() 'pause so user can see
End Sub
End Module
Tasks
1. Write a program which asks for your name and then displays it 5 times on the screen.
2. Write a program to display the name of the town you live in 10 times.
3. Write a program to ask for a person’s favourite CD and the artist. Both should be
displayed on the same line 5 times.
4. Write a program to ask for a number and display its multiplication table 1 to 100
5. Write a program that asks the user for a number 5 times and adds them all up to give
a total.
ConstconMaxPlanets As Integer = 9
'string constants
ConstconVersion = "07.10.A"
ConstconCodeName = "Enigma"
' try assigning a new value to one of your constants
'to make a constant available to the whole program "Public" should precede it
'and it should be placed inside the module but outside the procedure
'try it
'there are string constants created by VB
Console.WriteLine("Pi is" &conPi)
Console.WriteLine("Pi is" &vbCr&conPi)
Console.WriteLine("Pi is" &vbTab&conPi)
Console.ReadKey()
141 | P a g e
Example Program 10 – 1 dimensional arrays
Tasks
1) Write a program which will set up an array to hold 50 numbers. Call the array numbers.
Display
the array's contents across the screen. They should all be 0.
2) Create a program that stores an array of car records. At least 5 cars and 4 fields per record.
3) Create a program that stores an array of 5 people records. The information should be entered
by
the user.
4) Adapt program 2 to now do a linear search for a certain car and display its details.
Tasks
1) Write a program that validates a user is old enough to drive (older than 17, younger than 80)
2) Write a program that checks that a telephone number entered is long enough (string length)
3) Write a program that checks that both a username and password is correct before allowing
you to proceed.
142 | P a g e
Example Program 12 – Read from a text file
Dim objStreamReader As IO. StreamReader
Dim strLine As String
'Pass the file path and the file name to the StreamReader constructor.
objStreamReader = New IO. StreamReader("H: \Diary.txt")
'Read the first line of text.
strLine = objStreamReader.ReadLine
'Continue to read until you reach the end of the file.
Do While Not strLineIs Nothing
'Write the line to the Console window.
Console.WriteLine(strLine)
'Read the next line.
strLine = objStreamReader.ReadLine
Loop
'Close the file.
objStreamReader.Close()
Console.ReadLine()
Tasks
1) Write a program that reads the students’ names from a txt file and displays them on the
screen
2) Write a program that reads 10 team names from a txt file and stores them in an array
3) Write a program that reads 5 song titles from a csv file and displays them on the screen
4) Write a program that reads 20 team names from a csv file into an array, then displays the
array on screen
143 | P a g e
PRE-RELEASE MATERIAL MAY/JUNE 2016
In preparation for the examination candidates should attempt the following
practical tasks by writing and testing a program(s)
The manager of a building materials delivery service needs a program to
check the contents and weight of sacks to ensure that correct orders are
made up for delivery. A price for the order will be calculated.
Write and test a program for the manager
Yourprogram must include appropriate prompts for the entry of data.
Error messages and other output need to be set out clearly.
All variables, constants and other identifiers must have meaningful names.
TASK 1-check the contents and weight of a single sack
Each sack must obey the following rules to be accepted:
Contain cement, gravel or sand, with a letter on the side for easy identification
o C-cement
o G-gravel
o S-sand
Sand and gravel must weigh over 49.9 and under 50.1 kilograms
Cement must weigh over 24.9 and under 25.1 kilograms
Input and store the weight and contents for one sack. The contents must be
checked and an incorrect sack rejected. The weight must be validated on
entry and an overweight or underweight sack rejected.
Output the contents and weight of an accepted sack. If a sack is rejected,
output the reason(s).
TASK 2- check a customer’s order for delivery
Input and store the number of sacks for each type required for the order. Use
TASK 1 to check the contents and weigh of each sack. Ensure that the
delivery contains the correct number and type of sacks for the order.
Output the total weight of the order.
Output the number of sacks rejected from the order.
TASK 3- calculate the price for a customer’s order
Extend TASK 2 to calculate a price for an order. Prices for the sacks are as
follows:
Regular price for each sack
o Cement,$3
o Gravel,$2
o Sand,$2
Discount price for a special pack containing 1 sack of cement,2 sacks of sand
and 2 sacks of gravel,$10.
Calculate and output the regular price for the order. Check how many special
packs are in the order. If a discount price applies then output the new price for
the order and the amount saved.
144 | P a g e
Sub Main()
Dim Content AsChar
Dim Weight AsSingle
EndSelect
Console.ReadKey()
EndSub
EndModule
146 | P a g e
CountRejected 0
CDeliver 0
SDeliver 0
GDeliver 0
TWeight 0
WHILE CDeliver < COrder OR SDeliver < SOrder OR GDeliver < GOrder DO
PRINT“Enter content of sack to deliver“
READ Content
IF CDeliver < COrder AND Content = "C"THEN
PRINT“Enter weight of sack of cement “
READ Weight
CASE OF Weight
<=24.9, >=25.1: CountRejected CountRejected + 1
PRINT“Rejected due to invalid weight“
OTHERWISE: CDeliver = CDeliver + 1
TWeight = TWeight + Weight
ENDCASE
ELSEIF GDeliver < GOrder AND Content = "G"THEN
PRINT“Enter weight of sack of gravel “
READ Weight
<=49.9, >=50.1: CountRejected CountRejected + 1
PRINT“Rejected due to invalid weight “
OTHERWISE: SDeliver = SDeliver + 1
TWeight = TWeight + Weight
ENDCASE
147 | P a g e
ELSEIF SDeliver < SOrder AND Content = "S"Then
PRINT“Enter weight of sack of sand “
READ Weight
<=49.9, >=50.1: CountRejected CountRejected + 1
PRINT“Rejected due to invalid weight“
OTHERWISE: GDeliver = GDeliver + 1
TWeight = TWeight + Weight
ENDCASE
ELSE
CountRejected CountRejected + 1
PRINT“Rejected due to completed order or invalid content “
ENDIF
ENDWHILE
PRINT "Total Rejected " ,CountRejected
PRINT"Total weight delivered " , TWeight)
148 | P a g e
/04
'Declaration of constants
Const CPrice = 3
Const GPrice = 2
Const SPrice = 2
Const SpecialPrice = 10
Variable 1: ..........................................................................................................................
Use: ....................................................................................................................................
...........................................................................................................................................
Variable 2: ..........................................................................................................................
Use: ....................................................................................................................................
.......................................................................................................................................[4]
(b) Write an algorithm to complete Task 1, using either pseudo code and programming
statements.
Pseudo code: ..................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Programming statements.............................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.................................................................................................................................................. [5]
152 | P a g e
(c) (i) Explain how you completed Task 3. You can include pseudocode or programming
statements as part of your explanation. You should assume that Task 2 has been
completed. [5]
(ii) Comment on the efficiency of your design for Task 3.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(b) Write an algorithm to complete Task 2, using either pseudocode, programming statements or
a flowchart.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[5]
(c) (i) Explain how you completed Task 3. You should assume that Task 2 has been completed.
You can include pseudocode or programming statements as part of your explanation.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[6]
(ii) Comment on the efficiency of your design for Task 3.
...........................................................................................................................................
...........................................................................................................................................
....................................................................................................................................... [1]
(iii) Give two sack weights that you could use to check the validation used in Task 1. Explain why
you chose each weight.
Weight 1 ............................................................................................................................
Reason for choice .............................................................................................................
...........................................................................................................................................
Weight 2 ............................................................................................................................
Reason for choice .............................................................................................................
.......................................................................................................................................[4]
153 | P a g e
2.3 Database
• definea single-table database from given data storage requirements
• choose and specify suitable data types
• choose a suitable primary key for a database table
• perform a query-by-example from given search criteria
Examples:
phone book
address book
Census Bureau data
Database record
Data in a database table is organised into rows (records) and columns (fields). Each
record in a relational database table corresponds to an entity. In the example table of
'Students' above there are 5 records. Each record corresponds to an individual student.
Note that although there are two students called Philip Barker with the same date of
birth, they have different Student IDs and are different students.
Database field
An attribute is a piece of information or a characteristic of an entity. Attributes of entities
are represented in database tables by fields (columns). A field stores one item of data for
a record. In the table above, each student is represented in the relational database by a
record and the student attributes are stored in the following fields:
Student ID
Forename
Surname
Date of Birth
Fields have the following characteristics:
Each field in a table has a unique name. Note, however, that the same field name can
occur in other tables of the same relational database.
Each field stores a single item of data - For example, a field called Date of Birth would
store no more than one date of birth value.
Each field has a particular data type – for example, text, Boolean, integer, date/time,
etc.
Each field can have its own validation rules - these ensure that data recorded in the
field is of the right type and format.
Data types
Different data types are identified so that a computer can store and process the data
155 | P a g e
appropriately.
Data types include:
text (or string)
number (numeric) may include:
o Auto number
o Currency
date/time
Boolean (or Yes/No).
Primary Keys
Each table has a primary key. This is a field chosen so that it can uniquely identify each
record.
Sometimes an existing attribute can be used because it is unique but most of the time
some sort of ID is created. Primary keys can be used to link to foreign keys in other
tables. A foreign key is the primary key in a different table and it is not necessarily
unique.
Example Question:
A picture gallery owner has decided to set up a database to keep information about the
pictures he has for sale. The database table, PICTURE, will contain the following fields:
Title; Artist; Description; Catalogue Number; Size (area in square centimeters); Price;
Arrived (date picture arrived at gallery); Sold (whether picture is already sold)
(a) (i) State what data type you would choose for each field.
Title: ..............................................................................................................
Artist: ...........................................................................................................
Description: ..................................................................................................
Catalogue Number: .......................................................................................
Size: .......................................................................................................
Price: ..........................................................................................................
Arrived: .........................................................................................................
Sold: ........................................................................................................[4]
(ii) State which field you would choose for the primary key...................[1]
Query
The prime function of a relational database is to store data in an organised way so that
users can interrogate (search) and manipulate (sort) the data. The interrogation of a
database is called querying the database and a question used to interrogate the data is
called a query.
Query by Example (QBE) is a database query language for relational databases. It was
devised by Moshé M. Zloof at IBM Research during the mid-1970s, in parallel to the
development of SQL. It is the first graphical query language, using visual tables where
the user would enter commands, example elements and conditions.
Databaseuser-interface in which the user fills out a form to retrieve data. The database
makes the search on the basis of the example(s) provided by the user.
156 | P a g e
The query to find students in form 10B
A complex query looks for data in two or more fields and uses the logical operators OR,
AND or NOT.
The following example uses a complex query to find all of the pupils in Form 10B who
were born before 1995. This query uses the logical operator AND:
(Form = “10B”) AND (Date of Birth < 01/01/1995).
Operators can be used to refine search results.
Operator Meaning
= Equals
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
<> Not equal to
The query design is shown below. Note that this time there are two entries in the search
criteria row Also note that this time the query has been given a meaningful name
(“Select Query – Pupils in 10B born before 1995”). This saves other database users
from unnecessarily creating the same query.
157 | P a g e
Below is a new complex query that uses the logical operator OR to find pupils who are in
Form 10A or Form 10C: (Form = “10A” OR “Form = “10C”) This time, in the query
definition there will be two criteria lines. The query and its results are shown below:
Wildcards in Queries
Wildcard characters can be used in database queries. For example you may want a list
of all pupils born in November, or all of the pupils whose surname starts with a ‘C’.
Wildcard searches allow you to specify the part of the data that you know and leave the
data handling software to fill in the blanks.
Surname Like “C*” would find all records where the surname begins with a C.
Example Question:
A database was set up to compare oil companies. A section of the database is shown
below:
158 | P a g e
(a) Complete the query-by-example grid below to show no. of employees, head office
and profit, have a No of countries greater than 40 and Head office is Europe?
A survey of motorways was carried out and a database was produced. A section of the
database is shown below.
(a) How many fields and how many records are shown?
(i) number of fields ............................................................................................................
159 | P a g e
(ii) number of records ..................................................................................................... [2]
(b) Complete the query-by-example grid below to show Motorway ID and Lanes if the
(d)Complete the query-by-example grid below to show the motorways where the number
of cars perday exceeds 50 000 or the toll charge per kilometer is greater than $0.50?
Patient’s height
Patient ID
Contact
telephone
number
Marking scheme
Field Name Name of validation check Example of data which would fail the
validation check
Date of visit format check e.g. 2012/12/04
type/character check e.g. 3rd March 2012
Patient’s height range check can’t be < 0 or > 2.5m
limit check e.g. –5, five
e.g. 8, -3,
Patient ID type check (can’t be < 0 or > 99999999)
length check e.g. 3142ABCD
range check e.g. 2131451, 136498207
e.g. –3, 851341625
Contact length check e.g. 0773141621834
telephone type/character check e.g. 7H215GD
format check e.g. 01223/123456/8901234
number
Q2) The terms file, record and field are used in databases. Explain the meaning of each
term and explain the connections between them; you may wish to include a diagram.
.............................................................................................................................................
.............................................................................................................................................
.............................................................................................................................................
Q3)An estate agent uses a computer system to store details about properties for sale. A
section of the properties file is shown below:
162 | P a g e
Property Type Area Price
4217 D Lake 99.92
4219 D Park 200.00
4220 S Lake 105.50
4221 F Park 175.25
4222 F Town 75.00
a Why is coded data used for Type?
.............................................................................................................................................
.............................................................................................................................................
b What is the data type for Price?
.............................................................................................................................................
.............................................................................................................................................
c What is meant by a key field? Which is the key field?
.............................................................................................................................................
.............................................................................................................................................
Q4) Explain the following terms:
database: ........................................................................................................................
.............................................................................................................................................
file: ....................................................................................................................................
.............................................................................................................................................
record ...............................................................................................................................
.............................................................................................................................................
Q5) A shop sells bicycles. Information about each bicycle in stock is held in a computer
file. Part of the information is shown in the table below.
.............................................................................................................................................
.............................................................................................................................................
.............................................................................................................................................
.............................................................................................................................................
Q7) A teacher uses a database to store the marks of pupils from all year 9 classes.
(a) PUPIL and CLASS are two entities used in this database.
Explain the term entity.
.............................................................................................................................................
.............................................................................................................................................
.............................................................................................................................................
........................................................................................................................................ [2]
(b) The data for the first four pupils in the PUPIL table is shown below.
(i) State the primary key for the PUPIL table and explain your answer.
Primary Key ..................................................................................................................[1]
Explanation
.............................................................................................................................................
.................................................................................................................................... [2]
164 | P a g e
(ii) The database also contains a CLASS table. The primary key for the CLASS table is
ClassCode.Explain why ClassCode has also been included in the PUPIL table.
.............................................................................................................................................
.........................................................................................................................................
...................................................................................................................................... [3]
Q8)An MP3 player contains a database of songs. This database has only one table. A
sample of the data in this table is shown below.
TrackNo Artist Song Length TimesPlayed Protected
001 Dave Eade Holidays 3.7 3 True
002 Tail Seeing You 2.7 0 True
003 Dave Eade Truly Cool 4 11 False
004 Aries Love 1.9 0 True
005 Mc Nail Skit 0.4 0 False
006 The Flies Skit 0.6 4 False
007 Mc Nail Game Over 2.7 1 True
(c) State the most appropriate data type for each of the fields shown below:
Field Data Type
Song
Length
TimesPlayed
Protected
(a) Howmanyrecordsarethereinthedatabasesection?
....................................................................................................................................... [1]
(b) Ifthefollowingquerywasinput:
(CDlength(mins)<60)AND(numberofhittracks>1)
UsingReferenceNumberonly,writedownwhichdataitemswouldbeoutput.
................................................................................................................................ [1]
(c) WritedownaquerytoselectwhichCDsarespecialeditionorhavemorethan 10tracks.
................................................................................................................................. [1]
................................................................................................................................ [1]
(e) The radio station has aphone-inservicewherealistener texts the
titleoftheCDontheirmobilephone.The popularity
ofeachCDisthenknownandwhichCDstheradiostationshouldplay.
(i) Howwouldthisinformationbestored?
................................................................................................................................ [1]
(ii) Howcouldthisinformationbelinkedtothedatabase?
................................................................................................................................ [1]
166 | P a g e
Q2) Winter 2010:
A database has been set up to store information about aircraft. A section is shown below.
(i) The branch and country are coded. Give a reason for this. [1]
(ii) One of the six fields is not appropriate.
Name this field and give a reason for your choice. Suggest an improved field.
Name of field
Reason for choice
Improved field choice [3]
167 | P a g e
Q3) Summer 2011:
A database showing the population of world cities has been produced. A section of the
database is shown below.
Patient’s height
Patient ID
Contact
telephone
number
172 | P a g e
Introduction to Logo
LOGO is a programming language that was developed at the MIT Artificial Intelligence
Lab in the 1970s. It was designed to be used as an introduction for people toboth
programming and artificial intelligence. However, while it is easy to learn,Logo is a
powerful language. Once you know the basics, Logo can be used to doextremely
complicated things. Logo code has been used in telecommunications, multimedia
software and robotics. Finally Logo is FUN!
Turtle?
When Logo started, the Turtle was a robotic creature which sat on the floor and
wasdirected to move around by a user typing commands on a computer. Today the
turtleis represented by an icon on the screen and can be made to draw on the screen
usingthe same commands. In some environments the turtle looks like a turtle (with
head,tail and feet) in others represent the turtle with a triangle.
Logo Commands
The following are some of the most use full commands in theLogo Language, which you
will want to become familiar with:
FORWARD - Follow this command with a number (such as: 10 or 1000.) A smallnumber
will cause the turtle to move forward a short distance. A largernumber will cause it to
move further. If you select a large enough number the turtle will go off the canvas and
wrap around to the other side.
BACK- Follow this command with a number, the same as FORWARD, only thistime the
turtle will move backwards.
RIGHT - Follow this command with a number between 0 and 360. The turtle willturn right
specified number of degrees.
LEFT - Follow this command with a number between 0 and 360. This command isthe
same as RIGHT only it will turn the turtle left, not right.
PENUP - This command will cause the turtle to pick up its “pen” up so that youcan move
the turtle without drawing a line.
PENDOWN - This is the command you would use to put the “pen” back down soyou can
draw again.
SETPENCOLOR - You can change the colour your turtle draws in. Follow the command
with a number to get different colours. For example
“SETPENCOLOR 0” would give you a black pen.
CLEAN- This command will erase the canvas
HOME- This command will move the turtle back to the centre of the canvas
The Repeat Command
You can get your turtle to do one (or several) things repeatedly, without typing them
again and again using the REPEAT command. Typing
REPEAT 4 [FORWARD 10]
Would cause the turtle to move forward 10 spaces, 4 time. So, in total the turtlewould
move forward 40 spaces.Now Try These. Type:
REPEAT 4 [FORWARD 50 RIGHT 90]
173 | P a g e
You should get a square. For a bigger square try replacing 50 with 100 or 200.Type:
REPEAT 360 [FORWARD 2 LEFT 1]
You should get a circle. For a smaller circle try replacing 2 with 1. Can you make abigger
one?
Your First Program
That’s a lot to type every time you want to make a square or circle though. Can it
beeasier? YES. You can teach Logo what a square (or a circle, or a flower) is by making
it program.Try typing:
TO SQUARE
REPEAT 360 [FORWARD 80 LEFT 90]
END
Now type SQUARE and see what happens.
How would you write the program CIRCLE?
How would you write the program CIRCLE_AND_SQUARE to make a drawingthat looks
like this (where the black triangle is the turtle at the end)?
TO CIRCLE_AND_SQUARE
HOME
CLEAN
CIRCLE
FORWARD 52
REPEAT 3 [ LEFT 90 FORWARD 104]
LEFT 90
FORWARD 52
END
Complete the set of instructions to draw the shape shown above (in bold lines).
Pen Down ......................................................................................................................................
Repeat 2.........................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
176 | P a g e
Summer 2012
A floor turtle can use the following instructions.
Past Papers
181 | P a g e
4 Five data types and five data samples are shown below.
Draw a line to link each data type to the correct data sample. [4]
HighestMidday
– …replace value in HighestMidday by midday temperature
– …store array index in MiddayMonthDay/MiddayWeekday
– output HighestMidday outside the loop
– output MiddayMonthDay/MiddayWeekday outside the loop
Sample algorithm (max 4):
HighestMidday ← -999
FOR Count ← 1 TO 7
IF MiddayTemperature [Count] > HighestMidday
THEN HighestMidday ← MiddayTemperature[Count]
MiddayMonthDay/MiddayWeekday ← Count
ENDIF
NEXT Count
PRINT 'The highest midday temperature was ',HighestMidday, ' on day ',
Count
If pseudocode or programming only and no explanation, then maximum 4
marks [6]
Section B
2 1 mark for each error identified + suggested correction
Line 1 or Small = 0: this should read Small = 999
line 5 or IF…: this should read IF Num < Small THEN Small = Num
line 8 or UNTIL: this should read UNTIL Counter = 10 or
UNTIL Counter > = 10 or
UNTIL Counter > 9
line 7 or PRINT…: PRINT Small should come after the end of the repeat
loop
or
line 8 or UNTIL: this should come before line 7 [4]
190 | P a g e
Section B
2 Read this section of program code that should input 30 positive numbers and then output the
largest number input.
1 Large = 9999
2 Counter = 0
3 WHILE Counter > 30
4 DO
5 INPUT Num
6 IF Num < Large THEN Large = Num
7 Counter = Counter - 1
8 ENDWHILE
9 PRINT Large
There are four errors in this code.
Locate these errors and suggest a corrected piece of code for each error.
1 .......................................................................................................................................................
..........................................................................................................................................................
2 .......................................................................................................................................................
..........................................................................................................................................................
3 .......................................................................................................................................................
..........................................................................................................................................................
4 .......................................................................................................................................................
......................................................................................................................................................[4]
193 | P a g e
3 (a) The flowchart below inputs six single digit numbers. The predefined function MOD gives the
value of the remainder, for example, Y 10 MOD 3 gives the value Y = 1
194 | P a g e
Complete a trace table for each of the two sets of input data.
Set 1 5, 2, 4, 3, 1, 5
Set 2 3, 2, 1, 0, 7, 3
Trace table set 1: 5, 2, 4, 3, 1, 5
5 (a) Write an algorithm, using pseudocode and a FOR … TO … NEXT loop structure, to input
1000 numbers into an array.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]
195 | P a g e
(b) Rewrite your algorithm using another loop structure.
..........................................................................................................................................................
............................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[4]
6 A database, MARKS, was set up to record the test results for a class of students. Part of the
database is shown below.
line 6 or IF: this should read IF Num > Large THEN Large = Num (b) 4 marks
line 7 or Counter =…: this should read Counter = Counter + 1 [4] – initialisation
– start of loop
– update loop counter
– end of loop
Example1
Count 1 (1 mark)
REPEAT (1 mark)
INPUT A[Count]
Count Count + 1 (1 mark)
UNTIL Count > 1000 (1 mark)
Example2
Count 0 (1 mark)
WHILE Count < 1000 (1 mark)
(b) – (modulo 11) check digit calculation [1] DO
(c) 1 mark for identifying the problem, 2 marks for the solution Count Count + 1 (1 mark)
Problem – doesn’t deal correctly with remainder 10/a check digit of X INPUT A[Count]
Solution – check Z for X as a final digit ENDWHILE (1 mark)
– have a special case where check = 10 6 (a) – 7 [1]
– accept where Check = 10 and F = X [3] (b) – Class ID
4 1 mark for each correct line, two lines from one box not allowed – Uniquely identifies each student [2]
(c) Diana Abur, Paul Smith
– both names
– ……. correct order [2]
Section B
2 Read this section of program code that should input 50 numbers and then output the
average.
1 Total = 0
2 For Counter = 1 TO 50
3 INPUT Num
4 Total = Total + 1
5 Counter = Counter + 1
6 Average = Total/Counter
7 NEXT Counter
8 PRINT Average
There are four errors in this code.Locate these errors and suggest code corrections to
remove each error.
1. ......................................................................................................................................................
..........................................................................................................................................................
2 .......................................................................................................................................................
..........................................................................................................................................................
3 .......................................................................................................................................................
..........................................................................................................................................................
4 .......................................................................................................................................................
......................................................................................................................................................[4]
3 (a) The flowchart inputs an integer. The
predefined function DIV gives the integer
result of thedivision, e.g. Y 10 DIV 3 gives the
value Y = 3. The predefined function MOD
gives thevalue of the remainder, e.g. Y 10
MOD 3 gives the value Y = 1.
Complete a trace table for each of the two
input values 5 and 12.
5 Identify two different conditional statements that you can use when writing pseudocode.
1 .........................................................................................................................................
2 ......................................................................................................................................[2]
6 A picture gallery owner has decided to set up a database to keep information about the
pictures he has for sale. The database table, PICTURE, will contain the following fields:
Title; Artist; Description; Catalogue Number; Size (area in square centimetres); Price;
Arrived (date picture arrived at gallery); Sold (whether picture is already sold)
(a) (i) State what data type you would choose for each field.
Title ...................................................................................................................................
Artist ..................................................................................................................................
Description ........................................................................................................................
Catalogue Number ............................................................................................................
Size ...................................................................................................................................
Price ..................................................................................................................................
Arrived ...............................................................................................................................
Sold ...............................................................................................................................[4]
(ii) State which field you would choose for the primary key.
.......................................................................................................................................[1]
(b) Give a validation check that you can perform on each of these fields. Each validation
check must be different.
Catalogue Number ............................................................................................................
Size ...................................................................................................................................
Price ...................................................................................................................................
Arrived ............................................................................................................................[4]
201 | P a g e
(c) Complete the query-by-example grid below to select and show the Catalogue
Number, Title and Price of all unsold pictures by the artist ‘Twister’.
ENDIF
Marking Scheme (c) (i) Explanation
Section A General marks award as seen
1 (a) (i) Any two variables with matching uses, one mark for the variable Give one mark for a mention of any one of the 4 checks below
name and one mark for the matching use. The variables and the matching If a mark is given for a check then mark the corresponding action taken
uses must relate to the tasks on the exam paper. There are many possible Maximum of five marks overall
correct answers these are examples only. General
Variable 1 – Counter(: INTEGER) – check all recorded temperatures (loop 18 times)
Use – to use as a loop counter when entering the temperatures – update counter for those out of range
Variable 2 – BabyTemperature(: REAL) – output suitable message if counter >= 2
Use – to store the baby’s temperature [4] 1 check if temperature range <= 1 and highest recorded not out of range and
(ii) Any two constants with matching uses, one mark for the constant (name lowest recorded not out of range
and value) and one mark for the matching use. The constants and the – ... exit
matching uses must relate to the tasks on the exam paper. There are several 2 check if temperature range > 1...
possible correct answers these are examples only. – … output suitable message e.g. "Temperature range greater than one
Constant 1 – MinBabyTemperature = 36.0 degree"
Use – to keep the lowest acceptable baby temperature 3 check if highest recorded temperature out of range…
Constant 2 – MaxBabyTemperature = 37.5 – … output a suitable message if at least two recorded temperatures out of
Use – to keep the highest acceptable baby temperature [4] range
(b) Any five from e.g. "Temperature too high on more than one occasion"
– prompt for baby’s temperature 4 check if lowest recorded temperature out of range…
– input baby’s temperature – … output a suitable message if at least two recorded temperatures out of
– test for > 37.5 range
– … then output suitable message if this is the case e.g. "Temperature too low on more than one occasion" [5]
– test for < 36.0 (ii) Any two from
– … then output suitable message if this is the case – only checks necessary conditions
– output suitable message if temperature between those values [5] – uses results from task 2
Sample algorithm: – checks for normal values first [2]
PRINT 'Please enter temperature of baby ' Section B
INPUT BabyTemperature 2 One mark for each error identified + suggested correction
IF BabyTemperature > MaxBabyTemperature or 37.5 line 4 or (Total =) Total + 1: this should read (Total =) Total + Num
THEN Print 'Temperature too high' line 5 or Counter = Counter + 1: delete this line
ELSE line 6 or (Average = )Total / Counter: swap lines 6 and 7
IF BabyTemperature < MinBabyTemperature or 36.0 line 6 or (Average = )Total / Counter : this should read (Average =) Total / 50
THEN Print 'Temperature too low' [4]
ELSE Print 'Temperature OK'
ENDIF
203 | P a g e
0, 1 no marks
2, 3 one mark
4, 5 two marks
6, 7 three marks
8 four marks [4]
(ii) Catalogue Number [1]
(b) One mark for each correct different check
Catalogue Number Format check/Presence Check/Check Digit/Length
check/uniqueness check
Size Type check/Presence Check/Range Check
Price Type check/Presence Check/Range Check
Arrived Type check/Presence Check/Range Check/Format check/Select from
calendar length check [4]
..........................................................................................................................................................
........................................................................................................................................[2]
4 A routine checks the age and height of children who are allowed to enter a play area. The
children must be less than 5 years of age and under 1 metre in height.
(a) The first set of test data used is age 3 and height 0.82 metres.
State what type of test data this is.
...................................................................................................................................................
Give a reason for using this test data.
...................................................................................................................................................
207 | P a g e
...............................................................................................................................................[2]
(b) Provide two additional sets of test data. For each, give
• the type of each set of test data
• the reason why it is used
Each type of test data and reason for use must be different.
Set 1 .........................................................................................................................................
Type ..........................................................................................................................................
Reason .....................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Set 2 .........................................................................................................................................
Type ..........................................................................................................................................
Reason .....................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[6]
5 A motor boat hire company decides to set up a database to keep information about boats that
are available for hire. The database table, BOAT, will contain the following fields:
Boat Name; Model; Engine Power (in hp); Number of Seats; Life Raft (whether there is a life raft
kept on the boat); Day Price (price for a day’s hire).
(a) Give the data type you would choose for each field.
Boat Name ................................................................................................................................
Model ........................................................................................................................................
Engine Power ............................................................................................................................
Number of Seats .......................................................................................................................
Life Raft ....................................................................................................................................
Day Price ..............................................................................................................................[3]
(b) State a validation check that you can perform on each of these fields. Each validation check
must be different.
Boat Name ................................................................................................................................
Model ........................................................................................................................................
Number of Seats .......................................................................................................................
Day Price ..............................................................................................................................[4]
(c) Complete the query-by-example grid below to select and show the Boat Name, Model and
Day Price of a day’s hire for all boats with 4 seats and an Engine Power of more than 100 hp.
output after the loop (One mark) [5]
Marking Scheme sample algorithm:
Section A HighestTemp 0; LowestTemp 100
1 (a) (i) Any two variables with matching uses, one mark for the variable and FOR Count 1 to 60
one mark for the matching use. The variables and the matching uses must INPUT Temperature
relate to the tasks on the exam paper. There are many possible correct ApartmentTemp[Count] Temperature
answers these are examples only. IF ApartmentTemp[Count] > HighestTemp
Variable 1 – Counter(: INTEGER) THEN HighestTemp ApartmentTemp[Count]
Use – to use as a loop counter when entering the temperatures ENDIF
Variable 2 – HighestTemperature(: REAL) IF ApartmentTemp[Count] < LowestTemp
Use – to store the highest temperature recorded [4] THEN LowestTemp ApartmentTemp[Count]
(ii) Any two constant with matching uses, one mark for the constant and one ENDIF
mark for the matching use. The constants and the matching uses must relate NEXT Count
to the tasks on the exam paper. There are several possible correct answers Range HighestTemp – LowestTemp
these are examples only. PRINT 'Highest Temperature recorded ', HighestTemp
Constant 1 – MinAppartmentTemperature = 21.5/22 PRINT 'Lowest Temperature recorded ', LowestTemp
Use – to keep the temperature when the air-conditioning should be switched PRINT 'Range ', Range
off
Constant 2 – MaxAppartmentTemperature = 24.5/24 (c) (i) Explanation six marks from:
Use – to keep the temperature when the air-conditioning should be switched 1 – check if highest temperature <= 24 and lowest temperature >= 22…
on [4] – … message temperature always within acceptable range then exit
(b) Any four from: 2 – check if highest out of range
– initialisation, set highest apartment temperature to a low value, set lowest – so count number of times temperature goes above range
apartment temperature to a high value outside loop – message recorded temperature too high on counted number of occasions
– input temperature 3 – check if lowest out of range
– store in array – so count number of times temperature goes below range
– test for temperature > highest apartment temperature reset highest – message recorded temperature too low on counted number of occasions
apartment General
temperature if this is the case – check all recorded temperatures (loop)
– test for temperature < lowest apartment temperature reset lowest apartment [6]
temperature (ii) Any one from:
if this is the case – only checks necessary conditions
– calculate range – uses results from task 2 [1]
– output highest temperature, lowest temperature and the range outside loop
(Max four marks) Section B
– loop 60 times must have both tests within the loop, initialisation before the 2 One mark for each error identified + suggested correction
loop and line 5 or IF Num < 0: this should read IF Num > 0 (THEN Total = Total +
209 | P a g e