#include <iostream>
using std::cerr;
using std::cout;
using std::endl;
using std::fixed;
using std::ios;
using std::left;
using std::right;
using std::showpoint;
#include <string>
using std::string;
#include <iomanip>
using std::setprecision;
using std::setw;
#include <fstream>
using std::ifstream;
using std::ostream;
#include <cstdlib>
using std::exit; // exit function prototype
class Account
{
public:
Account( )
{
}
Account( int accountNumberValue, string lastNameValue, string firstNameValue, double balanceValue )
{
setAccountNumber( accountNumberValue );
setLastName( lastNameValue );
setFirstName( firstNameValue );
setBalance( balanceValue );
}
int getAccountNumber() const
{
return accountNumber;
}
void setAccountNumber( int accountNumberValue )
{
accountNumber = accountNumberValue; // should validate
}
string getLastName() const
{
return lastName;
}
void setLastName( string lastNameString )
{
const char *lastNameValue = lastNameString.data();
strncpy( lastName, lastNameValue, 5 );
lastName[ 5 ] = '\0';
}
string getFirstName() const
{
return firstName;
}
void setFirstName( string firstNameString )
{
const char *firstNameValue = firstNameString.data();
strncpy( firstName, firstNameValue, 5 );
firstName[ 5 ] = '\0';
}
double getBalance() const
{
return balance;
}
void setBalance( double balanceValue )
{
balance = balanceValue;
}
private:
int accountNumber;
char lastName[ 15 ];
char firstName[ 10 ];
double balance;
};
void outputLine( ostream&, const Account & ); // prototype
int main()
{
ifstream inCredit( "credit.dat", ios::in );
if ( !inCredit )
{
cerr << "File could not be opened." << endl;
exit( 1 );
} // end if
Account client; // create record
inCredit.read( reinterpret_cast< char * >( &client ), sizeof( Account ) );
while ( inCredit && !inCredit.eof() )
{
if ( client.getAccountNumber() != 0 )
outputLine( cout, client );
inCredit.read( reinterpret_cast< char * >( &client ),sizeof( Account ) );
}
return 0;
}
void outputLine( ostream &output, const Account &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;
}
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20
1 AAAAA BBBBB 1.20