Past-paper question · 2018 October-November · Paper 22 · Q5

Question 5 2018 · October-November · Paper 22 · 11 marks

Original past-paper question for 5
Original past-paper question for 5
Original past-paper question for 5
Reveal official mark-scheme answer Official mark-scheme answer for 5

Official answer for Question 5

✓
PROCEDURE LineNumber(FileName: STRING,

Question 11

✓
StartNumber: INTEGER, StepNumber: INTEGER)
✓
DECLARE
✓
FileData : STRING
✓
DECLARE
✓
Count : INTEGER
✓
DECLARE
✓
Reply : CHAR
✓
DECLARE
✓
Continue : BOOLEAN
✓
Count ← 0
✓
Continue ← TRUE
✓
OPENFILE FileName FOR READ
✓
WHILE NOT EOF(FileName) AND Continue = TRUE
✓
READFILE FileName, FileData
✓
FileData ← NUM_TO_STRING(StartNumber) & ": " &
✓
FileData
✓
OUTPUT FileData
✓
Count ← Count + 1
✓
IF Count = 20 THEN
✓
OUTPUT "Do you wish to continue?"
✓
INPUT Reply
✓
IF Reply = 'N'
✓
THEN
✓
Continue ← FALSE
✓
ELSE
✓
Count ← 0
✓
ENDIF
✓
ENDIF
✓
StartNumber ← StartNumber + StepNumber
✓
ENDWHILE
✓
CLOSEFILE FileName
✓
ENDPROCEDURE
✓
9608/22
✓
Cambridge International AS/A Level – Mark Scheme
✓
October/November
✓
PUBLISHED
✓
2018
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_w18_ms_22.pdf →

Show text version of question

Question 5

The procedure LineNumber() will:

  • read data from a text file
  • modify each line by adding a line number, and the string (": ")
  • output each modified line.

For example, when the procedure reads MyFile.txt, the output is:

10: <First line of MyFile.txt> 15: <Second line of MyFile.txt> 20: <Third line of MyFile.txt>

…

350: <Last line of MyFile.txt>

The procedure takes three parameters:

Identifier Data type Description FileName STRING The name of the text file StartNumber INTEGER The first line number to be added StepNumber INTEGER The line number increment

In this example, the procedure call would be:

CALL LineNumber("MyFile.txt", 10, 5)

After every 20 lines, the program outputs a message asking whether the user wants to continue.

The program ends when the user enters an 'N' or the end of file is reached.

Write pseudocode for the LineNumber() procedure.

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

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

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

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

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

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

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

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

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

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

Question 15

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[11]

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 string "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 string "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING returns rightmost x characters from ThisString

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

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

Example: If x has the value 87.5 then NUM_TO_STRING(x) will return "87.5" Note: This function will also work if x is of type integer.

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

Example: INT(27.5415) returns 27

ASC(ThisChar : CHAR) RETURNS INTEGER returns the ASCII value of character ThisChar

Example: ASC('A') returns 65

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

91% 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_w18_qp_22.pdf

Keep practising this topic