Past-paper question · 2019 May-June · Paper 22 · Q5(b)

Question 5(b) 2019 · May-June · Paper 22 · 6 marks

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

Official answer for Question 5

Part (b)

✓
PROCEDURE CountLines(FileName : STRING)

Question 6

✓
DECLARE NumLines : INTEGER
✓
DECLARE Dummy : STRING
✓
NumLines ← 0
✓
OPENFILE FileName FOR READ
✓
WHILE NOT EOF(FileName)
✓
READFILE FileName, Dummy
✓
NumLines ← NumLines + 1
✓
ENDWHILE
✓
CLOSEFILE FileName
✓
OUTPUT "Number of lines in the file : ", NumLines
✓
ENDPROCEDURE
✓
One mark for each of the following:
✓
1.
✓
Procedure header and end, including parameter
✓
2.
✓
Declaration and initialisation of a local INTEGER to count lines (e.g. NumLines)
✓
3.
✓
OPEN file in read mode and CLOSE file
✓
4.
✓
WHILE loop stopping when EOF(FileName)
✓
5.
✓
Read a line from the file and increment NumLines in a loop
✓
6.
✓
Output a message plus the NumLines outside a loop
✓
9608/22
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2019
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s19_ms_22.pdf →

Show text version of question

Question 5

Part (b)

Question 5

A student is learning about text files. She wants to write a program to count the number of lines in

a file.

Part (b)

A procedure, CountLines(), is being written to count the number of lines in a text file. The

procedure will:

  • take a filename as a string parameter
  • count the number of lines in the file
  • output a single suitable message that includes the total number of lines.

Write pseudocode for the procedure CountLines().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[6]

Question 12

Topic relevance

Why this question appears here

71% assigned-topic match · Programming › Structured programming

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