Class Exercise:  File Input and Output

File:  An area in secondary storage used to hold information

The file I/O process:
a.  Include the header file fstream;
b.  Declare filestream variables: ifstream for input file stream and ofstream
    for output file stream;
c.  Associate the filestream variables with input/output sources (fopen);
d.  Use the filestream variables with the cout insertion (<<), cin extraction
    (>>) operators, and other input/output functions(e.g. getLine(inFile,str));

1.  Code a C++ statement to include the header file fstream in a program;    
   

2.  Declare itemIn to be a filestream variable of the type ifstream.


3.  Declare itemOut to be a filestream variable of the type ofstream.


4.  Have itemIn invoke the predefined open function and pass it the argument
    (actual parameter) value "item.txt";


5.  Have itemOut invoke the predefined open function and pass it the argument
    "item.prn";


6.  Use the filestream variable itemIn with extraction operators (>>) to
    specify the input of elementary variables named description, price 
    and quantity;


7.  Given that a while loop is to be contructed to control the input of
    multiple sets of item data, code a boolean expression to determine
    whether it is true that the filestream variable named itemIn has not
    read past the end of the input file.



8.  Use the filestream variable itemOut with the insertion operator (<<) to
    output the variable description and also the product of price times
    quantity.


9.  Code statements to close (disassociate and free) the filestream variables
    itemIn and itemOut.



Note:
Our Webpage contains links to program examples FileInput.cpp and
    FileOutput.cpp that may also be helpful.