www.gibmonks.com

Main Page




Previous Page
Next Page

[Page 876 (continued)]

Self-Review Exercises

17.1

Fill in the blanks in each of the following:

  1. Ultimately, all data items processed by a computer are reduced to combinations of__________and__________.

  2. The smallest data item a computer can process is called a__________.

  3. A(n)__________is a group of related records.

  4. Digits, letters and special symbols are referred to as__________.

  5. A group of related files is called a(n)__________.

  6. Member function__________of the file streams fstream, ifstream and ofstream closes a file.

  7. The istream member function__________reads a character from the specified stream.

  8. Member function__________of the file streams fstream, ifstream and ofstream opens a file.

  9. The istream member function__________is normally used when reading data from a file in random-access applications.

  10. Member functions__________and__________of istream and ostream, set the file-position pointer to a specific location in an input or output stream, respectively.

17.2

State which of the following are true and which are false. If false, explain why.

  1. Member function read cannot be used to read data from the input object cin.

  2. The programmer must create the cin, cout, cerr and clog objects explicitly.

  3. A program must call function close explicitly to close a file associated with an ifstream, ofstream or fstream object.


  4. [Page 877]
  5. If the file-position pointer points to a location in a sequential file other than the beginning of the file, the file must be closed and reopened to read from the beginning of the file.

  6. The ostream member function write can write to standard-output stream cout.

  7. Data in sequential files always is updated without overwriting nearby data.

  8. Searching all records in a random-access file to find a specific record is unnecessary.

  9. Records in random-access files must be of uniform length.

  10. Member functions seekp and seekg must seek relative to the beginning of a file.

17.3

Assume that each of the following statements applies to the same program.

  1. Write a statement that opens file oldmast.dat for input; use an ifstream object called inOldMaster.

  2. Write a statement that opens file trans.dat for input; use an ifstream object called inTransaction.

  3. Write a statement that opens file newmast.dat for output (and creation); use ofstream object outNewMaster.

  4. Write a statement that reads a record from the file oldmast.dat. The record consists of integer accountNumber, string name and floating-point currentBalance; use ifstream object inOldMaster.

  5. Write a statement that reads a record from the file TRans.dat. The record consists of integer accountNum and floating-point dollarAmount; use ifstream object inTransaction.

  6. Write a statement that writes a record to the file newmast.dat. The record consists of integer accountNum, string name, and floating-point currentBalance; use ofstream object outNewMaster.

17.4

Find the error(s) and show how to correct it (them) in each of the following.

  1. File payables.dat referred to by ofstream object outPayable has not been opened.

    outPayable << account << company << amount << endl;
    
  2. The following statement should read a record from the file payables.dat. The ifstream object inPayable refers to this file, and istream object inReceivable refers to the file receivables.dat.

    inReceivable >> account >> company >> amount;
    
  3. The file tools.dat should be opened to add data to the file without discarding the current data.

    ofstream outTools( "tools.dat", ios::out );
    


Previous Page
Next Page