Computing (9691) · Oct/Nov 2015 · Question paper 21

Cambridge Computing (9691) question paper for paper 21, Oct/Nov 2015 — 9691/21/O/N/15, file 9691_w15_qp_21.pdf.

Advertisement
Loading the paper…

More Computing (9691) papers

Paper 21 in other years

All Computing papers
Text of this paper

Cambridge International Examinations
Cambridge International Advanced Subsidiary and Advanced Level

* 7 7 7 3 3 6 1 5 3 1 *

9691/21

COMPUTING
Paper 2

October/November 2015
2 hours

Candidates answer on the Question Paper.
No additional materials are required.
READ THESE INSTRUCTIONS FIRST
Write your Centre number, candidate number and name on all the work you hand in.
Write in dark blue or black pen.
You may use an HB pencil for any diagrams, graphs or rough working.
Do not use staples, paper clips, glue or correction fluid.
DO NOT WRITE IN ANY BARCODES.
Answer all questions.
At the end of the examination, fasten all your work securely together.
The number of marks is given in brackets [ ] at the end of each question or part question.

This document consists of 12 printed pages.
DC (NH/SW) 107247/2
© UCLES 2015

[Turn over

2
1

(a) A college provides courses for the local community. The Computing teacher, Ravi, wants to
develop a program to keep details of the courses. One way of storing this data will be to use
records. Each record will contain the fields shown in the table below.
Complete the table.
Example of
input data

Data type

Field

Identifier

course code

CourseCode

015110217

title

Title

Programming
for Beginners

tutor
(3-letter initials)

Tutor

PGL

Day

2

lab based?

IsLabBased

TRUE

session duration
in hours

SessionHours

2.5

fee ($)

CourseFee

25.50

date course starts

StartDate

02/11/2015

date course ends

EndDate

03/12/2015

day of week
(1 – Monday

Field size
(in bytes)

7 – Sunday)

[5]
(b) Use a high-level programming language to define a course record with identifier
CourseRecordType and the fields listed in part (a).
Programming language
Code

[4]
© UCLES 2015

9691/21/O/N/15

3
(c) Ravi decides to store course data in the array Course. The array will consist of 50 records.
Initially, the array elements will not contain course data.
Use the high-level language from part (b) to:
•
•

declare the array Course
initialise its contents with appropriate dummy values for each field

Programming language
Code

[6]

© UCLES 2015

9691/21/O/N/15

[Turn over

4
(d) Ravi has entered some course data. His program saved the array records to a serial file
CourseData.DAT. Only those array elements containing entered course details were saved
to the file.
A program is to be written to read the data from CourseData.DAT into consecutive locations
of the array Course.
(i)

Explain what the function EOF() does when used in a program.

[2]

Ravi wants to write another module in his program. The new module will:
•
•

read data from CourseData.DAT
write these data into consecutive elements of the array Course

(ii)

Write pseudocode to read the data from the file CourseData.DAT into the array
Course.

[6]

© UCLES 2015

9691/21/O/N/15

5
(e) Ravi wants to write a procedure to sort the records in the array Course. The records will
be sorted into ascending order of course fee. The array contains records for each course
provided. The remaining array elements contain dummy records.
One of his students has written a sorting algorithm:
PROCEDURE SortData
FOR x ← 1 TO 49
FOR y ← 1 TO 49
IF Course[y].CourseFee > Course[y + 1].CourseFee
THEN
TempRecord ← Course[y]
Course[y] ← Course[y + 1]
Course[y + 1] ← TempRecord
ENDIF
ENDFOR
ENDFOR
ENDPROCEDURE
An integer variable, NumberOfCourses, will contain the number of courses for which data
are stored in the array.
Improve the algorithm so that no unnecessary comparisons are made.
PROCEDURE SortData(NumberOfCourses)

[6]
© UCLES 2015

9691/21/O/N/15

[Turn over

6
2

Alia received a number coded as a sequence of letters. She wants to write a program to change
this sequence of letters back to the original number. She knows that each digit of the original
number was replaced by exactly one letter. The letters used are shown in the flowchart below.
She has drawn the flowchart as part of the design for her solution.
The function DenaryDigit(Letter) returns an integer.
FUNCTION DenaryDigit(Letter)

CASE OF
Letter

'K'

ELSE

'D'
'L'
'C'

Value

–1

'F'
'H'
'B'
'G'
'E'
'A'

RETURN Value

ENDFUNCTION

© UCLES 2015

9691/21/O/N/15

Value

0

Value

1

Value

2

Value

3

Value

4

Value

5

Value

6

Value

7

Value

8

Value

9

7
(a) (i)

Write the program code to implement the function DenaryDigit from its flowchart
design. Use a high-level programming language.
Programming Language
Code

[5]

(ii)

Alia needs to test this function before using it in her program.
Complete the table of test data.
Letter

Expected result

Type of data
(normal, borderline or invalid)

'1'
'X'
'G'
[3]

© UCLES 2015

9691/21/O/N/15

[Turn over

8
(b) Alia writes pseudocode to convert a coded number using
the function DenaryDigit() from part (a)
the string manipulation functions MID() and LENGTH()

•
•

Study the pseudocode:
01 PROCEDURE ConvertToDenary(CodedNumber : STRING)
02
03
Denary ← 0
04
05
FOR i ← 1 TO LENGTH(CodedNumber)
06
ThisChar ← MID(CodedNumber, i, 1)
07
ThisNumber ← DenaryDigit(ThisChar)
08
Denary ← Denary + (ThisNumber * 10)
09
ENDFOR
10
11
OUTPUT Denary
12 ENDPROCEDURE
(i)

Dry-run the procedure call ConvertToDenary("LED")by completing the trace table.

CodedNumber

Denary

"LED"

0

i

ThisChar

ThisNumber

OUTPUT

[5]
(ii)

The denary value of the coded number LED is 281. There is an error in the pseudocode
above.
Give the line number of the statement that needs correcting.

Write the corrected statement.

[2]

© UCLES 2015

9691/21/O/N/15

9
(iii)

State the type of error Alia made in her pseudocode.
[1]

(iv)

There are two other types of error that can occur when writing or executing program
code.
Name each type of error and describe when and how it is detected.
Error type 1
When

How

Error type 2
When

How
[6]

(c) (i)

The pseudocode in part (b) has some features that make it easier to read and understand.
State three such features.
1

2

3
[3]

(ii)

State one other feature Alia could have used to help the understanding of this code.
[1]

© UCLES 2015

9691/21/O/N/15

[Turn over

10
(iii)

Write program code to implement the pseudocode given in part (b).
Remember to declare variables before you use them.
The code is repeated here so that you do not need to turn back to part (b):
PROCEDURE ConvertToDenary(CodedNumber : STRING)
Denary ← 0
FOR i ← 1 TO LENGTH(CodedNumber)
ThisChar ← MID(CodedNumber, i, 1)
ThisNumber ← DenaryDigit(ThisChar)
Denary ← Denary + (ThisNumber * 10)
ENDFOR
OUTPUT Denary
ENDPROCEDURE
Programming Language
Code

[10]

© UCLES 2015

9691/21/O/N/15

11
(iv)

The parameter of ConvertToDenary might not be a valid coded number.
An error message is to be output if the string provided as a parameter is not valid.
Describe the changes required to the code design.

[3]

© UCLES 2015

9691/21/O/N/15

[Turn over

12
3

Ravi and Alia want to use debugging tools available in their program development environments.
(a) Explain how each of the following are used:
(i)

Breakpoint

[2]

(ii)

Stepping

[2]

(iii)

Variable check / watch

[2]

(b) Name the type of testing that is performed with such debugging tools.
[1]

Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every reasonable
effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will
be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge International
Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after
the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local
Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge.

© UCLES 2015

9691/21/O/N/15

Advertisement