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...

Assessment: Computer Science 0478 | Paper 2 Mock 01 | Algorithms, Programming and Logic Subject: Computer Science - 0478

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]

Answer Details

(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".

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning