Question 6(c) 2019 · May-June · Paper 22 · 3 marks
Reveal official mark-scheme answer
Official answer for Question 6
Part (c)
Question 3
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
- 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
- Input a preferred name. This will be an empty string if no preferred
- Concatenate the user ID and preferred name using a '*' character as
- Append the concatenated string to the file
- Close the file
- Return a Boolean value:
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
GetInfo() • Input a user ID and repeat until the user ID is valid
name is input.
a separator and return this string WriteInfo() • Open the file
○ TRUE if the file write was successful ○ FALSE if the file write failed, for example, if the disk was full
- 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().
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................
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
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
