Page 279 - DCAP404 _Object Oriented Programming
P. 279
Object-oriented Programming
Notes user console - keyboard for input and monitor for output. However, when data volume is large
it is generally not convenient to enter the data through console. In such cases data can be stored
in a file and then the program can read the data from the data file rather than from the console.
The data may be organized in fixed size record or may be in free form text. The various operations
possible on a data file using C++ programs are:
1. Opening a data file
2. Reading data stored in the data file into various variables and objects in the program
3. Writing data from a program into a data file
(a) Removing the previously stored data in the file
(b) Without removing the previously stored data in the file
(i) At the end of the data file
(ii) At any other location in the file
4. Saving the data file onto some secondary storage device
5. Closing the data file once the ensuing operations are over
6. Checking status of file operation
Did u know? Where did data file exist?
The data file itself can exist in many forms. It may contain textual data in ASCII format or
binary data.
(Figure 5.5).
C++ treats each source of input and output uniformly. The abstraction of a data source and data
sink is what is termed as stream. A stream is a data abstraction for input/output of data to and
from the program (Figure 13.1).
Figure 13.1 (a): Input Stream Currently Attached to a Data File
File
Figure 13.1 (b): Input Stream Currently attached to Keyboard
Fgure 5.5 (a) Input streamcurrentlyattachedtoa data file
i
272 Figure LOVELY PROFESSIONAL UNIVERSITY