Past-paper question · 2019 October-November · Paper 22 · Q6(c)

Question 6(c) 2019 · October-November · Paper 22 · 3 marks

Original past-paper question for 6(C)
Original past-paper question for 6(C)
Original past-paper question for 6(C)
Original past-paper question for 6(C)
Original past-paper question for 6(C)
Original past-paper question for 6(C)
Original past-paper question for 6(C)
Reveal official mark-scheme answer Official mark-scheme answer for 6(C)

Official answer for Question 6

Part (c)

✓
'Pseudocode' solution included here for development and clarification of mark

Question 3

✓
scheme.
✓
Programming language example solutions appear in the Appendix.
✓
One mark per underlined section:
✓
Result ← CountTimes (Leavers, "")
✓
(Space before open bracket to highlight underlined section only)
✓
9608/22
✓
Cambridge International AS/A Level – Mark Scheme
✓
October/November
✓
PUBLISHED
✓
2019
✓
Program Code Example Solutions
✓
Q6 (a): Visual Basic
✓
Function SearchLeavers(ByVal Reference As String) As Boolean
✓
Dim Index As Integer
✓
Dim Found As Boolean
✓
Found = FALSE
✓
Index = 0
✓
Do While Index < 500 And Not Found
✓
If Reference = Leavers(Index) Then
✓
Found = TRUE
✓
End If
✓
Index = Index + 1
✓
Loop
✓
Return Found
✓
End Function
✓
9608/22
✓
Cambridge International AS/A Level – Mark Scheme
✓
October/November
✓
PUBLISHED
✓
2019
✓
Q6 (a): Pascal
✓
function SearchLeavers(Reference : String) : boolean;
✓
var Index : integer;
✓
var Found : boolean;
✓
begin
✓
Found := FALSE;
✓
Index := 0;
✓
While Index < 500 And Not Found
✓
begin
✓
if Reference = Leavers[Index] Then
✓
Found := TRUE;
✓
Index := Index + 1;
✓
end;
✓
result := Found; // SearchLeavers := Found
✓
end;
✓
Q6 (a): Python
✓
def SearchLeavers(Reference):
✓
## Index : Integer
✓
## Found : Boolean
✓
Found = False
✓
Index = 0
✓
while Index < 500 and not Found:
✓
if Reference == Leavers[Index]:
✓
Found = True
✓
Index = Index + 1
✓
return Found
✓
9608/22
✓
Cambridge International AS/A Level – Mark Scheme
✓
October/November
✓
PUBLISHED
✓
2019
✓
Q6 (c): Visual Basic
✓
Result = CountTimes(Leavers, "")
✓
Q6 (c): Pascal
✓
Result := CountTimes(Leavers, "");
✓
Q6 (c): Python
✓
Result = CountTimes(Leavers, "")

Mark scheme 9608_w19_ms_22.pdf →

Show text version of question

Question 6

Part (c)

Question 6

A text file, StudentList.txt, contains a list of information about students in a school.

Each line of the file contains a reference, name and date of birth for one student. All the information is held as strings and separated by the asterisk character ('*') as follows:

<Reference>'*'<Name>'*'<Date Of Birth>

An example of one line from the file is:

"G1234*Aleza Hilton*05062001"

The reference string may be five or eight characters in length and is unique for each student. It is made up of alphabetic and numeric characters only.

A
global 1D array, Leavers, contains the references of all students who have recently left the

school. The array consists of 500 elements of data type STRING. Unused elements contain the empty string "".

A
program is to be written to produce a new text file, UpdatedList.txt, containing information

only for students who are still attending the school.

The program is to be implemented as several modules. The outline description of three of these is as follows:

Module Outline description

  • Read each line from the file StudentList.txt
  • Check whether the Reference appears in the
  • array using SearchLeavers() ProcessStudentList()

  • If the Reference does not appear then write the
  • line to the file UpdatedList.txt

  • Return the number of lines not copied.
  • Search for a given Reference in the array Leavers
  • SearchLeavers() • If the Reference is found, return TRUE, otherwise return FALSE

  • Take two parameters: the name of an array and a
  • string. CountTimes()

  • Count the number of elements that are the same as

the string. Return the count value.

Question 15

Part (c)

CountTimes() is to be used to count how many unused elements there are in the Leavers

array. An unused element is one that contains an empty string.

The module description is repeated here for reference.

Module Outline description

  • Take two parameters: the name of an array and a
  • string. CountTimes()

  • Count the number of elements that are the same as

the string. Return the count value.

Write a statement in program code that uses CountTimes() to assign the count of unused elements to the variable Result.

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

Program code

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

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

[3]

Question 18

Appendix Built-in functions (pseudocode)

Each function returns an error if the function call is not properly formed.

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

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"

INT(x : REAL) RETURNS INTEGER returns the integer part of x

Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING returns a string representation of a numeric value. Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

STRING_TO_NUM(x : STRING) RETURNS REAL returns a numeric representation of a string. Note: This function will also work if x is of type CHAR

Example: STRING_TO_NUM("23.45") returns 23.45

Operators (pseudocode)

Operator Description Concatenates (joins) two strings & Example: "Summer" & " " & "Pudding" produces "Summer Pudding" Performs a logical AND on two Boolean values AND Example: TRUE AND FALSE produces FALSE Performs a logical OR on two Boolean values OR Example: TRUE OR FALSE produces TRUE

Question 19

Question 20

reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will be pleased to make amends at the earliest possible opportunity.

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cambridgeinternational.org after the live examination series.

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.

Topic relevance

Why this question appears here

99% assigned-topic match · Data types and structures › Data types and records

Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.

Permanent source page: Educate A Change · From 9608_w19_qp_22.pdf

Keep practising this topic