Example #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
Example #2
0
void ClientData::searchAccount()
 {
	ifstream indatabase("ATM.txt", ios::in | ios::binary);

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

 cout << left << setw( 10 ) << "Account" << setw( 16 )
<< setw( 11 ) << "User Name" << left
 << setw( 10 ) << right << "Balance" << endl;

 ClientData database; // create record

indatabase.read(reinterpret_cast< char *>(&database),
   sizeof(ClientData));

// read all records from fil e
while (indatabase && !indatabase.eof() )
{
  // display record
 
 if ( database.getAccountNumber() != 0 )
     //outputLine(cout, client);

  indatabase.read(reinterpret_cast < char *>(&database),
        sizeof(ClientData));
  
} // end while
} // end search record
Example #3
0
// create formatted text file for printing
void createTextFile(fstream &readFromFile)
{
	// create text file
	ofstream outPrintFile("print.txt", ios::out);

	// exit program if ofstream cannot create file
	if (!outPrintFile)
	{
		cerr << "File could not be created" << endl;
		exit(1);
	} // end if

	outPrintFile << left << setw(10) << "Account" << setw(16)
		<< "Last name" << setw(11) << "First Name" << right << setw(10)
		<< "Balance" << endl;

	// ** SET FILE POSITION POINTER TO BEGINNING OF readFromFile
	readFromFile.seekg(0);

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

	// copy all records from record file into text file
	while (!readFromFile.eof() ) // While not the end of file
	{
		// Write single record to text file
		if (client.getAccountNumber() != 0) // skip empty records
			outputLine(outPrintFile, client);

		// read next record from record file
		readFromFile.read(reinterpret_cast<char * >(&client), sizeof( ClientData ) );
	} // end while
} // end function createTextFile
Example #4
0
int main()
{
   ifstream inCredit( "credit.dat", ios::in | ios::binary );

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

   cout << left << setw( 10 ) << "Account" << setw( 16 )
      << "Last Name" << setw( 11 ) << "First Name" << left
      << setw( 10 ) << right << "Balance" << endl;

   ClientData client; // create record

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

   // read all records from file
   while ( inCredit && !inCredit.eof() ) 
   {
      // display record
      if ( client.getAccountNumber() != 0 )
         outputLine( cout, client );

      // read next from file
      inCredit.read( reinterpret_cast< char * >( &client ),
         sizeof( ClientData ) );
   } // end while
} // end main
Example #5
0
// display single record
void outputLine( ostream &output, const ClientData &record )
{
   output << left << setw( 10 ) << record.getAccountNumber()
      << setw( 16 ) << record.getLastName()
      << setw( 11 ) << record.getFirstName()
      << setw( 10 ) << setprecision( 2 ) << right << fixed 
      << showpoint << record.getBalance() << endl;
} // end function outputLine
Example #6
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
Example #7
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
void createPrimary(istream& read, ostream& primary){
    int number,byte = 0;
    map<int,int> mymap;
    PrimaryIndex p;
    ClientData client;
    read.clear();
    read.seekg(0);
    primary.seekp(0);
    if(read.eof())return;
    read >> client;
    while(!read.eof()){
        if(number = client.getAccountNumber()){
            mymap[number] = byte;
            byte = read.tellg();
        }
        read >> client;
    }
    for(map<int,int>::iterator it = mymap.begin(); it != mymap.end(); it++){
        p.AccountNumber = it->first;
        p.Byte = it->second;
        primary.write(reinterpret_cast<char*>(&p), sizeof(PrimaryIndex));
    }
}