예제 #1
0
// update balance in record
void updateRecord( fstream &updateFile )
{
   // obtain number of account to update
   int accountNumber = getAccount( "Enter account to update" );

   // move file-position pointer to correct record in file
   updateFile.seekg( ( accountNumber - 1 ) * sizeof( ClientData ) );

   // read first record from file
   ClientData client;
   updateFile.read( reinterpret_cast< char * >( &client ), 
      sizeof( ClientData ) );

   // update record
   if ( client.getAccountNumber() != 0 ) 
   {
      outputLine( cout, client ); // display the record

      // request user to specify transaction
      cout << "\nEnter charge (+) or payment (-): ";
      double transaction; // charge or payment
      cin >> transaction;

      // update record balance
      double oldBalance = client.getBalance();
      client.setBalance( oldBalance + transaction );
      outputLine( cout, client ); // display the record

      // move file-position pointer to correct record in file
      updateFile.seekp( ( accountNumber - 1 ) * sizeof( ClientData ) );

      // write updated record over old record in file
      updateFile.write( reinterpret_cast< const char * >( &client ), 
         sizeof( ClientData ) );
   } // end if
예제 #2
0
// create account
void ClientData::createAccount ()
{
	int accountNumber;
	int pinCode;
	string UserName;
	
	double balance;

    fstream outdatabase( "ATMData.txt", ios::in | ios::out | ios::binary );

// exit program if fstream cannot open file
 if (!outdatabase)
    {
   cerr << "File could not be opened." << endl;
   exit( 1 );
   } // end if

  cout << "Enter account number (1 to 10000, 0 to end input)\n? ";

 // require user to specify account number
   ClientData database;
   cin >> accountNumber;

 // user enters information, which i  copied into file
while ( accountNumber > 0 && accountNumber <= 10000 )
 {
// user enters pin code, user name, and balance
cout << "Enter Pin code, User name,  balance\n? ";
 
 cin >> pinCode;
 cin >>UserName;

 cin >> balance;

 // set record accountNumber, pincode, UserName, balance values
   database.setAccountNumber( accountNumber ) ;
   database.setPinCode(pinCode);
   database.setUserName( UserName );
   //database.setFirstName( firstName ) ;
   database.setBalance( balance );

// seek position in file of user-specified record
outdatabase.seekp( ( database.getAccountNumber() - 1 ) *
sizeof( ClientData ) ) ;

 // enable user to enter another account
 cout << "Enter account number\n? ";
 cin >> accountNumber;
 } // end while
 } // end save data to file
예제 #3
0
int main()
{
   int accountNumber;
   string lastName;
   string firstName;
   double balance;

   fstream outCredit( "credit.dat", ios::in | ios::out | ios::binary );

   // exit program if fstream cannot open file
   if ( !outCredit ) 
   {
      cerr << "File could not be opened." << endl;
      exit( EXIT_FAILURE );
   } // end if

   cout << "Enter account number (1 to 100, 0 to end input)\n? ";

   // require user to specify account number
   ClientData client;
   cin >> accountNumber;

   // user enters information, which is copied into file
   while ( accountNumber > 0 && accountNumber <= 100 ) 
   {
      // user enters last name, first name and balance
      cout << "Enter lastname, firstname, balance\n? ";
      cin >> lastName;
      cin >> firstName;
      cin >> balance;

      // set record accountNumber, lastName, firstName and balance values
      client.setAccountNumber( accountNumber );
      client.setLastName( lastName );
      client.setFirstName( firstName );
      client.setBalance( balance );

      // seek position in file of user-specified record
      outCredit.seekp( ( client.getAccountNumber() - 1 ) * 
         sizeof( ClientData ) );

      // write user-specified information in file
      outCredit.write( reinterpret_cast< const char * >( &client ),
         sizeof( ClientData ) );

      // enable user to enter another account
      cout << "Enter account number\n? ";
      cin >> accountNumber;
   } // end while
} // end main