Y12 CS T2 W6 L1 Ch10 - Records - Files

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

Chapter 10

Data types and structures


TOPIC: Data types
WALT:
How can I evaluate the features of
records and files?
WILF
• Able to create and use records in pseudocode
• Able to use text files in pseudocode
• Able to implement file handling operations in pseudocode
Keywords
Text file, mode, open, close, record,
append, basic data type, composite
data type
Basic data types
Data types allow programming languages to provide different
classifications for items of data, so they can be used for different purposes.
The built-in basic data types are
Composite data types

• A composite data type references other existing data types when it is


defined.

• A composite data type must be defined before it can be used.

• Any data type not provided by a programming language must be defined

before it can be used.

• Eg: Records, Arrays


Record
• Records are composite data types formed by the inclusion of several related items that
may be of different data types.
• This allows a programmer to refer to these items using the same identifier, enabling a
structured approach to using related items.
• A record will contain a fixed number of items.
• For example, a record for a book could include title, author, publisher, number of pages,
and whether it is fiction or non-fiction.
File Handling
▪ Programs process and use data.
▪ When a program finishes, or is closed, any data it held is lost.
▪ To prevent loss, data can be stored in a file so that it can be
accessed again at a later date.
▪ Every file is identified by its filename.
▪ Text files contain a sequence of characters.
▪ Text files can include an end of line character that enables the
file to be read from and written 7 to as lines of characters.
Opening a file
▪ A file must be opened before any data can be read from it or written to it.

▪ To open a file, it must be referred to by its identifier.

8
Reading from a file

▪ Once a file has been opened, the data is read from it one line
at a time. The data can be read into a variable

Writing to a file
▪ Once the file is opened in WRITE or APPEND mode, it can be
written to a line at a time

9
End of file and Closing a file

10
11
Example code – Writing to a file

12
Example code – Writing to a file

13
Example code – Writing to a file

14
Reading the content of a file

Existing file

15
Task

Write a Pseudocode to
• open a file named MyFile
• Write few lines of text into the file and
• read the content from the file.

16
Task Answer

17
Past paper question
19
20
21
22
23
PLENARY

24
Plenary answer

25
IL TASK

You might also like