0% found this document useful (0 votes)
6 views

Sequential Data Files (Text Files) Readings

Sequential data files store data in chronological order. They are text files that can be read by programming languages. The document provides examples of opening, reading from, and writing to a sequential data file called Students.txt that contains student records. Pseudocode is given to demonstrate reading from the file line-by-line until end of file, and accepting user input to write new records to the file.

Uploaded by

carlynn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Sequential Data Files (Text Files) Readings

Sequential data files store data in chronological order. They are text files that can be read by programming languages. The document provides examples of opening, reading from, and writing to a sequential data file called Students.txt that contains student records. Pseudocode is given to demonstrate reading from the file line-by-line until end of file, and accepting user input to write new records to the file.

Uploaded by

carlynn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Sequential Data Files (Text Files)


1.1. What is a Sequential Data Files (Text Files)
Sequential Data File is a type of computer file which stores the data in a
chronological order. The data is pile up in an ordered or unordered way in the files. In
other words, sequential data file is a text file similar to the program written in the note
pad and saved as.txt file. These sequential files can also be read by various
programming languages including but not limited to Java, C#, Visual basic, C++ and
so forth.

The data of the text file is read sequentially i.e., sequential file data are read from the
initial location up to end of the desired data. Sequential access devices, such as
magnetic tape and compact disc(CD) are used to store the Sequential Data File.

Sample representation of a sequential data file:


File Name: Students.txt

Student_No Student_Name Student _Address Date_of_Birth


“St230065”, “Peter Oldjohn”, “689 BETH AVENUE”, “2/15/1997”
‘St220054”, “Johannes Chonco”, “387 Sein Avenue”, “8/25/1999”
“St217890”, “Carrol Pahbu”, “890 RABIE ROAD”, “9/17/1998”
“St223456”, “Shakira Vincent”, “689 VlOLTA ST”, “6/26/2001”
“St231457”, “Sthembiso Dladla”, “278 ORDER ST”, “4/15/2000”
“St232000”, “Martha Phetolo”, “2500 VILAKAZi ST”, “11/27/1995”

1.2. Understand the generic statements using the file above to perform
the following:
1.2.1. Opening the sequential access file: Every file that is used in the program must
be opened before it can be used. The opening statements were categorized as
follows:
a) open input (name of file): This statement is used when an input file is
opened. E.g. open input (Students.txt)
b) open outputCreate (name of file): This statement is used when an output
file is opened to create a new output file.
E.g. open outputCreate (Students.txt)
c) open outputAppend (name of file): This statement is used when an output
file is opened to append or add a new text lines to it.
E.g. open outputAppend (Students.txt)

1
1.2.2. Closing a sequential access file: A file should be closed as soon as all the text
has been read from it to prevent loss of information when using an input file. .
a) close (name of file). E.g. close (Students.txt)

1.2.3. Reading the information from the sequential access file: A sequential access
file is always read from the beginning of the file. Lines can be read from a file until
the end-of-file (eof) character is found, which indicates that the file doesn’t
contain any data that has not been read.
a) read (name of file).E.g. StudentData = read(Students.txt)

1.2.1. Writing the information sequential access file: A text lines can be added to an
existing file or a new output file can be created.
a) write (name of file).E.g. write (Students.txt).

1.3. Pseudocode example 1: lines of text are read from the Student file.

if exists(Students.txt) then
open input(Students.txt)
EmployeeData = read(Students.txt)
do until eof
display EmployeeData
EmployeeData = read(Students.txt)
loop
close(Students.txt)
else
display “The file does not exist.”
Endif

Pseudocode Interpretation
open input(Students.txt) Open the Data file
called students.
EmployeeData = read(Students.txt) Read the content of
do until eof the Data file
display EmployeeData called students
EmployeeData = read(Students.txt) from the beginning
loop until the end(by
means of [do loop])
close(Students.txt) Close the Data file
called students.

2
1.4. Pseudocode example - 2: Student data will be accepted from the keyboard
and written to a new text file.

if exists(Students.txt) then
open outputCreate(Students.txt)
display “Enter the first line of Student data, enter -1 to stop”
enter StudentData
do while StudentData <> “-1”
write(Students.txt) from StudentData
write new line
display“Enter the next line of Students data, enter -1 to stop”
enter StudentData
loop
close(Students.txt)
Endif

Pseudocode Interpretation
write(Students.txt) from StudentData Write to a new text
file.
Every line of student

write new line data must be written to


a new line in the file.
display “Enter the first line of Student Write the information
data, enter -1 to stop” to the new text file.
enter StudentData
do while StudentData <> “-1”
write(Students.txt) from StudentData
write new line
display“Enter the next line of
Students data, enter -1 to stop”
enter StudentData
loop

============================THE END=========================

You might also like