CHAPTER 9  

FILE HANDLING:  A DATABASE 

  A key feature of the computer is the ability to store information, and to retrieve it at a later time. The information (data) has to be saved somewhere, which is called a file, and has to be under a name, which is called a filename. A program constantly interacts with the files to store, retrieve, modify or delete the data. Traditionally, a file that is used to store or retrieve data is called data file or input file. A data file may contain personal information such as the names of employees, their telephone numbers and salaries. 

You may work interactively with a program and enter the data each time. However, when the input data become large, it is necessary to work with a data file rather than typing the data over and over each time. One example of a data file would be supermarket pricing, where a huge amount of data is manipulated.  In today’s web engine, hundreds of files may have to be processed in order to complete a search. The advancement of the Internet has proportionally increased the number of files and their size.  For any organization, data processing and data manipulation are essential operations.  A database runs the day-to-day operations by adding new records, searching for particular record(s), modifying the existing records and generating reports. Due to the real-time demand of data, the efficiency of databases is subject to review and, as a result, a tremendous effort has been spent to secure their reliability.   

WORKING WITH A DATA FILE 

In order to work with a data file, whether it is to be used to store data or retrieve data, the following steps need to be taken into consideration. 

1)                  Include the file stream in the header file section.

2)                  Associate a name with the data file and specify its mode as to whether to output, append or input. This step will open the data file and get it ready.  

3)                  Use the associated file name throughout the program the same way cin and cout are used, except that with cin and cout data are handled by the console (keyboard and screen). 

4)                  Close the file when you are finished.