0% found this document useful (0 votes)
6 views20 pages

968_s21_

Uploaded by

hsnalttr
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)
6 views20 pages

968_s21_

Uploaded by

hsnalttr
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/ 20

Cambridge International AS & A Level

CO M P U T E R SCIE N CE 9 6 1 8 /2 2
Paper 2 Fundamental Problem-solving and Programming Skills M ay / J u ne 2 0 2 1

INSERT 2 h ou rs
*3013807674-I*

IN F O R M AT IO N
● This insert contains all the resources referred to in the questions.
● You may annotate this insert and use the blank spaces for planning. D o not w rite y ou r ans w ers on the
insert.

This document has 4 pages.


m
co
e.
at

DC (MB) 200598/3
-m

© UCLES 2021 [ T u rn over


m
xa
.e
w
w
w
2

N ote: An error oc c u rs if a f u nc tion c all is not p rop erly f ormed, or if th e p arameters are inc orrec t.

ST R IN G F u nc tions

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns "FGH"

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

LCASE(ThisChar : CHAR) RETURNS CHAR


returns the character value representing the lower case equivalent of ThisChar
Characters that are not upper case alphabetic are returned unchanged

Example: LCASE('W') returns 'w'

UCASE(ThisChar : CHAR) RETURNS CHAR


returns the character value representing the upper case equivalent of ThisChar
Characters that are not lower case alphabetic are returned unchanged

Example: UCASE('a') returns 'A'

TO_UPPER(ThisString : STRING) RETURNS STRING


returns a string formed by converting all characters of ThisString to upper case

Example: TO_UPPER("Error 803") returns "ERROR 803"

TO_LOWER(ThisString : STRING) RETURNS STRING


returns a string formed by converting all characters of ThisString to lower case

Example: TO_LOWER("JIM 803") returns "jim 803"

NUM_TO_STR(x : <data type>) RETURNS STRING


returns a string representation of a numeric value
m
co

Note: <data type> may be REAL or INTEGER


e.
at
-m

Example: NUM_TO_STR(87.5) returns "87.5"


m
xa

© UCLES 2021 96 18/22/INSERT/M/J/ 21


.e
w
w
w
3

STR_TO_NUM(x : <data type1>) RETURNS <data type2>


returns a numeric representation of a string
Note: <data type1> may be CHAR or STRING
Note: <data type2> may be REAL or INTEGER

Example: STR_TO_NUM("23.45") returns 23.45

IS_NUM(ThisString : STRING) RETURNS BOOLEAN


returns the value TRUE if ThisString represents a valid numeric value
Note: <data type> may be CHAR or STRING

Example: IS_NUM("12.36") returns TRUE


Example: IS_NUM("-12.36") returns TRUE
Example: IS_NUM("12.3a") returns FALSE

ASC(ThisChar : CHAR) RETURNS INTEGER


returns an integer value (the ASCII value) of ThisChar

Example: ASC('A') returns 65

CHR(x : INTEGER) RETURNS CHAR


returns the character whose integer value (the ASCII value) is x

Example: CHR(87)returns 'W'

N U M E R IC F u nc tions

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

RAND(x : INTEGER) RETURNS REAL


returns a real number in the range 0 to x (not inclusive of x)

Example: RAND(87) could return 35.43

D AT E F u nc tions

N ote: D ate f ormat is as s u med to be D D M M Y Y Y Y u nles s oth erw is e s tated.

DAY(ThisDate : DATE) RETURNS INTEGER


returns the current day number from ThisDate

Example: DAY(4/10/2003) returns 4

MONTH(ThisDate : DATE) RETURNS INTEGER


returns the current month number from ThisDate
m
co

Example: MONTH(4/10/2003) returns 10


e.
at
-m
m
xa

© UCLES 2021 96 18/22/INSERT/M/J/ 21 [ T u rn over


.e
w
w
w
4

YEAR(ThisDate : DATE) RETURNS INTEGER


returns the current year number from ThisDate

Example: YEAR(4/10/2003) returns 2003

DAYINDEX(ThisDate : DATE) RETURNS INTEGER


returns the current day index number from ThisDate where Sunday = 1, Monday = 2,
Tuesday = 3 etc.

Example: DAYINDEX(12/05/2020) returns 3

SETDATE(Day, Month, Year : INTEGER) RETURNS DATE


returns a variable of type DATE

NOW() RETURNS DATE


returns the current date

O T H E R F u nc tions

EOF(FileName : STRING) RETURNS BOOLEAN


returns TRUE if there are no more lines to be read from file FileName

Note: This function will generate an ERROR if the file is not already open in READ mode

O P E R AT O R S

Concatenates (joins) two strings


& Example: "Summer" & " " & "Pudding" evaluates to "Summer Pudding"
Note: This operator may also be used to concatenate a character with a string
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE evaluates to FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE evaluates to TRUE
Performs a logical NOT on a Boolean value
NOT
Example: NOT TRUE evaluates to FALSE
Finds the remainder when one number is divided by another
MOD
Example: 10 MOD 3 evaluates to 1
Finds the quotient when one number is divided by another
DIV
Example 10 DIV 3 evaluates to 3

N ote: An error is generated if an op erator is u s ed w ith a valu e or valu es of an inc orrec t ty p e.

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.
m

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
co

Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
e.

at www.cambridgeinternational.org after the live examination series.


at
-m

Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of
Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge.
m
xa

© UCLES 2021 96 18/22/INSERT/M/J/ 21


.e
w
w
w
Cambridge International AS & A Level
* 3 0 1 3 8 0 7 6 7 4 *

CO M P U T E R SCIE N CE 9 6 1 8 /2 2
Paper 2 Fundamental Problem-solving and Programming Skills M ay / J u ne 2 0 2 1

2 h ou rs

You must answer on the question paper.

You will need: Insert (enclosed)

IN ST R U CT IO N S
● Answer all questions
● Use a black or dark blue pen.
● W rite your name, centre number and candidate number in the boxes at the top of the page.
● W rite your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an H B pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.

IN F O R M AT IO N
● The total mark for this paper is 7 5.
● The number of marks for each question or part question is shown in brackets [ ] .
● No marks will be awarded for using brand names of software packages or hardware.
● The insert contains all the resources referred to in the questions.

This document has 1 6 pages. Any blank pages are indicated.


m
co
e.
at

DC (MB/FC) 200588/5
-m

© UCLES 2021 [ T u rn over


m
xa
.e
w
w
w
2

Refer to the ins ert for the list of pseudocode functions and operators.

1 ( a) ( i) Complete the following table by giving the appropriate data type in each case.

V ariable E x amp le data valu e D ata ty p e


Name "Catherine"
Index 100
Modif ied FALSE
Holiday 25/12/2020
[4 ]

( ii) Evaluate each expression in the following table by using the initial data values shown in
p art ( a) ( i) .

E x p res s ion E valu ates to


Modif ied OR Index > 100
LENGTH("Student: " & Name)
INT(Index + 2.9 )
MID(Name, 1, 3)
[4 ]

( b) Each pseudocode statement in the following table contains an example of selection,


assignment or iteration.

Put one tick (‘ ✓’ ) in the appropriate column for each statement.

Statement Selec tion As s ignment Iteration


Index Index + 1
IF Modif ied = TRUE THEN
ENDWHILE
[ 3] m
co
e.
at
-m
m
xa

© UCLES 2021 96 18/22/M/J/ 21


.e
w
w
w
3

2 ( a) Examine the following state-transition diagram.

Low level detected | Activate pump

Low level detected

X S2
S1

Normal level detected Normal level detected | Deactivate pump


S3

( i) Complete the table with reference to the diagram.

Ans w er
The number of transitions that result in a different state
The number of transitions with associated outputs
The label that should replace ‘ X ’
The final or halting state
[4 ]

( ii) The current state is S1. The following inputs occur.

1. Low level detected


2. Low level detected
3. Low level detected
4 . Low level detected

Give the number of outputs and the current state.

Number of outputs .............................................................................................................

Current state .....................................................................................................................


[ 2]
m
co
e.
at
-m
m
xa

© UCLES 2021 96 18/22/M/J/ 21 [ T u rn over


.e
w
w
w
4

( b) A system is being developed to help manage book loans in a library.

Registered users may borrow books from the library for a period of time.

( i) State th ree items of data that must be stored for each loan.

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

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

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

( ii) State one item of data that will be required in the library system but does not need to be
stored for each loan.

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

( iii) One operation that manipulates the data stored for each loan, would produce a list of all
overdue books.

Identify tw o oth er operations.

Operation 1 .......................................................................................................................

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

Operation 2 .......................................................................................................................

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

m
co
e.
at
-m
m
xa

© UCLES 2021 96 18/22/M/J/ 21


.e
w
w
w
5

3 The following diagram represents an Abstract Data Type (ADT).

A B
Dolphin Cat Fish Elk

( a) Identify this type of ADT.

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

( b) Give the technical term for the item labelled A in the diagram.

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

(c ) Give the technical term for the item labelled B in the diagram.

Explain the meaning of the value given to this item.

Term ..........................................................................................................................................

Meaning ....................................................................................................................................

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

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

( d) Complete the diagram to show the ADT after the data has been sorted in alphabetical order.

Dolph in C at F ish E lk

[ 2]
m
co
e.
at
-m
m
xa

© UCLES 2021 96 18/22/M/J/ 21 [ T u rn over


.e
w
w
w
6

4 A teacher uses a paper-based system to store marks for a class test. The teacher requires a
program to assign grades based on these results.

The program will output the grades together with the average mark.

W rite a detailed description of the algorithm that will be needed.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

..........................................................................................................................................................
m
co

.................................................................................................................................................... [ 6 ]
e.
at
-m
m
xa

© UCLES 2021 96 18/22/M/J/ 21


.e
w
w
w
7

5 ( a) A student is learning about arrays.

She wants to write a program to:

• declare a 1D array RNum of 100 elements of type INTEGER


• assign each element a random value in the range 1 to 200 inclusive
• count and output how many numbers generated were between 6 6 and 17 3 inclusive.

( i) W rite pseudocode to represent the algorithm.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

( ii) The student decides to modify the algorithm so that each element of the array will contain
a unique value.

Describe the changes that the student needs to make to the algorithm.

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

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

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

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

...........................................................................................................................................
m
co

..................................................................................................................................... [ 3]
e.
at
-m
m
xa

© UCLES 2021 96 18/22/M/J/ 21 [ T u rn over


.e
w
w
w
8

( b) The following is a pseudocode function.

Line numbers are given for reference only.

01 FUNCTION StringClean(InString : STRING) RETURNS STRING


02
03 DECLARE NextChar : CHAR
04 DECLARE OutString : STRING
05 DECLARE Counter : INTEGER
06
07 OutString ""
08
09 FOR Counter 1 TO LENGTH(InString)
10 NextChar MID(InString, Counter, 1)
11 NextChar LCASE(NextChar)
12 IF NOT((NextChar < 'a') OR (NextChar > 'z ')) THEN
13 OutString OutString & NextChar
14 ENDIF
15 NEXT Counter
16
17 RETURN OutString
18
19 ENDFUNCTION

( i) Examine the pseudocode and complete the following table.

Ans w er

Give a line number containing an example of an initialisation statement.

Give a line number containing the start of a repeating block of code.

Give a line number containing a logic operation.

Give the number of parameters to the function MID().


[4 ]

( ii) W rite a simplified version of the statement in line 12.

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

..................................................................................................................................... [ 2]
m
co
e.
at
-m
m
xa

© UCLES 2021 96 18/22/M/J/ 21


.e
w
w
w
9

B LAN K P AG E

m
co
e.
at
-m
m
xa

© UCLES 2021 96 18/22/M/J/ 21 [ T u rn over


.e
w
w
w
1 0

6 A procedure CountVowels() will:

• be called with a string containing alphanumeric characters as its parameter


• count and output the number of occurrences of each vowel (a, e, i, o, u) in the string
• count and output the number of occurrences of the other alphabetic characters (as a single
total).

The string may contain both upper and lower case characters.

Each count value will be stored in a unique element of a global 1D array CharCount of type
INTEGER. The array will contain six elements.

W rite pseudocode for the procedure CountVowels().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

..........................................................................................................................................................
m

..........................................................................................................................................................
co
e.
at

..........................................................................................................................................................
-m
m
xa

© UCLES 2021 96 18/22/M/J/ 21


.e
w
w
w
1 1

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

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

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

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

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

7 A procedure, FormatName():

• is called with a string containing words and spaces as its parameter. In this context, a word is
any sequence of characters that does not contain a space character.

• creates a new formatted string from this string with the following requirements:
1. Any leading spaces removed (spaces before the first word).
2. Any trailing spaces removed (spaces after the last word).
3. Any multiple spaces between words converted to a single space.
4 . All characters converted to lower case.

The FormatName() procedure has been written in a programming language and is to be tested
using the black-box method.

( a) Give a test string that could be used to show that all f ou r formatting requirements have been
applied correctly.

Use the symbol ‘ ∇’ to represent a space character.

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

( b) The FormatName() procedure should assign a value to the global variable FString.

There is a fault in the program, which means that the assignment does not always take place.

Explain tw o ways of exposing the fault.

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

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

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

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

............................................................................................................................................. [ 2]
m
co
e.
at
-m
m
xa

© UCLES 2021 96 18/22/M/J/ 21 [ T u rn over


.e
w
w
w
1 2

8 A program is needed to take a string containing a full name and to produce a new string of initials.

Some words in the full name will be ignored. For example, “ the” , “ and” , “ of” , “ for” and “ to” may all
be ignored.

Each letter of the new string must be upper case.

For example:

F u ll name Initials
Integrated Development Environment IDE
The American Standard Code for Information Interchange ASCII

The programmer has decided to use the following global variables:

• a ten element 1D array IgnoreList of type STRING to store the ignored words
• a string FNString to store the full name string.

Assume that:

• each alphabetic character in the full name string may be either upper or lower case
• the full name string contains at least one word.

The programmer has started to define program modules as follows:

M odu le D es c rip tion


• Called with an INTEGER as its parameter, representing the number of
a word in FNString
GetStart() • Returns the character start position of that word in FNString or
returns -1 if that word does not exist
• For example: GetStart(3) applied to "hot and c old" returns 9
• Called with the position of the first character of a word in FNString
as its parameter
GetWord() • Returns the word from FNString
• For example: if FNString contains the string "hot and c old",
GetWord(9 ) returns "c old"
• Called with a STRING parameter representing a word
IgnoreWord() • Searches for the word in the IgnoreList array
• Returns TRUE if the word is found, otherwise returns FALSE
• Processes the sequence of words in the full name one word at a time
GetInitials()
• Calls GetStart(), GetWord() and IgnoreWord() to process
each word to form the new string
• Outputs the new string
m
co
e.
at
-m
m
xa

© UCLES 2021 96 18/22/M/J/ 21


.e
w
w
w
1 3

( a) W rite pseudocode for the module IgnoreWord().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [ 5]
m
co
e.
at
-m
m
xa

© UCLES 2021 96 18/22/M/J/ 21 [ T u rn over


.e
w
w
w
1 4

( b) W rite pseudocode for the module GetInitials().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

...................................................................................................................................................
m
co

...................................................................................................................................................
e.
at
-m

............................................................................................................................................. [ 8]
m
xa

© UCLES 2021 96 18/22/M/J/ 21


.e
w
w
w
1 5

B LAN K P AG E

m
co
e.
at
-m
m
xa

© UCLES 2021 96 18/22/M/J/ 21


.e
w
w
w
1 6

B LAN K P AG E

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.
m

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
co

Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
e.

at www.cambridgeinternational.org after the live examination series.


at
-m

Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of
Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge.
m
xa

© UCLES 2021 96 18/22/M/J/ 21


.e
w
w
w

You might also like