0% found this document useful (0 votes)
17 views19 pages

9608/21/o/n/15 © Ucles 2015

Uploaded by

EarthGamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views19 pages

9608/21/o/n/15 © Ucles 2015

Uploaded by

EarthGamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

QUESTION 7.

1 Computer programs have to evaluate expressions.

Study the sequence of pseudocode statements.

Write down the value assigned to each variable.

DECLARE h, w, r, Perimeter, Area : REAL


DECLARE A, B, C, D, E : BOOLEAN

h ← 13.6
w ← 6.4
Perimeter ← (h + w) * 2 (i) Perimeter …………………………………… [1]

r ← 10
Area 3.142 * r^2 (ii) Area ………………………………………………… [1]

Z ← 11 + r / 5 + 3 (iii) Z ………………………………………………………… [1]

A ← NOT(r > 10) (iv) A ………………………………………………………… [1]

2 A programmer uses an Integrated Development Environment (IDE) for all program development.

(i) Describe what is meant by an IDE.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[2]

(ii) Name three features you would expect to be available in an IDE to help initial error detection
or debugging.

1 ...............................................................................................................................................

...................................................................................................................................................

2 ...............................................................................................................................................

...................................................................................................................................................

3 ...............................................................................................................................................

...............................................................................................................................................[3]

© UCLES 2015 9608/21/O/N/15 [Turn over


QUESTION 8. 13

4 A company employs Ahmed as a programmer.

(a) At College, before joining the company, Ahmed used two items of software for programming:

• a text editor
• a compiler

Describe how he could have developed programs using these software tools.

Include in the description the terms ‘object code’ and ‘source code’.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[3]

(b) Ahmed now uses an Integrated Development Environment (IDE) for programming.

(i) State one feature an IDE provides to help with the identification of syntax errors.

...........................................................................................................................................

.......................................................................................................................................[1]

(ii) State one feature an IDE provides to carry out white box testing.

...........................................................................................................................................

.......................................................................................................................................[1]

(c) The company maintains a file of product data. Ahmed is to write a program to add a new
product and search for a product based on the structure diagram shown:

Product
processing

Add Search for


product product

By By By
product code description price

© UCLES 2016 9608/21/O/N/16 [Turn over


14

The program records the following data for each product:

• product code
• product description
• product retail price

The text file PRODUCTS stores each data item on a separate line, as shown below:

File PRODUCTS
0198
Plums(10kg)
11.50
0202
Onions(20kg)
10.00

0376
Mango chutney(1kg)
02.99

0014
Mango(10kg)
12.75

The program uses the variables shown in the identifier table.

Identifier Data type Description

Storing the code, description and


PRODUCTS TEXT FILE
retail price for all current products
PCode ARRAY[1:1000] OF STRING Array storing the product codes
PDescription ARRAY[1:1000] OF STRING Array storing the product descriptions
PRetailPrice ARRAY[1:1000] OF REAL Array storing the product retail prices
i INTEGER Array index used by all three arrays

© UCLES 2016 9608/21/O/N/16


15

(i) The first operation of the program is to read all the product data held in file PRODUCTS
and write them into the three 1D arrays.

Complete the pseudocode below.

OPEN ................................................................................................................................

i 1

WHILE ..............................................................................................................................

READFILE ("PRODUCTS", ......................................................................................)

READFILE ("PRODUCTS", ......................................................................................)

READFILE ("PRODUCTS", ......................................................................................)

.......................................................................................................................................

.......................................................................................................................................

ENDWHILE

CLOSE "PRODUCTS"

OUTPUT "Product file contents written to arrays"


[5]

When Ahmed designed the PRODUCTS file, File PRODUCTS


he considered the alternative file structure
shown opposite. 0198 Plums(10kg) 11.50
0202 Onions(20kg) 10.00
It stores one product per line in the text file.

0376 Mango chutney(1kg) 02.99

0014 Mango(10kg) 12.75

(ii) State one benefit and one drawback of this file design.

Benefit ...............................................................................................................................

...........................................................................................................................................

Drawback ..........................................................................................................................

.......................................................................................................................................[2]

© UCLES 2016 9608/21/O/N/16 [Turn over


16

(d) To code the ‘Search by product code’ procedure, Ahmed draws a structure chart showing the
different stages.

The procedure uses the variables shown in the identifier table.

Identifier Data type Description

SearchCode STRING Product code input by the user


Array index position for the
ThisIndex INTEGER
corresponding product
ThisDescription STRING Product description found
ThisRetailPrice REAL Product retail price found

You can assume that before the procedure is run, all the product data is read from file
PRODUCTS and then stored in three 1D arrays as described in part (c)(i).

Label the structure chart to show the input(s) and output(s).

Lookup by
product code
......................

......................
......................

.................
................ ......................

......................

INPUT Search for OUTPUT details


search criteria product code

[4]

© UCLES 2016 9608/21/O/N/16


17

(e) A first attempt was made at writing the ‘Search for product code’ module.
Ahmed designs this as a function ProductCodeSearch.

The function returns an integer value as follows:

• if the product code is found, it returns the index position of the 1D array PCode being
searched
• if the product code is not found, the function returns -1

Write program code for function ProductCodeSearch.

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ...................................................................................................

......................................................................................................................................

......................................................................................................................................

......................................................................................................................................

......................................................................................................................................

......................................................................................................................................

......................................................................................................................................

......................................................................................................................................

......................................................................................................................................

......................................................................................................................................

......................................................................................................................................

......................................................................................................................................

......................................................................................................................................

......................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[6]

© UCLES 2016 9608/21/O/N/16 [Turn over


QUESTION 9. 6

3 (a) A multi-user computer system stores information about users. It uses a 1D array,
UserNameArray, of type STRING. There are 100 elements in the array.

The format of the string in each element of the array is as follows:

<UserID><UserName>

• UserID is a six-character string of numerals.


• UserName is a variable-length string.

Write pseudocode for a procedure, BubbleSort, to perform an efficient bubble sort on


UserNameArray. The array is to be sorted in ascending order of UserID.

You should assume that UserNameArray has been declared as a global variable.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2017 9608/21/O/N/17


7

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[8]

© UCLES 2017 9608/21/O/N/17 [Turn over


8

(b) The value of UserID should be unique for each user but a problem has occurred and
repeated UserID values may have been issued.

The array is sorted by UserID, so any repeated UserID values will appear in consecutive
array elements.

A procedure, FindRepeats is required.

This will:

• compare each element with the previous element and output the UserID and UserName
if the UserID is repeated
• output the total number of UserIDs that are repeated.

For example, the UserNameArray contains the following entries.

Array element Comment

122222Jim Moriarty

123456Fred Smith
123456Eric Sykes Repeated User ID
123456Kevin Turvey Repeated User ID

222244Alice Chan
222244Myra Singh Repeated User ID

333333Yasmin Halim

For this example, the output is:

123456Eric Sykes
123456Kevin Turvey
222244Myra Singh
There are 3 repeated UserIDs

If no repeated UserIDs are found, the output is:

The array contains no repeated UserIDs


© UCLES 2017 9608/21/O/N/17
9

Write program code for the procedure, FindRepeats.


You should assume that UserNameArray has been declared as a global variable.

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[8]

© UCLES 2017 9608/21/O/N/17 [Turn over


10

(c) (i) The FindRepeats procedure forms part of a program.

Name three stages in a program development cycle.

1 ........................................................................................................................................

2 ........................................................................................................................................

3 ........................................................................................................................................
[3]

(ii) The program containing FindRepeats will be created using an IDE.

State what is meant by IDE.

...........................................................................................................................................

.......................................................................................................................................[1]

(iii) Name two features provided by an IDE that assist in the program development cycle.

1 ........................................................................................................................................

...........................................................................................................................................

2 ........................................................................................................................................

...........................................................................................................................................
[2]

(iv) The procedure, FindRepeats, is written assuming there are 100 elements in
UserNameArray.

In the main program, the global array, UserNameArray, has been declared with only
50 elements.

State the type of error this will cause.

.......................................................................................................................................[1]

© UCLES 2017 9608/21/O/N/17


QUESTION 10. 10

4 Programming languages provide built-in functions to generate random numbers.


To be truly random, the frequency of each number generated should be the same.

You are required to write program code to test the random number generator of your chosen
language.

The test should:

• generate a given number of random numbers between 1 and 10 inclusive


• keep a count of the number of times each number is generated
• calculate the expected frequency of each number 1 to 10
• output the actual frequency of each number 1 to 10
• output the difference between the actual frequency and the expected frequency.

The program code should be written as a procedure. In pseudocode, the procedure heading will
be:

PROCEDURE TestRandom(Repetitions AS INTEGER)

The parameter, Repetitions, contains a value representing the total number of random numbers
that should be generated.

The following example shows the expected output for the procedure call, TestRandom(200).

The expected frequency is 20.

Number Frequency Difference


1 17 −3
2 21 1
3 12 −8
4 28 8
5 20 0
6 19 −1
7 21 1
8 16 −4
9 24 4
10 22 2

© UCLES 2017 9608/22/O/N/17


11

(a) Write program code for the procedure, TestRandom.

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................ [16]
© UCLES 2017 9608/22/O/N/17 [Turn over
12

(b) Name three features of a typical IDE that would help a programmer to debug a program.

Explain how each of these could be used in the debugging of the TestRandom procedure
from part (a).

Feature 1 ..................................................................................................................................

Explanation ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Feature 2 ..................................................................................................................................

Explanation ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Feature 3 ..................................................................................................................................

Explanation ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[6]

(c) The procedure is developed and run using the call TestRandom(200). No system errors
are produced.

To ensure that the procedure works correctly, you need to check the output.

Describe two checks you should make to suggest the program works correctly.

1 ...............................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

2 ...............................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2017 9608/22/O/N/17


QUESTION 11. 5

2 (a) A student is learning about arrays. She wants to write a program to:

• search through a 1D array of 100 elements


• count the number of elements that contain the string “Empty”
• output the number of elements containing “Empty” together with a suitable message.

Use structured English to describe the algorithm she could use.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

(b) She uses the process of stepwise refinement to develop her algorithm.

Explain this process.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2019 9608/23/M/J/19 [Turn over


6

(c) The student is learning about file handling.

She has been told that there are different file modes that can be used when opening a text
file. She wants to make sure that the existing contents are not deleted when the file is opened.

Identify two file modes she could use and describe their use.

Mode .........................................

Description ................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Mode .........................................

Description ................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[4]

(d) The student has completed the design of her program and is ready to use an Integrated
Development Environment (IDE).

Describe the features of an IDE that she can use to write, translate and test her program.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2019 9608/23/M/J/19


7

Question 3 begins on the next page.

© UCLES 2019 9608/23/M/J/19 [Turn over


QUESTION 12. 5

2 (a) A structure chart is often used in modular program design. One feature shown is the sequence
of module execution.

State four other features that may be shown.

Feature 1 ..................................................................................................................................

...................................................................................................................................................

Feature 2 ..................................................................................................................................

...................................................................................................................................................

Feature 3 ..................................................................................................................................

...................................................................................................................................................

Feature 4 ..................................................................................................................................

...................................................................................................................................................
[4]

(b) Identify and describe one feature of an Integrated Development Environment (IDE) that can
help with program presentation.

Feature .....................................................................................................................................

Description ................................................................................................................................

...................................................................................................................................................
[2]

(c) By value is one method of passing a parameter to a subroutine.

Identify and describe the other method.

Method ......................................................................................................................................

Description ................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

(d) Explain the term adaptive maintenance.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]
© UCLES 2019 9608/21/O/N/19 [Turn over
QUESTION 13. 5

2 (a) Describe the program development cycle with reference to the following:

• source code
• object code
• corrective maintenance.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

(b) Give three features of an Integrated Development Environment (IDE) that can help with
initial error detection while writing the program.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2019 9608/22/O/N/19 [Turn over

You might also like