Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 14 – File Processing

Similar presentations


Presentation on theme: "Chapter 14 – File Processing"— Presentation transcript:

1 Chapter 14 – File Processing
Outline 14.1 Introduction 14.2 The Data Hierarchy 14.3 Files and Streams 14.4 Creating a Sequential Access File 14.5 Reading Data from a Sequential Access File 14.6 Updating Sequential Access Files 14.7 Random Access Files 14.8 Creating a Random Access File 14.9 Writing Data Randomly to a Random Access File 14.10 Reading Data Sequentially from a Random Access File 14.11 Example: A Transaction Processing Program 14.12 Input/Output of Objects

2 Data files can be created, updated, and processed by C++ programs
14.1 Introduction Data files can be created, updated, and processed by C++ programs Files are used for permanent storage of large amounts of data Storage of data in variables and arrays is only temporary

3 14.2 The Data Hierarchy Bit - smallest data item Byte – 8 bits
value of 0 or 1 Byte – 8 bits used to store a character Decimal digits, letters, and special symbols Field - group of characters conveying meaning Example: your name Record – group of related fields Represented a struct or a class Example: In a payroll system, a record for a particular employee that contained his/her identification number, name, address, etc. File – group of related records Example: payroll file Database – group of related files

4 14.2 The Data Hierarchy (II)
Judy Green Sally Black Tom Blue Iris Orange Randy Red File Record Field Byte (ASCII character J) Bit Record key identifies a record to facilitate the retrieval of specific records from a file Sequential file records typically sorted by key

5 C++ views each file as a sequence of bytes
14.3 Files and Streams C++ views each file as a sequence of bytes File ends with the end-of-file marker Stream created when a file is opened File processing Headers <iostream.h> and <fstream.h> class ifstream - input class ofstream - output class fstream - either input or output

6 14.4 Creating a Sequential Access File
Files are opened by creating objects of stream classes ifstream, ofstream or fstream File stream member functions for object file: file.open(“Filename”, fileOpenMode); file.close(); destructor automatically closes file if not explicitly closed File open modes: Makes a "line of communication" with the object and the file.

7 1. Load headers 1.1 Initialize ofstream object
1 // Fig. 14.4: fig14_04.cpp 2 // Create a sequential file 3 #include <iostream> 4 5 using std::cout; 6 using std::cin; 7 using std::ios; 8 using std::cerr; 9 using std::endl; 10 11 #include <fstream> 12 13 using std::ofstream; 14 15 #include <cstdlib> 16 17 int main() 18 { 19 // ofstream constructor opens file 20 ofstream outClientFile( "clients.dat", ios::out ); 1. Load headers 1.1 Initialize ofstream object ofstream objects open a file for output (i.e., write to the file). If the file "clients.dat" does not exist, it is created. ios::out is the default for ofstream objects.

8 Overloaded operator! returns true if failbit or badbit are set.
21 22 if ( !outClientFile ) { // overloaded ! operator cerr << "File could not be opened" << endl; exit( 1 ); // prototype in cstdlib 25 } 26 27 cout << "Enter the account, name, and balance.\n" << "Enter end-of-file to end input.\n? "; 29 30 int account; 31 char name[ 30 ]; 32 double balance; 33 34 while ( cin >> account >> name >> balance ) { outClientFile << account << ' ' << name << ' ' << balance << '\n'; cout << "? "; 38 } 39 40 return 0; // ofstream destructor closes file 41 } Overloaded operator! returns true if failbit or badbit are set. 2. Test for file open 2.1 Input values 3. Output to file Program Output Input sets of data. When end-of-file or bad data is input, cin returns 0 (normally it returns cin), and the while loop ends. Rather than outputting to cout, we output to outClientFile, which is linked to clients.dat outClientFile's destructor automatically closes client.dat Enter the account, name, and balance. Enter EOF to end input. ? 100 Jones 24.98 ? 200 Doe ? 300 White 0.00 ? 400 Stone ? 500 Rich ? ^Z

9 14.5 Reading Data from a Sequential Access File
File stream member functions for repositioning file position pointer: seekg (seek get) for istream and seekp (seek put) for ostream // position to the nth byte of fileObject // assumes ios::beg fileObject.seekg( n ); // position n bytes forward in fileObject fileObject.seekg( n, ios::cur ); // position y bytes back from end of fileObject fileObject.seekg( y, ios::end ); // position at end of fileObject fileObject.seekg( 0, ios::end ); tellg and tellp – return current location of pointer location = fileObject.tellg() //returns long

10 Reading a sequential file 1. Load header 1.1 Function prototype
1 // Fig. 14.7: fig14_07.cpp 2 // Reading and printing a sequential file 3 #include <iostream> 4 5 using std::cout; 6 using std::cin; 7 using std::ios; 8 using std::cerr; 9 using std::endl; 10 11 #include <fstream> 12 13 using std::ifstream; 14 15 #include <iomanip> 16 17 using std::setiosflags; 18 using std::resetiosflags; 19 using std::setw; 20 using std::setprecision; 21 22 #include <cstdlib> 23 24 void outputLine( int, const char * const, double ); 25 26 int main() 27 { 28 // ifstream constructor opens the file Reading a sequential file 1. Load header 1.1 Function prototype

11 Opens "clients.dat" for input (i.e., read from file)
29 ifstream inClientFile( "clients.dat", ios::in ); 30 31 if ( !inClientFile ) { cerr << "File could not be opened\n"; exit( 1 ); 34 } 35 36 int account; 37 char name[ 30 ]; 38 double balance; 39 40 cout << setiosflags( ios::left ) << setw( 10 ) << "Account" << setw( 13 ) << "Name" << "Balance\n" << setiosflags( ios::fixed | ios::showpoint ); 43 44 while ( inClientFile >> account >> name >> balance ) outputLine( account, name, balance ); 46 47 return 0; // ifstream destructor closes the file 48 } 49 50 void outputLine( int acct, const char * const name, double bal ) 51 { 52 cout << setiosflags( ios::left ) << setw( 10 ) << acct << setw( 13 ) << name << setw( 7 ) << setprecision( 2 ) << resetiosflags( ios::left ) << bal << '\n'; 56 } Opens "clients.dat" for input (i.e., read from file) 1.2 Initialize ifstream object 1.3 Test for open 1.4 Initialize variables 2. Format table 3. Output data 3.1 Function definition Account Name Balance Reads data, record by record, and puts it into account, name and balance. Calls outputLine, which formats data and outputs it to the screen. while loop continues until the end of the file stream, when 0 is returned (instead of inClientFile). The destructor automatically closes clients.dat

12 Program Output Account Name Balance 100 Jones 24.98 200 Doe 345.67
White Stone Rich Program Output

13 Credit inquiry program 1. Load headers 1.1 Function prototypes
1 // Fig. 14.8: fig14_08.cpp 2 // Credit inquiry program 3 #include <iostream> 4 5 using std::cout; 6 using std::cin; 7 using std::ios; 8 using std::cerr; 9 using std::endl; 10 11 #include <fstream> 12 13 using std::ifstream; 14 15 #include <iomanip> 16 17 using std::setiosflags; 18 using std::resetiosflags; 19 using std::setw; 20 using std::setprecision; 21 22 #include <cstdlib> 23 24 enum RequestType { ZERO_BALANCE = 1, CREDIT_BALANCE, DEBIT_BALANCE, END }; 26 int getRequest(); 27 bool shouldDisplay( int, double ); 28 void outputLine( int, const char * const, double ); 29 30 int main() 31 { 32 // ifstream constructor opens the file Credit inquiry program 1. Load headers 1.1 Function prototypes 1.2 enumeration

14 1.1 Open file for input 1.2 Test for errors 1.3 Initialize variables
33 ifstream inClientFile( "clients.dat", ios::in ); 34 35 if ( !inClientFile ) { cerr << "File could not be opened" << endl; exit( 1 ); 38 } 39 40 int request, account; 41 char name[ 30 ]; 42 double balance; 43 44 cout << "Enter request\n" << " 1 - List accounts with zero balances\n" << " 2 - List accounts with credit balances\n" << " 3 - List accounts with debit balances\n" << " 4 - End of run" << setiosflags( ios::fixed | ios::showpoint ); 50 request = getRequest(); 51 52 while ( request != END ) { 53 switch ( request ) { case ZERO_BALANCE: cout << "\nAccounts with zero balances:\n"; break; case CREDIT_BALANCE: cout << "\nAccounts with credit balances:\n"; break; case DEBIT_BALANCE: cout << "\nAccounts with debit balances:\n"; break; } 1.1 Open file for input 1.2 Test for errors 1.3 Initialize variables 2. Prompt user 2.1 Get input 2.2 switch statement

15 read data from file, copy into account, name and balance
65 inClientFile >> account >> name >> balance; 67 while ( !inClientFile.eof() ) { if ( shouldDisplay( request, balance ) ) outputLine( account, name, balance ); 71 inClientFile >> account >> name >> balance; } 74 inClientFile.clear(); // reset eof for next input inClientFile.seekg( 0 ); // move to beginning of file request = getRequest(); 78 } 79 80 cout << "End of run." << endl; 81 82 return 0; // ifstream destructor closes the file 83 } 84 85 int getRequest() 86 { 87 int request; 88 89 do { cout << "\n? "; cin >> request; 92 } while( request < ZERO_BALANCE && request > END ); 93 94 return request; 95 } 96 97 bool shouldDisplay( int type, double balance ) read data from file, copy into account, name and balance 2.3 Input data from file 2.4 Decide whether to display data 2.5 Reset eof for next input 2.6 Move to beginning of file 2.7 Loop until END entered 3. Function definitions Put file position pointer back to beginning.

16 3. Function definitions 98 {
98 { 99 if ( type == CREDIT_BALANCE && balance < 0 ) return true; 101 if ( type == DEBIT_BALANCE && balance > 0 ) return true; 104 if ( type == ZERO_BALANCE && balance == 0 ) return true; 107 return false; 109 } 110 111 void outputLine( int acct, const char * const name, double bal ) 112 { cout << setiosflags( ios::left ) << setw( 10 ) << acct << setw( 13 ) << name << setw( 7 ) << setprecision( 2 ) << resetiosflags( ios::left ) << bal << '\n'; 117 } 3. Function definitions

17 Program Output Enter request 1 - List accounts with zero balances
2 - List accounts with credit balances 3 - List accounts with debit balances 4 - End of run ? 1 Accounts with zero balances: White ? 2 Accounts with credit balances: Stone ? 3 Accounts with debit balances: Jones Doe Rich ? 4 End of run. Program Output

18 14.6 Updating Sequential Access Files
Cannot be modified without the risk of destroying other data Formatted text which is output to a file is very different than the internal representation 300 White Jones (old data in file) if we want to change White's name to Worthington, 300 White Jones 32.87 300 Worthington 0.00ones 32.87 300 Worthington 0.00 Data gets overwritten

19 14.7 Random Access Files Random access files
access individual records without searching through other records Instant access to records in a file Data can be inserted without destroying other data Data previously stored can be updated or deleted without overwriting. Implemented using fixed length records

20 14.8 Creating a Random Access File
write - outputs a fixed number of bytes beginning at a specific location in memory to the specified stream When writing an integer number to a file, outFile.write( reinterpret_cast<const char *>( &number ), sizeof( number ) ); First argument: pointer of type const char * (location to write from) address of number cast into a pointer Second argument: number of bytes to write(sizeof(number)) recall that data is represented internally in binary (thus, integers can be stored in 4 bytes) Do not use outFile << number; could print 1 to 11 digits, each digit taking up a byte of storage

21 1. Define struct 1.1 Load headers 1.2 Initialize ofstream object
1 // Fig : clntdata.h 2 // Definition of struct clientData used in 3 // Figs , 14.12, and 4 #ifndef CLNTDATA_H 5 #define CLNTDATA_H 6 7 struct clientData { 8 int accountNumber; 9 char lastName[ 15 ]; 10 char firstName[ 10 ]; 11 double balance; 12 }; 13 14 #endif 1. Define struct 1.1 Load headers 1.2 Initialize ofstream object 15 // Fig : fig14_11.cpp 16 // Creating a randomly accessed file sequentially 17 #include <iostream> 18 19 using std::cerr; 20 using std::endl; 21 using std::ios; 22 23 #include <fstream> 24 25 using std::ofstream; 26 27 #include <cstdlib> 28 29 #include "clntdata.h" 30 31 int main() 32 { 33 ofstream outCredit( "credit.dat", ios::binary ); 34

22 1.4 Initialize struct variable
35 if ( !outCredit ) { cerr << "File could not be opened." << endl; exit( 1 ); 38 } 39 40 clientData blankClient = { 0, "", "", 0.0 }; 41 42 for ( int i = 0; i < 100; i++ ) outCredit.write( reinterpret_cast<const char *>( &blankClient ), sizeof( clientData ) ); 46 return 0; 47 } 1.3 Check for file open 1.4 Initialize struct variable 2. Loop and write data to file Creates a random access file by writing equally-sized groups of data to the file. Each group is of size sizeof(clientData)

23 14.9 Writing Data Randomly to a Random Access File
seekp can be used in combination with write to store data at exact locations in an output file

24 1. Load header 1.1 Initialize ofstream object 1.2 Check for file open
1 // Fig : fig14_12.cpp 2 // Writing to a random access file 3 #include <iostream> 4 5 using std::cerr; 6 using std::endl; 7 using std::cout; 8 using std::cin; 9 using std::ios; 10 11 #include <fstream> 12 13 using std::ofstream; 14 15 #include <cstdlib> 16 #include "clntdata.h" 17 18 int main() 19 { 20 ofstream outCredit( "credit.dat", ios::binary ); 21 22 if ( !outCredit ) { cerr << "File could not be opened." << endl; exit( 1 ); 25 } 1. Load header 1.1 Initialize ofstream object 1.2 Check for file open

25 2.1 Set pointer to appropriate place in file
26 27 cout << "Enter account number " << "(1 to 100, 0 to end input)\n? "; 29 30 clientData client; 31 cin >> client.accountNumber; 32 33 while ( client.accountNumber > 0 && client.accountNumber <= 100 ) { cout << "Enter lastname, firstname, balance\n? "; cin >> client.lastName >> client.firstName >> client.balance; 38 outCredit.seekp( ( client.accountNumber - 1 ) * sizeof( clientData ) ); outCredit.write( reinterpret_cast<const char *>( &client ), sizeof( clientData ) ); 44 cout << "Enter account number\n? "; cin >> client.accountNumber; 47 } 48 49 return 0; 50 } 2. Input data 2.1 Set pointer to appropriate place in file 2.2 Write to file 2.3 Loop until end Enter account number (1 to 100, 0 to end input) Enter lastname, firstname, balance ? Barker Doug 0.00 Find the appropriate position in the file. The groups are of size sizeof(clientData), and the first position is at location 0. Accounts sorted by accountNumber

26 Program Output Enter account number (1 to 100, 0 to end input) ? 37
Enter lastname, firstname, balance ? Barker Doug 0.00 Enter account number ? 29 ? Brown Nancy ? 96 ? Stone Sam 34.98 ? 88 ? Smith Dave ? 33 ? Dunn Stacey ? 0 Program Output

27 14.10 Reading Data Sequentially from a Random Access File
- inputs a fixed number of bytes from the specified stream to an area in memory beginning at a specified address similar to write inFile.read( reinterpret_cast<char *>( &number ), sizeof( int ) ); First argument: pointer of type char * (location to put bytes) Second argument: number of bytes to read: sizeof( int ) Do not use inFile >> number; fast sorting with direct access techniques

28 1. Load header 1.1 Initialize ifstream object 1.2 Check for file open
1 // Fig : fig14_14.cpp 2 // Reading a random access file sequentially 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 using std::ios; 8 using std::cerr; 9 10 #include <iomanip> 11 12 using std::setprecision; 13 using std::setiosflags; 14 using std::resetiosflags; 15 using std::setw; 16 17 #include <fstream> 18 19 using std::ifstream; 20 using std::ostream; 21 22 #include <cstdlib> 23 #include "clntdata.h" 24 25 void outputLine( ostream&, const clientData & ); 26 27 int main() 28 { 29 ifstream inCredit( "credit.dat", ios::in ); 30 31 if ( !inCredit ) { cerr << "File could not be opened." << endl; exit( 1 ); 1. Load header 1.1 Initialize ifstream object 1.2 Check for file open

29 1.3 Initialize struct object
34 } 35 36 cout << setiosflags( ios::left ) << setw( 10 ) << "Account" << setw( 16 ) << "Last Name" << setw( 11 ) << "First Name" << resetiosflags( ios::left ) << setw( 10 ) << "Balance" << endl; 40 41 clientData client; 42 43 inCredit.read( reinterpret_cast<char *>( &client ), sizeof( clientData ) ); 45 46 while ( inCredit && !inCredit.eof() ) { 47 if ( client.accountNumber != 0 ) outputLine( cout, client ); 50 inCredit.read( reinterpret_cast<char *>( &client ), sizeof( clientData ) ); 53 } 54 55 return 0; 56 } 57 58 void outputLine( ostream &output, const clientData &c ) 59 { 60 output << setiosflags( ios::left ) << setw( 10 ) << c.accountNumber << setw( 16 ) << c.lastName << setw( 11 ) << c.firstName << setw( 10 ) << setprecision( 2 ) << resetiosflags( ios::left ) << setiosflags( ios::fixed | ios::showpoint ) << c.balance << '\n'; 66 } 1.3 Initialize struct object 2. Read in data and put it into client 3. Function definition Inputs sizeof( clientData) bytes and puts it into &client (the memory address of client). Uses eof function to test for the end of file. Outputs data in client to the screen.

30 Program Output Account Last Name First Name Balance
Brown Nancy Dunn Stacey Barker Doug Smith Dave Stone Sam Program Output

31 14.11 Example: A Transaction Processing Program
The following example uses random access files to achieve instant access processing of a bank’s account information. We will update existing accounts add new accounts delete accounts store a formatted listing of all accounts in a text file

32 1. Load headers 1.1 Function prototypes
1 // Fig : fig14_15.cpp 2 // This program reads a random access file sequentially, 3 // updates data already written to the file, creates new 4 // data to be placed in the file, and deletes data 5 // already in the file. 6 #include <iostream> 7 8 using std::cout; 9 using std::cerr; 10 using std::cin; 11 using std::endl; 12 using std::ios; 13 14 #include <fstream> 15 16 using std::ofstream; 17 using std::ostream; 18 using std::fstream; 19 20 #include <iomanip> 21 22 using std::setiosflags; 23 using std::resetiosflags; 24 using std::setw; 25 using std::setprecision; 26 27 #include <cstdlib> 28 #include "clntdata.h" 29 30 int enterChoice(); 31 void textFile( fstream& ); 32 void updateRecord( fstream& ); 33 void newRecord( fstream& ); 1. Load headers 1.1 Function prototypes

33 1.3 Initialize fstream object
34 void deleteRecord( fstream& ); 35 void outputLine( ostream&, const clientData & ); 36 int getAccount( const char * const ); 37 38 enum Choices { TEXTFILE = 1, UPDATE, NEW, DELETE, END }; 39 40 int main() 41 { 42 fstream inOutCredit( "credit.dat", ios::in | ios::out ); 43 44 if ( !inOutCredit ) { cerr << "File could not be opened." << endl; exit ( 1 ); 47 } 48 49 int choice; 50 51 while ( ( choice = enterChoice() ) != END ) { 52 switch ( choice ) { case TEXTFILE: textFile( inOutCredit ); break; case UPDATE: updateRecord( inOutCredit ); break; case NEW: newRecord( inOutCredit ); break; case DELETE: deleteRecord( inOutCredit ); break; default: 1.2 enumeration 1.3 Initialize fstream object 1.4 Test for file open 1.5 Initialize variable 2. while loop and switch statements fstream objects can both input and output. Calls function enterChoice

34 Opens or creates print.txt
cerr << "Incorrect choice\n"; break; } 70 inOutCredit.clear(); // resets end-of-file indicator 72 } 73 74 return 0; 75 } 76 77 // Prompt for and input menu choice 78 int enterChoice() 79 { 80 cout << "\nEnter your choice" << endl << "1 - store a formatted text file of accounts\n" << " called \"print.txt\" for printing\n" << "2 - update an account\n" << "3 - add a new account\n" << "4 - delete an account\n" << "5 - end program\n? "; 87 88 int menuChoice; 89 cin >> menuChoice; 90 return menuChoice; 91 } 92 93 // Create formatted text file for printing 94 void textFile( fstream &readFromFile ) 95 { 96 ofstream outPrintFile( "print.txt", ios::out ); 97 98 if ( !outPrintFile ) { cerr << "File could not be opened." << endl; exit( 1 ); 3. Function definitions Opens or creates print.txt

35 Outputs formatted data to print.txt
} 102 outPrintFile << setiosflags( ios::left ) << setw( 10 ) << "Account" << setw( 16 ) << "Last Name" << setw( 11 ) << "First Name" << resetiosflags( ios::left ) << setw( 10 ) << "Balance" << endl; readFromFile.seekg( 0 ); 108 clientData client; readFromFile.read( reinterpret_cast<char *>( &client ), sizeof( clientData ) ); 112 while ( !readFromFile.eof() ) { if ( client.accountNumber != 0 ) outputLine( outPrintFile, client ); 116 readFromFile.read( reinterpret_cast<char *>( &client ), sizeof( clientData ) ); } 120 } 121 122 // Update an account's balance 123 void updateRecord( fstream &updateFile ) 124 { int account = getAccount( "Enter account to update" ); 126 updateFile.seekg( ( account - 1 ) * sizeof( clientData ) ); 128 clientData client; updateFile.read( reinterpret_cast<char *>( &client ), sizeof( clientData ) ); 132 if ( client.accountNumber != 0 ) { 3. Function definitions Outputs formatted data to print.txt Moves to proper location in file based upon account number. Input data to client

36 Check if account exists.
outputLine( cout, client ); cout << "\nEnter charge (+) or payment (-): "; 136 double transaction; // charge or payment cin >> transaction; // should validate client.balance += transaction; outputLine( cout, client ); updateFile.seekp( ( account-1 ) * sizeof( clientData ) ); updateFile.write( reinterpret_cast<const char *>( &client ), sizeof( clientData ) ); } else cerr << "Account #" << account << " has no information." << endl; 149 } 150 151 // Create and insert new record 152 void newRecord( fstream &insertInFile ) 153 { int account = getAccount( "Enter new account number" ); 155 insertInFile.seekg( ( account-1 ) * sizeof( clientData ) ); 157 clientData client; insertInFile.read( reinterpret_cast<char *>( &client ), sizeof( clientData ) ); 161 if ( client.accountNumber == 0 ) { cout << "Enter lastname, firstname, balance\n? "; cin >> client.lastName >> client.firstName >> client.balance; client.accountNumber = account; insertInFile.seekp( ( account - 1 ) * 3. Function definitions Modify account balance, find proper location in file, and write to file. Create a new record. Check if account exists. Input data. Position pointer

37 Delete record by replacing it with an empty account.
sizeof( clientData ) ); insertInFile.write( reinterpret_cast<const char *>( &client ), sizeof( clientData ) ); } else cerr << "Account #" << account << " already contains information." << endl; 176 } 177 178 // Delete an existing record 179 void deleteRecord( fstream &deleteFromFile ) 180 { int account = getAccount( "Enter account to delete" ); 182 deleteFromFile.seekg( (account-1) * sizeof( clientData ) ); 184 clientData client; deleteFromFile.read( reinterpret_cast<char *>( &client ), sizeof( clientData ) ); 188 if ( client.accountNumber != 0 ) { clientData blankClient = { 0, "", "", 0.0 }; 191 deleteFromFile.seekp( ( account - 1) * sizeof( clientData ) ); deleteFromFile.write( reinterpret_cast<const char *>( &blankClient ), sizeof( clientData ) ); cout << "Account #" << account << " deleted." << endl; } Write new data to file 3. Function definitions Delete record by replacing it with an empty account.

38 3. Function definitions Formatted output. 199 else
cerr << "Account #" << account << " is empty." << endl; 201 } 202 203 // Output a line of client information 204 void outputLine( ostream &output, const clientData &c ) 205 { output << setiosflags( ios::left ) << setw( 10 ) << c.accountNumber << setw( 16 ) << c.lastName << setw( 11 ) << c.firstName << setw( 10 ) << setprecision( 2 ) << resetiosflags( ios::left ) << setiosflags( ios::fixed | ios::showpoint ) << c.balance << '\n'; 212 } 213 214 // Get an account number from the keyboard 215 int getAccount( const char * const prompt ) 216 { int account; 218 do { cout << prompt << " ( ): "; cin >> account; } while ( account < 1 || account > 100 ); 223 return account; 225 } 3. Function definitions Formatted output.

39 Program Output AFTER OPTION 1 PRINT.TXT CONTAINS:
Account Last Name First Name Balance Brown Nancy Dunn Stacey Barker Doug Smith Dave Stone Sam Program Output Enter account to update ( ): 37 Barker Doug Enter charge (+) or payment (-): Barker Doug Enter new account number ( ): 22 Enter lastname, firstname, balance ? Johnston Sarah Enter account to delete ( ): 29 Account #29 deleted.

40 14.12 Input/Output of Objects
When object data members output to a disk file lose the object’s type information only have data bytes Possible solution precede object output by specifying its type


Download ppt "Chapter 14 – File Processing"

Similar presentations


Ads by Google