Banking Simulation Help Pt 1

This is a long program. I have included a brief description in the reply field at the bottom after the second part of the code.

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>

using namespace std;

const double OVERDRAFT_FEE = 35.00;
const int MAX_CUSTOMERS = 1000;

int linearSearch(string acno, const string acNums[], int numAccs)
{
int i;
for(i=0; i<numAccs; i++)
{
if(acno==acNums[i])
return i;
}
return -1;
}

void menu()
{
cout<<setw(22)<<"Geaux Tigers Bank ATM"<<endl;
cout<<setw(24)<<left;
cout<<"========================"<<endl;
cout<<"OPEN AN ACCOUNT......[1]"<<endl;
cout<<"CLOSE AN ACCOUNT.....[2]"<<endl;
cout<<"DEPOSIT..............[3]"<<endl;
cout<<"WITHDRAW.............[4]"<<endl;
cout<<"BALANCE INQUIRY......[5]"<<endl;
cout<<"CUSTOMERS LISTING....[6]"<<endl;
cout<<"EXIT.................[0]"<<endl;
}

void openAccount(string acno,string fName,string lName,
char midInit,double initBal,string acNums[],
string fNames[],string lNames[],char midInitials[],
double balances[],int& numAccs)
{
for(int i= numAccs; i<MAX_CUSTOMERS; i++)
{
acNums[i]= acno;
fNames[i]= fName;
lNames[i]= lName;
midInitials[i]= midInit;
balances[i]= initBal;
}
numAccs++;
}

void closeAccount(string acno,string acNums[],string fNames[],
string lNames[],char midInitials[],
double balances[],int& numAccs)
{
for(int i=numAccs; i<=MAX_CUSTOMERS ;i++)
{
acNums[i]= acNums[i+1];
fNames[i]= fNames[i+1];
lNames[i]= lNames[i+1];
midInitials[i]=midInitials[i+1];
balances[i]= balances[i+1];
}
numAccs--;
}
void deposit(string acno,double amount,string acNums[],
double balances[],int numAccs)
{
int i=linearSearch(acno, acNums, numAccs);//Is linear search a valid way to
//feed in i value?? Apply to all of
//some functions?
balances[i]= balances[i]+ amount;
}

void withdraw(string acno,double amount,const string acNums[],
double balances[],int numAccs)
{
int i=linearSearch(acno, acNums, numAccs);
if (amount>balances[i])
balances[i]= balances[i]-amount-OVERDRAFT_FEE;
else
balances[i]= balances[i]-amount;
}


void inquiry(string acno,const string acNums[],const string fNames[],
const string lNames[],const char midInitials[],const double
balances[],int numAccs)
{
int i = numAccs;
cout<<"------------------------------"<<endl;
cout<<"customer: "<<fNames[i]<<" "<<midInitials[i]<<". "<<lNames[i]<<endl;
cout<<"A/C #: "<<acNums[i]<<endl;
cout<<"Balance: $"<<setprecision(2)<<fixed<<balances[i]<<endl;
cout<<"------------------------------"<<endl;
}
//106
void customersList(const string acNums[],const string fNames[],
const string lNames[],const double balances[],
int numAccs)
{
if(numAccs==0)
cout<<" *** THERE ARE NO ACTIVE ACCOUNTS ***"<<endl;
else
cout<<" Geaux Tiger Bank, Louisiana LTD"<<endl;
cout<<" Customers Listing"<<endl;
cout<<" 100 Les Miles Dr., Baton Rouge, Louisiana 70802"<<endl;
cout<<"==========================================================="<<endl;
cout<<setw(14)<<left<<"a/c # "<<setw(14)<<left<<"First Name "<<setw(14)<<left<<"Last Name "<<setw(14)<<"Balance"<<endl;
cout<<"-----------------------------------------------------------"<<endl;
for(int i=0; i<numAccs;i++)
{

cout<<setw(14)<<left<<acNums[i]<<setw(14)<<left<<fNames[i]<<setw(14)<<left<<lNames[i]<<setw(14)<<setprecision(2)<<fixed<<"$"<<balances[i]<<endl;
}
cout<<"==========================================================="<<endl;
}


int main()
//129
{
fstream inStrInfo;
fstream inStrBal;
fstream outStrInfo;
fstream outStrBal;
string fileNameInfo ="acinfo.dbf";
string fileNameBal = "acbal.dbf";
string acno,lName,fName;
double initBal,amount;
char midInit;
string acNums[MAX_CUSTOMERS];
string lNames[MAX_CUSTOMERS];
string fNames[MAX_CUSTOMERS];
char midInitials[MAX_CUSTOMERS];
double balances[MAX_CUSTOMERS];
int numAccs,choice;

//Check for file existence before opening??

inStrInfo.open(fileNameInfo.c_str(), ios::in);
inStrBal.open(fileNameBal.c_str(), ios::in);

if(ifstream("acbal.dbf")&&ifstream("acinfo.dbf"))
{
cout<<"Almost there!"<<endl;
numAccs=0;
for(int i=0;i>MAX_CUSTOMERS;i++)
{
cout<<"Inside the 1st for loop";
inStrInfo>>acno[i];
inStrInfo>>lNames[i];
inStrInfo>>fNames[i];
inStrInfo>>midInitials[i];
inStrBal>>acno[i];
inStrBal>>balances[i];
numAccs++;
}
}
else
numAccs=0;

inStrInfo.close();
inStrBal.close();

cout<<"Just before the do while loop";

do
{
menu();
cout<<"Enter your choice: ";
cin>>choice;

Last edited on
//Part 2
switch(choice)
{
case 1:
cout<<"Enter a ten digit account number>"<<endl;
cin>>acno;

if(acno.length()!=10)
cout<<"Account number must be ten digits."<<endl;
if(linearSearch(acno,acNums,numAccs)>0)
cout<<acno<<" cannot be assigned to multiple customers."<<endl;
else
{
cout<<"Enter the first name>"<<endl;
cin>>fName;
cout<<"Enter the last name>"<<endl;
cin>>lName;
cout<<"Enter middle initial>"<<endl;
cin>>midInit;
cout<<"Enter initial deposit>"<<endl;
cin>>initBal;
}

if(initBal < 25.00)
cout<<"Insufficient funds to open account."<<endl;
else
openAccount(acno,fName,lName,midInit,initBal,acNums,fNames,lNames,
midInitials,balances,numAccs);
break;
//216
case 2:
cout<<"Enter a ten digit account number>"<<endl;
cin>>acno;

if(acno.length()!=10)
cout<<"Account number must be ten digits."<<endl;
else if(linearSearch(acno,acNums,numAccs)<0)
cout<<"Account number does not exist"<<endl;
else
closeAccount(acno,acNums,fNames,lNames,
midInitials,balances,numAccs);
break;
//228
case 3:
cout<<"Enter a ten digit account number>"<<endl;
cin>>acno;
if(acno.length()!=10)
cout<<"Account number must be ten digits."<<endl;
else if(linearSearch(acno,acNums,numAccs)<0)
cout<<"Account number does not exist"<<endl;
else
{
cout<<"Enter deposit amount>"<<endl;
cin>>amount;
}

if(amount<=0.00)
cout<<"Amount must be at least $0.01."<<endl;
else
deposit(acno,amount,acNums,balances,numAccs);
break;
//246
case 4:
cout<<"Enter a ten digit account number>"<<endl;
cin>>acno;
if(acno.length()!=10)
cout<<"Account number must be ten digits.";
else if(linearSearch(acno,acNums,numAccs)<0)
cout<<"Account number does not exist"<<endl;
else
{
cout<<"Enter withdrawal amount>"<<endl;
cin>>amount;
}
if(amount<=0.00)
cout<<"Amount must be at least $0.01."<<endl;
else
withdraw(acno, amount, acNums,balances,numAccs);
break;
//264
case 5:
cout<<"Enter a ten digit account number>"<<endl;
cin>>acno;
if(acno.length()!=10)
cout<<"Account number must be ten digits."<<endl;
else if(linearSearch(acno,acNums,numAccs)<0)
cout<<"Account number does not exist"<<endl;
else
inquiry(acno,acNums,fNames,lNames,midInitials,balances,numAccs);
break;

case 6:
customersList(acNums,fNames,lNames,balances,numAccs);
break;

case 0:
cout<<"Working!"<<endl;

break;

default:
cout<<"Enter a valid choice."<<endl;
exit(1);
break;
}

}while(choice!=0);

cout<<"After do-while."<<endl;

outStrInfo.open(fileNameInfo.c_str(), ios::out);
outStrBal.open(fileNameBal.c_str(), ios::out);


if(outStrBal.fail())
cout<<"File acbal.dbf failed to open."<<endl;
if(outStrInfo.fail())
cout<<"File acinfo.dbf failed to open."<<endl;
else
{
numAccs=0;
for(int i=0;i>MAX_CUSTOMERS;i++)
{
outStrInfo>>acno[i];
outStrInfo>>lNames[i];
outStrInfo>>fNames[i];
outStrInfo>>midInitials[i];
outStrBal>>acno[i];
outStrBal>>balances[i];
numAccs++;
}
}

outStrInfo.close();
outStrBal.close();

cout<<"Before Exit"<<endl;
return 0;
}
This is a class assignment meant to simulate a bank program. A ten digit account number must be enter, length verified, and then additional information entered and stored into parallel arrays. The program is to run until case 0 is chosen during which time outfiles are opened, updated, and closed.

If you need any clarification, I will try my best to answer.

Thank you so much!
Topic archived. No new replies allowed.