1 / 6

Session Objectives #U2 S7

Session Objectives #U2 S7 . Key Words. Record. Array. Serial file. Sequential file. Indexed Sequential. Random file. File Organisation. When programme files are created, the data used in that file or stored in different ways.

corine
Télécharger la présentation

Session Objectives #U2 S7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Session Objectives#U2 S7

  2. Key Words Record Array Serial file Sequential file Indexed Sequential Random file

  3. File Organisation When programme files are created, the data used in that file or stored in different ways. Serial file– the data is stored in the order which it arrives. New data is added to the end, which is called appending. Sequential file – data is stored according to a key field in the data that can be used to identify each individual record, like an ID field. Adding new items requires the file to be recreated as the new data needs to be inserted in the correct position with the records and not simply added to the end. Indexed Sequential – are sequential but have an index which allows records to be found directly. Random files – In all of the above examples, records are stored next to each other. A random file allows the data to be stored anywhere in a dedicated section of the disk. The location of the field is decided by a calculation called a hash algorithm.Finding these files is very quick, if you know the algorithm and key field, therefore random files are useful for large databases.

  4. File Handling Operations It is often useful to programme data in an external file, this requires the use of file operations to prepare, read and write to file Preparing a file – most languages use the OPEN command and specify file name/path. Read data from file – commands differ from among languages but simplest way is to read one line at a time from a serial/sequential files. For random files, lines are read from specific address given in the code. Writing data: This can merging (combining in new and old) as in sequential files, or appending (adding to the end) as in serial files.

  5. File Writing Operations TASK: Use the writetofile program and experiment creating different text files with different lines of text by changing the commands. TASK 2: Create an external text file, with a suitable filename, containing the first 2 verses of a song or poem. NB Make sure you have a line break between the 2 verses. EXT: Extend your calculator programmes so that the answers are written to an external file. (The file should contain some explanatory text, ie The Answer = …

  6. Estimating File Sizes It is possible to estimate the size of a file by calculating the following: The size (in bytes) of each field in the record (for a string use the largest size allowed) Add the field sizes to calculate the size of one record. Multiply the size of one record by the number of records in the file Add 10% to the result, for additional storage that will be needed to manage the file on disk (this is call an overhead). TASK: Attempt Q2 on p.97 of the Hodder book.

More Related