Past-paper question · 2024 May-June · Paper 42 · Q1(a)

Question 1(a) 2024 · May-June · Paper 42 · 6 marks

Original past-paper question for 1(A)
Original past-paper question for 1(A)
Reveal official mark-scheme answer Official mark-scheme answer for 1(A)

Official answer for Question 1

Part (a)

Question 1

mark each to max 6

Question 6

✓
Procedure declaration (and end where appropriate) taking (string) parameter
✓
Declaration of array to store the data read (type string, suitable number of elements e.g. 150)
✓
Opening file to read…
✓
... using exception handling with try and catch and output
✓
Reading in the data for each line in that file and storing in array…
✓
… removing carriage return (Java, Python)
✓
Counting the number of words
✓
Closing the file (might be within the Python opening file statement)
✓
e.g.
✓
Java
✓
public static void ReadWords(String FileName){
✓
try{
✓
FileReader f = new FileReader(FileName);
✓
try{
✓
BufferedReader Reader = new BufferedReader(f);
✓
String Line= Reader.readLine();
✓
while (Line != null){
✓
WordArray[NumberWords] = Line.replace("\n","");
✓
NumberWords++;
✓
Line = Reader.readLine();
✓
}
✓
Reader.close();
✓
}catch(IOException ex){}
✓
9618/42
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2024
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9618_s24_ms_42.pdf →

Show text version of question

Question 1

Part (a)

Question 1

A program outputs a main word. The program asks the user to enter the different words of 3 or

more letters that can be made from the letters in the main word. These are called the answers.

There are 3 files: Easy.txt, Medium.txt and Hard.txt. Each file has the main word on the first line. For example, the main word in Easy.txt is house.

The answers are stored in the file. Each answer is on a new line after the main word. For example, Easy.txt has 14 answers that can be made from the letters in house.

The words read from the text file are stored in the global array WordArray. The number of words that can be made from the letters in the main word is stored in the global variable NumberWords.

Part (a)

The procedure ReadWords():

  • takes a file name as a parameter
  • opens the file and reads in the data
  • stores the main word in the first element in WordArray
  • stores each answer in a new element in WordArray
  • counts and stores the number of answers.

Write program code for the procedure ReadWords().

Save your program as Question1_J24.

Copy and paste the program code into part 1(a) in the evidence document.

[6]
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 9618_s24_qp_42.pdf

Keep practising this topic