Docstoc

Files

Document Sample
Files Powered By Docstoc
					             Data Structures
                   Files




20/08/2012                     1
             Learning Objectives
    Explain concepts of files, records, fields.
    Explain simple linear file structure – with a
    variety of fields of fixed length.
    Explain the function of key fields.
    Calculate from this structure an estimated
    file size given the number of records.



20/08/2012                                          2
                     Data
    Data stored in computers is normally
    connected in some way.
    For example, some data about 20
    students has a connection because it all
    refers to the same set of people.
    Each person will have the same
    information stored about them, for
    instance their name, address, telephone
    number, exam grades…

20/08/2012                                     3
                 Fields & Records
    Each column is a field.
    Each row is a record.



Account Number   Surname      Forename   Balance

45278            Smith        Sally      €10.00
1208             Jones        John       €20.00
3217             Cain         Shazad     €100.00
4310             White        Peter      €250.00
20/08/2012                                         4
                           File
    A large quantity of data that has an
    identity.
        e.g. Data about a set of students.




20/08/2012                                    5
                    Fixed Length
    Records should be of a fixed length.
    Advantages:
        The file can be stored and searched faster.
        It also makes it possible to estimate the file
         size and so choose a suitable storage
         medium with enough space.
    Disadvantages:
        Field sizes must be chosen before use so
         space may be wasted or may not be enough.

20/08/2012                                                6
                      Fixed Length
        However, string variables use 1 byte per
         character (so are as long as the text they
         hold).
             String variables in a random access file record
             need to be of a fixed length (this will remove
             characters if the string is longer than the fixed
             length or add spaces to extend it to reach the fixed
             length).




20/08/2012                                                      7
                        Key Field
    Some fields may contain the same items of data
    in more than one record.
        e.g. there may be two people with the same name or
         balance.
    It is important that the computer can identify
    individual records, and it can only do this if it can
    be sure that one of the fields will always contain
    different data in all the records.
    The key field is unique and is used to identify the
    record.
        In our example the key field would be the account
         number.

20/08/2012                                                    8
                              Data Types
 Main Data      Data           Range / Fractional Real         Storage Requirements
  Types        Types                 Precision                        (bytes)
Text (Characters) /       Any characters
                                                                   1 per character
String in VB
              Byte        0 - 255                                         1
Integer       Integer     In Access stored by 2 bytes so +/-
                          32,768.
(Numeric,                                                               2-4
Whole                     In VB stored by 4 bytes so approx.
                          +/- 2 billion
numbers,
no            Long        In Access stored by 4 bytes so
fractions)    (Integer)   approx. +/- 2 billion.                        4–8
                          In VB stored by 8 bytes so approx.
                          +/– 9.2...E+18.
Floating      Single      7                                               4
Point         Double      15                                              8
(Fractional
Real          Decimal     28
                                                                         12
Numbers)
Boolean (Y/N True/False)                                       Often 1 byte is reserved
Date/Time                                                                 8
    Summary of Data Types Storage
           Requirements
                                             Storage Requirements
             Data Type
                                                     (bytes)
                 Text                          1 byte per character
         Integer 0 – 255                                   1 byte
          Integer > 255                                    4 bytes
             Decimal                                       8 bytes
             Boolean                                       1 byte
  (True/False – Yes/No – 2 answers only)

             Date / Time                                   8 bytes

20/08/2012
             Note: Use this summary in exam questions. The previous slide is for   10
                                  general interest only.
    1. A library stores details of the
       books that are available.
    Apart from title and author, state 3 other fields that it
    would be sensible for the library to store in this file,
    giving a reason why each of your chosen fields would be
    necessary.
                                                              (6)
    One mark for each of three sensible fields with an extra
    mark for an explanation of the need for that field.
    e.g.
        ISBN/to identify book
        Shelf number/ to allow for ease of search for book
        Fiction or reference or children's (some form of category)/ to
         decide whereabouts in library it should go


20/08/2012                                                                11
A library stores details of the books
          that are available.
    State which field would be used as the key
    field of the record and explain why a key
    field is necessary.
                                             (2)
    Book number (ISBN)
        because it is unique to that record and hence
         can be used as an identifier.
    Name a suitable data type for this field.
        String / Integer Why?

20/08/2012                                               12
2.           A stock file in a warehouse has the following
             fields in each record.
             (i) State data types suitable for each of the
             fields.

       Name of item.                Text / String
       Date of last delivery.       Date
       Price of item.               Currency / Decimal
       Whether or not an            Boolean
       order is outstanding.
       Number of that item          Integer
       left in stock.

20/08/2012                                                   13
(ii)         Given that there are approximately 10000
             different items in the warehouse, estimate the
             size of the stock file. You should clearly show
             all the stages in the calculation.

       Name of item.                 10 bytes
       Date of last delivery.        8 bytes
       Price of item.                8 bytes
       Whether or not an             1 bytes
       order is outstanding.
       Number of that item           4 bytes
       left in stock.

20/08/2012                                                 14
(ii) Calculation

         Total 31 bytes
         31 x 10000 = 310000 bytes
         Overhead:
            10% of 310000 = 310000 * 0.1 =
         310000 + 31000 = 341000
         341000 / 1024 ~ 341 Kbytes



20/08/2012                                    15
                        Plenary
    What are records, fields and files?
        Each column is a field.
        Each row is a record.
        A large quantity of data that has an identity.




20/08/2012                                                16
                           Plenary
    Why do records in a file have to be of fixed
    length?
        So that the computer knows where each
         record starts and ends.
             String variables need to be of a fixed length.
    What are key fields?
        The key field is unique and is used to identify
         the record.


20/08/2012                                                    17

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:19
posted:8/18/2012
language:English
pages:17