Past-paper question · 2019 May-June · Paper 22 · Q6(c)

Question 6(c) 2019 · May-June · 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)
Reveal official mark-scheme answer Official mark-scheme answer for 6(C)

Official answer for Question 6

Part (c)

✓
FUNCTION WriteInfo (FileData : STRING, Filename : STRING)

Question 3

✓
RETURNS BOOLEAN
✓
One mark per underlined section
✓
*** End of Mark Scheme – example program code solutions follow ***
✓
9608/22
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2019
✓
PUBLISHED
✓
Program Code Example Solutions
✓
Q6 (a): Visual Basic
✓
Function GetInfo() As String
✓
Dim ID As String = ""
✓
Dim PreferredName As String = ""
✓
Dim Valid As Boolean = False
✓
While Valid = False
✓
Console.Write("Please enter a valid ID : ")
✓
ID = Console.ReadLine()
✓
If Len(ID) = 5 And Left(ID, 1) >= "A" And Left(ID, 1) <= "Z" __
✓
And IsNumeric(Right(ID, 4)) Then
✓
Valid = True
✓
End If
✓
End While
✓
Console.Write("Please enter preferred name : ")
✓
PreferredName = Console.ReadLine()
✓
Return ID & "*" & PreferredName
✓
End Function
✓
Alternative:
✓
Function GetInfo() As String
✓
Dim
✓
ID As String
✓
Dim
✓
PreferredName As String
✓
Dim
✓
Valid As Boolean
✓
Dim
✓
Number As String
✓
Dim
✓
Size As Integer
✓
Dim
✓
i As Integer
✓
Valid = False
✓
While Valid = False
✓
Console.WriteLine("Please Enter a valid ID")
✓
ID = Console.ReadLine()
✓
Size = Len(ID)
✓
If (Size = 5) And ((Left(ID, 1) >= "A") And (Left(ID, 1) <= "Z"))
✓
Then
✓
Valid = True
✓
For i = 2 To 5
✓
Number = Mid(ID, i, 1)
✓
If (Number < "0") Or (Number > "9") Then
✓
Valid = False
✓
End If
✓
Next
✓
End If
✓
End While
✓
Console.WriteLine("Please enter preferred name")
✓
PreferredName = Console.ReadLine()
✓
Return (ID & "*" & PreferredName)
✓
End Function
✓
9608/22
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2019
✓
PUBLISHED
✓
Q6 (a): Pascal
✓
function GetInfo() : String;
✓
var
✓
ID : String;
✓
PreferredName : String;
✓
Valid : Boolean;
✓
Value, Code : Integer;
✓
begin
✓
Valid := false;
✓
while not Valid do
✓
begin
✓
Write('Please enter a valid ID : ');
✓
Readln(ID);
✓
if (Length(ID) = 5) and (ID[1] >= 'A') and (ID[1] <= 'Z') then
✓
Valid := true;
✓
Val(Copy(ID, 2, 4), Value, Code);
✓
if Code <> 0 then
✓
Valid := false;
✓
end;
✓
Write('Please enter preferred name : ');
✓
Readln(PreferredName);
✓
GetInfo := ID + '*' + PreferredName;
✓
end;
✓
Free Pascal
✓
function GetInfo() : String;
✓
var
✓
ID : String;
✓
PreferredName : String;
✓
Valid : Boolean;
✓
Value, Code : Integer;
✓
begin
✓
Valid := false;
✓
while not Valid do
✓
begin
✓
Write('Please enter a valid ID : ');
✓
Readln(ID);
✓
if (Length(ID) = 5) and (ID[1] >= 'A') and (ID[1] <= 'Z') __
✓
and (IsNumber(SubStr(ID, 2, 4))) then
✓
Valid := true;
✓
end;
✓
Write('Please enter preferred name : ');
✓
Readln(PreferredName);
✓
result := ID + '*' + PreferredName;
✓
end;
✓
9608/22
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2019
✓
PUBLISHED
✓
Q6 (a): Python
✓
def GetInfo() :
✓
ID = ""
✓
# string variable
✓
PreferredName = ""
✓
# string variable
✓
Valid = False
✓
# Boolean variable
✓
while not Valid :
✓
ID = input("Please enter a valid ID : ")
✓
if len(ID) == 5 and ID[0] >= "A" and ID[0] <= "Z" and
✓
ID[1:].isnumeric() :
✓
Valid = True
✓
PreferredName = input("Please enter preferred name : ")
✓
return ID + "*" + PreferredName

Mark scheme 9608_s19_ms_22.pdf →

Show text version of question

Question 6

Part (c)

Question 6

Nadine is developing a program to store the ID and preferred name for each student in a school.

For example, student Pradeep uses the preferred name “Prad”.

The program will:

1. prompt and input a valid user ID and a preferred name 2. write the user ID and preferred name to one of two files 3. allow the user to end the program or repeat from step 1.

The program will consist of three separate modules. Each module will be implemented using either a procedure or a function.

Nadine has defined the modules as follows:

Module Description TopLevel() • Call GetInfo() to obtain a string containing a valid user ID and a preferred name

  • Call WriteInfo() to write the string to either File1.txt or
  • File2.txt depending on the first character of the user ID as follows: ○ ‘A’ to ‘M’: writes to File1.txt ○ ‘N’ to ‘Z’: writes to File2.txt For example, a string with a user ID of "G1234" writes to File1.txt

  • End the program if the file write was unsuccessful
  • Input (Y/N) to either repeat for the next user ID or to end the program
  • GetInfo() • Input a user ID and repeat until the user ID is valid

  • Input a preferred name. This will be an empty string if no preferred
  • name is input.

  • Concatenate the user ID and preferred name using a '*' character as
  • a separator and return this string WriteInfo() • Open the file

  • Append the concatenated string to the file
  • Close the file
  • Return a Boolean value:

○ TRUE if the file write was successful ○ FALSE if the file write failed, for example, if the disk was full

A
valid user ID:
  • is five characters in length
  • has a single upper case alphabetic character followed by four numeric characters, for

example “G1234”.

Nadine has decided that global variables and nested modules must not be used.

Nadine wants all inputs to have suitable prompts.

Question 13

Part (c)

Write pseudocode for the module declaration of WriteInfo().

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

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

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

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

[3]

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.

Question 16

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.

Example: NUM_TO_STRING(87.5) returns "87.5" Note: This function will also work if x is of type INTEGER

STRING_TO_NUM(x : STRING) RETURNS REAL returns a numeric representation of a string.

Example: STRING_TO_NUM("23.45") returns 23.45 Note: This function will also work if x is of type CHAR

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

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_s19_qp_22.pdf

Keep practising this topic