Download presentation
Presentation is loading. Please wait.
Published byCarmel Patterson Modified over 8 years ago
1
Chapter 9: Data types and data structures OCR Computing for A Level © Hodder Education 2009
2
What this chapter is about In this chapter we learn about the uses within a program. This includes: Data types – descriptions of individual items of data Data structures – ways in which several items of data are grouped under one identifier Files OCR Computing for A Level © Hodder Education 2009
3
Data types Basic data types used in programming languages are: Numeric data types, including: –Integer: whole numbers, e.g. 7 –Real: numbers which may have a decimal point, e.g. 7.2 Alphanumeric data types, including: –Character: a single character, digit or symbol, e.g. ‘c’ –String: several characters grouped together, e.g. ‘Mrs. Smith’ Boolean: data which can only take one of two values (usually TRUE or FALSE) OCR Computing for A Level © Hodder Education 2009
4
Arrays An array contains several items of data grouped under one identifier. Each item in the array (called an element) has an index which allows that specific element to be identified. Arrays can be one-dimensional (each element has one index), two dimensional, etc. When an array is declared, the following items must be specified: -its identifier (name) -its dimension (one-dimensional, two-dimensional, etc.) -its data type -the maximum and minimum index values (bounds). OCR Computing for A Level © Hodder Education 2009
5
Records Records contain several items of data of different data types which are grouped together. This is convenient as the data usually refers to a particular individual or object in real life. Each item of data within the record is called a field. Several records can be grouped together to create data files. OCR Computing for A Level © Hodder Education 2009
6
File organisation Different ways in which files are accessed and used are: Serial files: data is stored in the file in the order in which it was entered. New data is appended to the end of the file. Sequential files: the data is sorted according to a key field. New data is inserted in the correct position. Indexed sequential files: the data is sorted and a separate index is kept so that groups of records can be accessed directly. Suitable for large files. Direct access files: the file has records of equal length stored next to each other. The address of any record can be calculated using its position in the file. Random files: the address of each record is calculated using a hash algorithm. The records are stored according to this address and may not be next to each other. OCR Computing for A Level © Hodder Education 2009
7
Estimating the size of a file Determine the maximum size, in bytes, of each field. Add the field sizes to calculate the size of each record. Multiply this by the number of records. Add 10% for overheads. Notes: You might need to convert your final answer to a more sensible unit like KB or MB. Typical field sizes: Integer: 2 or 4 bytesReal: 4 or 8 bytes Character: 1 byteString: 1 byte per character Boolean: 1 byteDate: 4 or 8 bytes OCR Computing for A Level © Hodder Education 2009
8
File operations Programming languages offer facilities to manipulate files. These include: –opening files and setting the access mode –reading data from a file sequentially or directly –writing data to a file –file management, e.g. copying, moving, deleting files. You should know how these operations are carried out in the programming language you have studied. OCR Computing for A Level © Hodder Education 2009
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.