Professional Documents
Culture Documents
2 3 4-Iteration
2 3 4-Iteration
6 A firm employs five staff who take part in a training programme. Each member of staff must
complete a set of twelve tasks which can be taken in any order. When a member of staff
successfully completes a task, this is recorded.
A program is to be produced to record the completion of tasks for the five members of staff.
To test the code, the programmer makes the program generate test data.
Each pair of numbers simulates the completion of one task by one member of staff.
(a) Explain why the generation of 60 (5 staff x 12 tasks) pairs of random numbers will not simulate
all tasks completed by all staff.
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]
The table shows that two members of staff have each successfully completed one task.
The program must use a suitable data structure to store, for all staff:
The program will output the staff number and task number in the order in which tasks are
completed.
(iii) The incrementing of a variable used as a counter, but not to control a ‘count controlled’
loop.
.................... [1]
.................... [1]
.......................................................................................................................................[1]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[3]
(iv) Give the global variable that needs to be declared at line 03.
.......................................................................................................................................[2]
(d) Line 17 in the pseudocode outputs the staff number and the task number.
Staff number Staff name
A new requirement is to display the name of the
member of staff given in the table. 1 Sadiq
2 Smith
Write a CASE structure using variable StaffNum. 3 Ho
Assign to a new variable StaffName the appropriate 4 Azmah
staff name. 5 Papadopoulos
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[4]
4 The standard pack of playing cards has four suits – called Clubs, Diamonds, Hearts and Spades.
Each card has a value shown by its number or a name: 1 (Ace), 2, 3, … 10, 11 (Jack), 12 (Queen),
13 (King). The pack of cards has one combination for each suit and value.
A program is to be written which simulates a magician dealing all 52 cards from the card pack.
(a) Explain why the generation of 52 (4 suits x 13 card values) pairs of random numbers will not
simulate the dealing of the complete pack.
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]
Card value
Suit
number 1 2 3 4 5 6 7 8 9 10 11 12 13
1 (Clubs) F F F F F F F F F F T F F
2 (Diamonds) F F F F F F F F F F F F F
3 (Hearts) F F T F F F F F F F F F F
4 (Spades) F F F F F F F F F F F F F
The table shows two cards have been dealt so far; the 3 of Hearts and the Jack of Clubs.
The program will output the suit and the card value in the order in which the cards are dealt.
.......................................................................................................................................[1]
.......................................................................................................................................[1]
(iii) The initialisation of a variable used as a counter, but not to control a ‘count controlled’
loop.
.......................................................................................................................................[1]
.......................................................................................................................................[1]
...............................................................................................................................................[1]
...............................................................................................................................................[1]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]
(g) Line 18 in the design shows which new card is dealt each time.
When an Ace, Jack, Queen or King is dealt, the output displays the number for that card, not
the name of the card.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[4]
There is an Appendix on pages 19 and 20. Some questions will refer you to this information.
1 A programmer wants to write a program to calculate the baggage charge for a passenger’s airline
flight.
Each ticket type has a baggage weight allowance as shown below. The airline makes a charge if
the weight exceeds the allowance.
(a) A program flowchart will document the program. The flowchart will contain the following
statements:
Statement
Statement
number
1 Charge 0
2 INPUT BaggageWeight
4 Is ExcessWeight > 0 ?
5 INPUT TicketType
7 BaggageAllowance 16
8 ChargeRate 3.5
9 OUTPUT Charge
10 ChargeRate 5.75
11 BaggageAllowance 20
12 Is TicketType = 'E' ?
Complete the flowchart by putting the appropriate statement number in each flowchart
symbol. Statement 5 has been done for you.
© UCLES 2016 9608/21/O/N/16
3
Start
Stop
[6]
.................................................................
E 15
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
[5]
(c) The program design is to be amended. The value input by the user for the ticket type is to be
validated. Part of the amended flowchart is shown below.
Start
Loop
INPUT TicketType
Is
TicketType
No E or S ?
Yes
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
(a) Radhika was interviewed for the job. Part of the interview process was to study some program
code written in language ABC.
11 settype($TimesTable, Integer);
12 settype($upTo, Integer);
13 settype($Posn, Integer);
14 settype($Product, Integer);
15 $TimesTable = 7;
16 $UpTo = 10;
17
18 $Posn = 1
19 While ($Posn < $UpTo + 1)
20 {
21 $Product = $Posn * $TimesTable;
22 Echo $Posn . ' X' . $TimesTable . ' = ' . $Product . "<br>";
23 $Posn = $Posn + 1;
24 }
...........................................................................................................................................
...................................................................................................................................... [1]
...................................................................................................................................... [1]
...................................................................................................................................... [1]
State the syntax that language ABC uses to indicate which statements must be executed
inside a loop.
...................................................................................................................................... [1]
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [2]
(ii) Give two examples which suggest that programming in a high-level language is a
transferrable skill.
1 .......................................................................................................................................
...........................................................................................................................................
2 .......................................................................................................................................
...................................................................................................................................... [2]
Description: ...................................................................................
.......................................................................................................
Input
Pseudocode example: ..................................................................
.......................................................................................................
Description: ...................................................................................
.......................................................................................................
....................
Pseudocode example: ..................................................................
.......................................................................................................
Description: ...................................................................................
.......................................................................................................
....................
Pseudocode example: ..................................................................
.......................................................................................................
[7]
(b) (i) AND and OR are two operators that may be used when implementing an algorithm.
An example of their use is given in the following pseudocode statement:
.......................................................................................................................................[1]
(ii) State the name given to the type of operators to which AND and OR belong.
.......................................................................................................................................[1]
(iii) Evaluate the expressions given in the following table when the variable values are as
follows:
FlagA TRUE
FlagB FALSE
FlagC TRUE
Expression Evaluates to
Using pseudocode, write a pre-condition loop to output all of the even numbers between 99
and 201.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[4]
2 DISPLAY RIGHT(String1, 5)
[6]
Variable Value
FlagA TRUE
FlagB FALSE
FlagC TRUE
Expression Evaluates to
[3]
(c) The loop construct (also known as repetition or iteration) appears in many algorithms.
Use pseudocode to write a post-condition loop to output all the odd numbers between 100
and 200.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [4]
2 (a) One type of loop that may be found in an algorithm is a count-controlled loop.
Type ..........................................................................................................................................
Explanation ...............................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[2]
(b) Chris is asked to work on a program that has been coded in a language he is not familiar
with.
He has identified that the program contains the constructs: sequence, iteration and selection.
Identify three other features of the program that he should expect to recognise.
Feature 1 ..................................................................................................................................
Feature 2 ..................................................................................................................................
Feature 3 ..................................................................................................................................
[3]
(c) The following lines of code are taken from a program in a high-level language.
ON x {
15: Call ProcA
20: y := 0
25: y := 99
NONE: Call ProcError
}
Identify the type of control structure and describe the function of the code.
Description ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[3]
2 (a) (i) Two types of loop that may be found in an algorithm are the ‘pre-condition’ and ‘post-
condition’ loop.
Type ..................................................................................................................................
Explanation .......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[2]
LOOP
AlarmReset()
Set Status1 to
GetStatus(Sys_A)
Set Status2 to
GetStatus(Sys_B)
Are Status1
NO
and Status2
both TRUE?
YES
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [4]
(b) The following lines of code are taken from a high-level language program.
Study the code. Identify the relevant features in the following table.
Feature Answer
The line numbers for the start and end of a count-controlled loop
Identify one type of translator that can be used to translate the program.
............................................................................................................................................. [1]