File Organization in c++ PDF

Title File Organization in c++
Author Daniel Kaba
Course Programming
Institution University of Northampton
Pages 14
File Size 220 KB
File Type PDF
Total Downloads 104
Total Views 162

Summary

Lectures Notes...


Description

File Organization

File organization refers to the way records are physically arranged on a storage device. This topic describes the two main types of file organization.

File Organization methods

Sequential file organization In sequential file organization, records are arranged sequentially. A sequential file is a file whose records can be accessed on the order of their appearance in the file. The order in which the records are stored is determined by the order in which they are written when the file was prepared. This order does not charge. Records may be added at the end of file only. The records may be accessed in the order on which they were originally written into a file. Advantages of sequential file organization i.

Simple to implement

ii.

Requires very low software support

iii.

Efficiency of blocking is good

iv.

Blocking results in saving in terms of input-output time required handling a file.

v.

A substantial amount of storage space on the disk can be saved.

Disadvantages of sequential file organization i. ii.

Updates are not easily accommodated Random access is not possible

1

iii.

All records must be structurally identical, if a new field has to be added, and then every record must be rewritten to provide space for the new field.

iv.

Continuous areas may not be possible because both the primary data file and the transaction file must be looked during merging.

Area of Use Sequential files are most frequently used in commercial batch oriented data processing applications where there is the concept of a master file to which details are added periodically. Example: - Payroll applications. Index Sequential file organization When there is need to access records sequentially by some key value and also to access records directly by the same key value, the collection of records may be organized in an effective manner called index sequential file organization. In index sequential file organization, the records are stored in the key sequence order usually in ascending order. Some index tables are also created and maintained with the file. Index table provide to identify the groups of records in the file. When an indexed file is accessed randomly, the programmers control the sequence on which the records are accessed by specifying the value of a data item called record key. When the new records are inserted in the data file, the sequence of records needs to be preserved and also the index is accordingly updated. Advantage of index sequential file organization i.

In indexed sequential file organization, the item in the table can be examined sequentially if all the records in the file must be accessed.

2

ii.

Indexed sequential file organization is very useful when a random access or records by specifying the key is required.

iii.

Updating is easily accommodated

iv.

Random access is possible.

Area of use Index sequential file organization support applications that selectively access individual records rather than searching thru the entire collection in sequence. Example- Train Enquiry System, Reservation Enquiry System.

Relative file Organization A relative file is organized in such a way that a relative record number identifies each record. The relative record number specifies the position of the record from the beginning of the file. A relative file may be accessed sequentially. randomly and dynamically . In sequential access, records are accessed in order of ascending relative record numbers. In random access, the programmer must specify relative record number. In dynamic, both random and sequential access modes may be intermixed. Advantages of Relative File Organization i.

A relative file may be accessed sequentially randomly or dynamically.

ii.

It organizes data when there is a need to access individual records directly.

iii.

Updating is easily accommodated.

iv.

Processing efficiency is high.

3

Disadvantages of relative file organization

i. ii.

In most applications it may be difficult to specify the relative record position. In the case when have to access the records randomly and want to identify them by the value of the key, rather than the relative record number, then relative file organization is not suitable.

Input/output with files

C++ provides the following classes to perform output and input of characters to/from files:



ofstream: Stream class to write on files



ifstream: Stream class to read from files



fstream: Stream class to both read and write from/to files.

These classes are derived directly or indirectly from the classes istream, and ostream.

#include #include using namespace std;

int main () { ofstream myfile; myfile.open ("example.txt"); myfile...


Similar Free PDFs