File identifier: the file name as a string

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

File identifier: the file name as a string

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line uses a correct file identifier?
A OPENFILE FileA.txt FOR WRITE
B OPENFILE "FileA.txt" FOR WRITE
2. A file identifier is which data type?
A INTEGER
B STRING
3. Which file identifier includes the extension?
A "Scores.txt"
B "Scores"
4. A program writes to "Names.txt" and later reads the same data back. Which is correct?
A Use "Names.txt" in every file command
B Use a different file name for each command
5. Which pair of lines uses the identifier consistently?
A OPENFILE "Data.txt" FOR WRITE and CLOSEFILE "Data.txt"
B OPENFILE "Data.txt" FOR WRITE and CLOSEFILE "Info.txt"

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1OPENFILE "FileA.txt" FOR WRITE AThe identifier is not the same in both commands. The first has no .txt extension, so the commands refer to different files.
2"Scores.txt" BOPENFILE "Names.txt" FOR WRITE
3The same file identifier must be used in every file command that works on that file. CThe file identifier has no double quotes. A file identifier is a STRING, so it must be written as "FileA.txt".
4A file identifier is a STRING value, so the file name goes inside double quotes and includes the extension .txt. DOPENFILE "Data.txt" FOR READ READFILE "Data.txt", Line CLOSEFILE "Data.txt"
5OPENFILE FileA.txt FOR WRITE EOpens the file named FileA.txt so data can be written to it. The file identifier is a string in double quotes.
6OPENFILE "Scores" FOR READ CLOSEFILE "Scores.txt" FA file identifier: the file name written as a STRING value, in double quotes, with its extension.

Definitions

"FileA.txt"

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
OPENFILE "Scores.txt" FOR READ READFILE "__________", Score
2.
OPENFILE "Names____" FOR WRITE
3.
DECLARE FileName : ______ FileName ← "Data.txt" OPENFILE FileName FOR READ
4.
OPENFILE "Log.txt" FOR WRITE WRITEFILE "Log.txt", "Done" CLOSEFILE "_______"
5.
FileName ← "Data.txt" OPENFILE ________ FOR READ READFILE FileName, Line

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A DECLARE Name : STRING
B OPENFILE "Names.txt" FOR WRITE
C WRITEFILE Names.txt, Name
D CLOSEFILE "Names.txt"
Question 2
A DECLARE Line : STRING
B OPENFILE "Diary.txt" FOR READ
C READFILE "Diary.txt", Line
D CLOSEFILE "Dairy.txt"
Question 3
A DECLARE Mark : INTEGER
B OPENFILE "Mark.txt" FOR WRITE
C WRITEFILE "Marks.txt", Mark
D CLOSEFILE "Marks.txt"
Question 4
A DECLARE Entry : STRING
B OPENFILE "Log.txt" FOR READ
C READFILE 'Log.txt', Entry
D CLOSEFILE "Log.txt"
Question 5
A DECLARE Score : INTEGER
B OPENFILE "Quiz.txt" FOR WRITE
C Score ← 15
D WRITEFILE "Quiz.txt, Score
E CLOSEFILE "Quiz.txt"

Answer Key

File identifier: the file name as a string
Section A: Quick Questions
Q1
B — OPENFILE "FileA.txt" FOR WRITE
Q2
B — STRING
Q3
A — "Scores.txt"
Q4
A — Use "Names.txt" in every file command
Q5
A — OPENFILE "Data.txt" FOR WRITE and CLOSEFILE "Data.txt"
Section B: Match the Pairs
Q1
OPENFILE "FileA.txt" FOR WRITE → Opens the file named FileA.txt so data can be written to it. The file identifier is a string in double quotes.
Q2
"Scores.txt" → A file identifier: the file name written as a STRING value, in double quotes, with its extension.
Q3
The same file identifier must be used in every file command that works on that file. → OPENFILE "Data.txt" FOR READ READFILE "Data.txt", Line CLOSEFILE "Data.txt"
Q4
A file identifier is a STRING value, so the file name goes inside double quotes and includes the extension .txt. → OPENFILE "Names.txt" FOR WRITE
Q5
OPENFILE FileA.txt FOR WRITE → The file identifier has no double quotes. A file identifier is a STRING, so it must be written as "FileA.txt".
Q6
OPENFILE "Scores" FOR READ CLOSEFILE "Scores.txt" → The identifier is not the same in both commands. The first has no .txt extension, so the commands refer to different files.
Section C: Definitions
Q1
"FileA.txt" — A file identifier is the name of the file, written as a string in double quotes with its extension, such as "FileA.txt". The same identifier is used in every file command.
Section D: Fill in the Blanks
Q1
OPENFILE "Scores.txt" FOR READ READFILE "Scores.txt", Score
Q2
OPENFILE "Names.txt" FOR WRITE
Q3
DECLARE FileName : STRING FileName ← "Data.txt" OPENFILE FileName FOR READ
Q4
OPENFILE "Log.txt" FOR WRITE WRITEFILE "Log.txt", "Done" CLOSEFILE "Log.txt"
Q5
FileName ← "Data.txt" OPENFILE FileName FOR READ READFILE FileName, Line
Section E: Spot the Error
Q1
C — The file identifier is a string, so it must be in double quotes. Line 3 should be WRITEFILE "Names.txt", Name.
Q2
D — The same identifier must be used in every file command. "Dairy.txt" is a different name from "Diary.txt". Line 4 should be CLOSEFILE "Diary.txt".
Q3
B — The identifier here is "Mark.txt", but the other commands use "Marks.txt". It must be the same in every file command. Line 2 should be OPENFILE "Marks.txt" FOR WRITE.
Q4
C — In 0478 pseudocode a string, including a file identifier, is written in double quotes, not single quotes. Line 3 should be READFILE "Log.txt", Entry.
Q5
D — The closing double quote after the extension is missing, so the identifier is not a complete string. Line 4 should be WRITEFILE "Quiz.txt", Score.