A Adam Learning
Back to notes
9618-AS-10-03Chapter 10Section 10.3short-answer

10.3 Files 文件概念简答

Review the exact wording students need for this knowledge point, then open a filtered question list when ready to practise.

Find questions for 9618-AS-10-03

Scope

本页解释 files 的用途、persistence、file modes 与文字描述算法。File-handling pseudocode 留到专项。

Why files are needed

Variables and arrays normally hold data in main memory while a program runs。A file provides permanent/non-volatile storage

  • Data remains after the program ends or power is switched off。
  • Data can be loaded when the program runs again。
  • Large quantities of data do not need to be entered again。
  • Data can be shared or transferred between programs/users。

Mark-scheme pattern

A file stores data permanently, so it is not lost when the program terminates and can be restored when the program is run again.

File modes

ModeEffect
READExisting data is read; file contents are not replaced.
WRITECreates/replaces a file; existing content may be overwritten/deleted.
APPENDAdds new data after existing content without deleting it.

若现有 support list 必须保留并增加 names,应使用 APPEND。WRITE 会 overwrite existing data。

Describing a file algorithm

完整步骤通常包含:

  • Open the named file in the correct mode。
  • Initialise any line number, index, flag or accumulator。
  • Repeat until EOF or required count/condition。
  • Read one line inside the loop。
  • Convert/extract/compare the required data。
  • Write or output only when the condition is met。
  • Update index/counter inside the loop。
  • Close the file after processing。

固定长度 fields 的 search 还要说明如何使用 field positions/substring 提取目标 field。

Multiple save files

Use a counter/sequential suffix in the filename, incremented for each save,例如 SaveFile01.txtSaveFile02.txt。这样 filename 反映保存顺序且旧 save 不被覆盖。

Exam checklist

  • 是否写到 permanent storage?
  • Mode 是否与保留/覆盖需求匹配?
  • 描述是否包含 open、loop/read、process、close?
  • EOF/停止条件是否明确?
  • 是否避免在 “Do not include pseudocode” 题中写代码语句?

File declarations、EOF loops、READFILE/WRITEFILE 等语法留到代码专项。

Practice This Knowledge Point

Open the question bank with this knowledge code already filled in. The filtered list will show matching questions for this note.

Open filtered practice
Source questions used