You are on page 1of 17

18

(a) A user-defined function CountCharacter is defined, using pseudocode, as follows:

For
Examiner's
Use

FUNCTION CountCharacter(ThisArray : CHAR, UBound : INTEGER,


ThisCharacter : CHAR) RETURNS INTEGER
The function checks each element in the array ThisArray with upper bound UBound.
The function returns the number of times ThisCharacter appears in ThisArray.
If the function is incorrectly formed it will give a COMPILE ERROR.

The function is used with the three arrays shown below:


Subscript/Index
5
6

Identifier

City1

City2

<Space>

City3

10

What is returned by the following function calls?


(i) CountCharacter(City1, 6, O)
[1]
(ii) CountCharacter(City2, R, 8)
[1]
(iii) CountCharacter(City3, 9, t)
[1]
(iv) CountCharacter(City2, W)
[1]

UCLES 2013

9691/31/M/J/13

19
(b) A programmer writes pseudocode to report whether or not a string value ThisValue is
found in the string array ThisArray. This is designed as a function StringFound
which returns a Boolean value.

For
Examiner's
Use

(i) Show the function header for function StringFound.

[3]
(ii) Use the following numbers to label your function header above.
1.
2.

Function parameter(s)
Where the return data type is stated

[2]

(iii) Write a single statement which calls the function StringFound to search for the
value LISBON in the array CapitalCities (upper bound 300). The function
returns the value to variable CityWasFound in the calling statement.

[2]

UCLES 2013

9691/31/M/J/13

[Turn over

19
7

A user-defined function FoundBigger is defined, using pseudocode, as follows:

For
Examiner's
Use

FUNCTION FoundBigger(ThisArray : INTEGER, UBound : INTEGER,


ThisValue : INTEGER) RETURNS BOOLEAN
The function checks each element in the array ThisArray with upper bound UBound.
The function returns a Boolean value to show if ThisValue is bigger than any of the values
in ThisArray.
If the function is incorrectly formed it will give a COMPILE ERROR.

The function is used with the three arrays shown below:


Subscript/Index
5
6

Identifier

10

List1

17

23

11

16

List2

13

16

16

20

22

20

19

11

23

List3

41

29

34

39

39

44

(a) What is returned by the following function calls?


(i) FoundBigger(List3, 7, 50)
[1]
(ii) FoundBigger(List3, 7, 41)
[1]
(iii) FoundBigger(65, List1)
[1]
(iv) FoundBigger(List2, 10, 27)
[1]

UCLES 2013

9691/33/M/J/13

[Turn over

20
(b) A programmer writes pseudocode to calculate an employees net pay with a function
CalcNetPay.
The calculation is done using:

Employees pay grade (a single character: F, P or C)


Hours worked that week

Show the function header for CalcNetPay.

[3]

For
Examiner's
Use

14
8

(a) A high-level programming language has the following built-in function ChangeString
defined as follows:

ChangeString(ThisString1: String, ThisString2: String) RETURNS


String
will return the String value ThisString2<Space>first character of ThisString1
For Example:
ChangeString(Ben, Pollard) will return Pollard B
If the function is not properly formed an error is generated.

(i) State the function identifier and parameters for the above function.
Function identifier
Parameters
[2]
What value is returned from the following function calls?
(ii) ChangeString(Wesley, Lyons)
[1]
(iii) ChangeString(923, SMITH)
[1]
(iv) ChangeString(Zawinal)
[1]

(b) Describe two similarities between a user-defined function and a procedure.


1

2
[2]

UCLES 2012

9691/31/O/N/12

For
Examiner's
Use

14
8

(a) A high-level programming language


CharacterCount defined as follows:

has

the

following

built-in

function

CharacterCount(ThisChar: CHAR, ThisString: STRING) RETURNS INTEGER


returns an integer value for the number of times the character ThisChar occurs within
ThisString.
CHAR is a data type for a single character.
For Example:
CharacterCount(J, James Joyce) will return the integer 2
An error is returned if the function is not properly called.
(i) Explain what is meant by the term function identifier.

[1]
(ii) State the function identifier for the function given above.
[1]
(iii) Explain what is meant by the term parameter.

[1]
(iv) State the parameter identifiers for the function given above.

[2]

UCLES 2012

9691/32/O/N/12

For
Examiner's
Use

15
(b) What is returned from the following function calls?

For
Examiner's
Use

(i) CharacterCount(A, Adams Apple)


[1]
(ii) CharacterCount(a, Amber Arif)
[1]
(iii) CharacterCount(s, Mississippi)
[1]

UCLES 2012

9691/32/O/N/12

[Turn over

14
8

(a) A high-level programming language has the following built-in function SumRange
defined as follows:

SumRange(ThisInteger1: Integer, ThisInteger2: Integer) RETURNS


Integer
will return the integer value calculated as the sum of all integers between and including
MyInteger1 and MyInteger2.
For Example:
SumRange(11, 14) will return 50
An error is generated if:
The function is not properly formed, or
MyInteger2 is less than MyInteger1

(i) State the function identifier and parameters for the above function.
Function identifier
Parameters
[2]
What value is returned from the following function calls?
(ii) SumRange(1, 3)
[1]
(iii) SumRange(31, 33)
[1]
(iv) SumRange(1.5, 4.5)
[1]
(v) SumRange(78, 71)
[1]

(b) Describe a difference between a user-defined function and a procedure.

[1]

UCLES 2012

9691/33/O/N/12

For
Examiner's
Use

16
7

The function DateDiff is documented as follows:


FUNCTION DateDiff(Date1 : DATE, Date2 : DATE, OutputFlag : CHAR) RETURNS INTEGER

The function assumes Date1 is earlier than Date2.


The function calculates the difference, in days or as a whole number of months, between Date1
and Date2.
OutputFlag takes values:
'D' : the result is computed and returned as a number of days
'M' : the result is computed and returned as a whole number of months

An error is generated for each of the following:


An unrecognised or missing flag parameter
A date parameter in the wrong format
Date1   Date2
Dates are recognised by the function using the hash (#) delimiter.
What is returned from the following function calls?
(a) DateDiff(#12/09/2014#, #15/09/2014#, 'D')
...............................................................................................................................................[1]
(b) DateDiff(#21/10/2014#, #19/10/2014#, 'D')
...............................................................................................................................................[1]
(c) DateDiff(#30/07/2012#, #30/09/2012#, 'M')
...............................................................................................................................................[1]
(d) DateDiff("12/09/2014", "15/09/2014", 'D')
...............................................................................................................................................[1]
(e) DateDiff(#14/01/2014#, #17/01/2014#)
...............................................................................................................................................[1]
(f)

High-level programming languages have two types of function. These are built-in and userdefined.
Explain the difference between them. You may give an example from your practical experience
for a built-in function.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]

18
The function Replace is documented as follows:

FUNCTION Replace(ThisString : STRING, FindString : STRING,


ReplaceString : STRING, [MatchType : CHAR]) RETURNS STRING
Square brackets used in the function header indicate the parameter is optional.
The function searches for FindString within ThisString. When a match is found, all
occurrences of FindString within ThisString are replaced with ReplaceString.
MatchType indicates the type of match looked for:

'E': indicates the strings must match exactly


'C': indicates a match is reported irrespective of the case of either string

The function returns ThisString.


Any function call which is not properly formed returns an error.
What is returned by the following function calls?
(a) Replace("Mary Adams", "Adams", "Kelly", 'E')
...............................................................................................................................................[1]
(b) Replace("10110011", "011", "X", 'E')
...............................................................................................................................................[1]
(c) Replace("Dr Ajaz Drew", "Dr", "", 'E')
...............................................................................................................................................[1]
(d) Replace("database design", "sign")
...............................................................................................................................................[1]
(e) Replace("white box strategy", "STRATEGY", "TESTING", 'C')
.............................................................................................................................................. (1)
(f)

High-level programming languages have two types of function. These are built-in and
user-defined.
Explain the difference between them. You may give an example from your practical experience
for a built-in function.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]

UCLES 2014

9691/32/O/N/14

Page 9
7

Mark Scheme
GCE A LEVEL May/June 2013

Syllabus
9691

Paper
31

(a) (i) 2

[1]

(ii) COMPILE ERROR // reporting an error

[1]

(iii) 0

[1]

(iv) COMPILE ERROR // reporting an error

[1]

(b) (i) FUNCTION StringFound(ThisArray : STRING , UBound : INTEGER,


ThisValue : STRING) RETURNS BOOLEAN
Mark as follows:
FUNCTION StringFound

[1]

Array variable : STRING data type

[1]

ThisValue : STRING // UBound : INTEGER

[1]

(ii) Numbered 1 Parameter identifiers labelled


Numbered 2 (RETURNS) BOOLEAN

[1]
[1]

(iii) CityWasFound = StringFound(CapitalCities, 300, LISBON)


Mark as follows:
CityWasFound = StringFound( ...

[1]

LISBON is the correct position (f/t from their function header)

[1]
[Total: 11]

Cambridge International Examinations 2013

(a) (i) True / Yes

[1]

(ii) False / No

[1]

(iii) COMPILE ERROR

[1]

(iv) COMPILE ERROR

[1]

(b)
FUNCTION CalcNetPay (EmpGrade:CHAR/STRING, HoursWorked:SINGLE/INTEGER)
RETURN SINGLE
[1]
[1]
[1]
A: RETURN REAL/CURRENCY
[Total: 7]

(a) (i) -function name ChangeString


-ThisString1 and ThisString2

[2]

(ii) Lyons W

[1]

(iii) SMITH 9

[1]

(iv) Error

[1]

(b) -self-contained blocks of code


-subprograms
-must be given an identifier
-may have parameters

[2]
[Total: 7]

Cambridge International Examinations 2012

(a) (i) the name given to a function

[1]

(ii) CharacterCount

[1]

(iii) Value(s)/variable(s) which are given/passed (each time the function is called)

[1]

(iv) ThisChar

[1]
[1]

ThisString

(b) (i) 2

[1]

(ii) 0

[1]

(iii) Error

[1]
[Total: 8]

Cambridge International Examinations 2012

(a) (i) function name:


parameters:

SumRange
ThisInteger1 and ThisInteger2

[2]

(ii) 42

[1]

(iii) Error

[1]

(iv) Error

[1]

(v) Error

[1]

(b) A function always returns a value - (procedures may/may not return a value)

[1]
[Total: 7]

(a) 3 (days)

[1]

(b) Error

[1]

(c) 2 (months)

[1]

(d) Error

[1]

(e) Error

[1]

(f) Built-in functions are those provided (as a part of the programming language) //
accept by example
1
User defined functions are designed and coded by the programmer
1

[2]

Cambridge International Examinations 2014

(a)

Mary Kelly

[1]

(b)

1X0X

[1]

(c)

Ajaz ew

[1]

(d)

Error

[1]

(e)

white box TESTING

[1]

(f)

Built-in functions are those provided (as a part of the programming


language) // accept by example
1
User defined functions are designed and coded by the
programmer
1

[2]

Cambridge International Examinations 2014

You might also like