fstream customerFile("customer.txt", ios::in | ios::out | ios::binary);
void createCustomerFile( fstream & customerFile )
{
int MAXREC;
cout << "Enter number of records you want to create for customer File" << endl;
cin >> MAXREC;
C blankRec = { 0 }; // blank record to use to create file
for( int k = 0; k < MAXREC; k++ )
customerFile.write(reinterpret_cast <char *> ( &blankRec), sizeof( C ));
}
void newCustomer( fstream & customerFile, int latestCustomerID, int acct, int transactionNum, int accNumber)
{
C record;
//move to start of record
customerFile.seekg((acct ) * sizeof( C ), ios::beg );
customerFile.read( reinterpret_cast<char *> (&record), sizeof( C ) );
if ( record.customerID == 0 )
cout << "Customer account is there already.\n";
else
{
record.customerID = latestCustomerID;
cin.get();
cout << "Enter first name "<<endl;
gets(record.name);
cout << "Enter surname" << endl;
gets(record.surname);
cout << "Enter number of Accounts" << endl;
cin >> record.numAccounts;
record.accArray = new A[record.numAccounts]; //create dynamic array
for(int i =0; i < record.numAccounts;i++)
{
record.accArray[i].accNumber = accNumber;
record.accArray[i].transactionID = transactionNum;
cout << "Transaction ID = " << record.accArray[i].transactionID << endl;
cout << "Enter account type, either D or C" << endl;
cin >> record.accArray[i].accType;
if(record.accArray[i].accType == 'D' || record.accArray[i].accType == 'd' )
{
cout <<"Enter intrest Rate" << endl;
cin >> record.accArray[i].intrestRate;
cout <<"Enter balance" << endl;
cin >> record.accArray[i].balance;
cout << "acc Number " << record.accArray[i].accNumber <<endl;
accNumber++;
}
else if(record.accArray[i].accType == 'C' || record.accArray[i].accType == 'c')
{
cout <<"Enter balance" << endl;
cin >> record.accArray[i].balance;
cout << "acc Number " << record.accArray[i].accNumber <<endl;
accNumber++;
}
else if(record.accArray[i].accType != 'c' || 'd')
{
cout << "Error you must redo this step, you have not created an account" << endl;
}
}
customerFile.seekp( ( acct ) * sizeof( C ), ios::beg );
customerFile.write( reinterpret_cast< char* > (&record), sizeof( C ) );
customerID++;
infile.close();
}
return;
}
void updateCustomer(fstream & customerFile)
{
C record;
int customerid;
cout << "Enter customer id" << endl;
cin >> customerid;
customerFile.seekg((customerid) * sizeof( C ), ios::beg );
customerFile.read(reinterpret_cast<char*>(&record),sizeof(C));
int numBytes = customerFile.tellg();
int offset = (numBytes - 1) * sizeof(C);
customerFile.seekp(offset - sizeof(C));
char option;
bool menuDisplay = true;
while(menuDisplay == true)
{
system("CLS");
cout << MENU2;
cin >> option;
option = toupper(option);
cin.get();
if(option == 'n')
{
cin.get();
gets(record.name);
cout << "changing the first name" << endl;
system("PAUSE");
}
else if(option == 's')
{
cin.get();
gets(record.surname);
cout << "changing the surname" << endl;
system("PAUSE");
}
else if(option == 'X')
{
menuDisplay = false;
}
}
cout << record.name;
cout << record.surname;
customerFile.write( reinterpret_cast<char *> (&record), sizeof( C ) );
}