Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
This Matching the variable's data type to the file data worksheet is part of the IGCSE Computer Science 0478 — 8.3 File Handling journey. Print it as a booklet?
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1DECLARE LineOfText : STRING | ALine is meant to hold a line of text but is declared as INTEGER, so the text cannot be stored. It should be declared as STRING. | |
| 2DECLARE Score : INTEGER | BDECLARE Total : INTEGER WRITEFILE "total.txt", Total | |
| 3Choose the type when you declare the variable: a line of text needs a STRING variable before it is used with READFILE | CCreates a variable that can hold a whole number stored in a file | |
| 4A whole number written to a file should be held in an INTEGER variable | DAge holds a whole number but is declared as STRING, so using it in arithmetic causes an error. It should be declared as INTEGER. | |
| 5DECLARE Age : STRING READFILE "ages.txt", Age Total ← Age + 1 | EDECLARE Name : STRING READFILE "names.txt", Name | |
| 6DECLARE Line : INTEGER READFILE "poem.txt", Line | FCreates a variable that can hold a line of text read from a file or written to a file |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
DECLARE LineOfText : STRING — The variable used with READFILE or WRITEFILE needs a data type that suits the data: STRING for a line of text, INTEGER for a whole number. A wrong type causes errors.DECLARE LineOfText : STRING
READFILE "story.txt", LineOfTextDECLARE Score : INTEGER
READFILE "scores.txt", ScoreDECLARE Mark : INTEGER
READFILE "marks.txt", MarkDECLARE Total : INTEGER
Total ← 250
WRITEFILE "total.txt", TotalDECLARE Line : STRING
OPENFILE "poem.txt" FOR READ
READFILE "poem.txt", Line