0% found this document useful (0 votes)
91 views8 pages

Text Files Exercise

The document discusses a concert venue's program for calculating admission prices and storing ticket sales data, highlighting the inefficiency of re-entering data daily. It suggests using text files for data storage to streamline the process and includes pseudocode for procedures related to file handling and logging student network access. Additionally, it outlines a teacher's program for checking student project files for syntax errors, detailing various modules and their functionalities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views8 pages

Text Files Exercise

The document discusses a concert venue's program for calculating admission prices and storing ticket sales data, highlighting the inefficiency of re-entering data daily. It suggests using text files for data storage to streamline the process and includes pseudocode for procedures related to file handling and logging student network access. Additionally, it outlines a teacher's program for checking student project files for syntax errors, detailing various modules and their functionalities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1 (a) A concert venue uses a program to calculate admission prices and store information about ticket

sales.
A number of arrays are used to store data. The computer is switched off overnight and data
has to be input again at the start of each day before any tickets can be sold. This process is
very time consuming.
(i) Explain how the program could use text files to speed up the process.

.............................................................................................................................

.............................................................................................................................

.............................................................................................................................

.............................................................................................................................

.............................................................................................................................

.........................................................................................................................[2]

(ii) State the characteristic of text files that allow them to be used as explained in part (a)
(i).

.............................................................................................................................

....................................................................................................................... [1]

(iii) Information about ticket sales will be stored as a booking. The booking requires the
following data:

• name of person booking


• number of people in the group (for example a family ticket or a school party)
• event type.

Suggest how data relating to each booking may be stored in a text file.

.............................................................................................................................

.............................................................................................................................

.............................................................................................................................

....................................................................................................................... [2]
2

(b) A procedure Preview() will:

• take the name of a text file as a parameter


• output a warning message if the file is empty
• otherwise output the first five lines from the file (or as many lines as there are in the file
if this number is less than five).

Write pseudocode for the procedure Preview().

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

............................................................................................................................... [5]
3

2 The following data items will be recorded each time a student successfully logs on to the school
network:

Data item Example data


Student ID "CJL404"
Host ID "Lib01"
Time and date "08:30, June 01, 2021"

The Student ID is six characters long. The other two data items are of variable length.

A single string will be formed by concatenating the three data items. A separator character will need
to be inserted between items two and three.

For example:

"CJL404Lib01<separator>08:30, June 01, 2021"

Each string represents one log entry.

A programmer decides to store the concatenated strings in a 1D array LogArray that contains 2000
elements. Unused array elements will contain an empty string.

(a) Suggest a suitable separator character and give a reason for your choice.

Character ..................................................................................................................................

Reason .....................................................................................................................................

...............................................................................................................................................[2]

(b) The choice of data structure was made during one stage of the program development life cycle.

Identify this stage.

............................................................................................................................................. [1]

(c) A function LogEvents() will:


4

 take a Student ID as a parameter


 for each element in the array that matches the Student ID parameter:
o add the value of the array element to the existing text file LogFile
o assign an empty string to the array element
 count the number of lines added to the file
 return this count.
Write pseudocode for the function LogEvents().

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

...................................................................................................................................... [7]

3 A teacher is designing a program to perform simple syntax checks on programs written by students.
Student programs are submitted as text files, which are known as project files.
5

A project file may contain blank lines.

The teacher has defined the first program module as follows:

Module Description
• takes the name of an existing project file as a parameter of
type string
CheckFile()
• returns TRUE if the file is valid (it contains at least 10 non-
blank lines), otherwise returns FALSE

(a) Write pseudocode for module CheckFile().

..................................................................................................................................................
.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

..................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

..................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

..................................................................................................................................................
.

...................................................................................................................................................
6

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

Further modules are defined as follows:

Module Description
• takes a line from a project file as a parameter of type
string
CheckLine()
• returns zero if the line is blank or contains no syntax error,
otherwise returns an error number as an integer
• takes two parameters:
○ the name of a project file as a string
○ the maximum number of errors as an integer
• uses CheckFile() to test the project file. Outputs an
CountErrors() error message and ends if the project file is not valid
• calls CheckLine() for each line in the project file
• counts the number of errors
• outputs the number of errors or a warning message if the
maximum number of errors is exceeded

(b) CountErrors() is called to check the project file Jim01Prog.txt and to stop if more than 20
errors are found.

Write the pseudocode statement for this call.

..................................................................................................................................................
.

............................................................................................................................................. [2]

(c) Write pseudocode for module CountErrors(). Assume CheckFile() and CheckLine()
have been written and can be used in your solution.

.................................................................................................................................................................
.
7

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

...................................................................................................................................................

..................................................................................................................................................

...................................................................................................................................................
8

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

You might also like