Question 1 Report
A program needs to create a file containing a multiplication table.
(a) Write pseudocode to create a file called timestable.txt containing the 7 times table from 1 to 12 (e.g., "7 x 1 = 7" on each line). [4]
(a) Creating a file with the 7 times table uses OPENFILE FOR WRITE and a loop.
DECLARE i : INTEGER
DECLARE Line : STRING
OPENFILE "timestable.txt" FOR WRITE
FOR i ← 1 TO 12
Line ← "7 x " & NUM_TO_STR(i) & " = " & NUM_TO_STR(7 * i)
WRITEFILE "timestable.txt", Line
NEXT i
CLOSEFILE "timestable.txt"OPENFILE ... FOR WRITE creates or overwrites the file. [1] The loop runs from 1 to 12, building each line as a formatted string. [1] NUM_TO_STR converts numeric values to strings for concatenation. [1] WRITEFILE writes one line per iteration. [1]
The file will contain 12 lines, from "7 x 1 = 7" to "7 x 12 = 84".
Everything you need to excel in your exams