1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
int main()
{
AccountInfo bankRecord[MAX_CUSTOMERS];
string acno, lName, fName;
double initBal, amount;
char midInit;
int numAccs, pos,option;
// write code to read data from acinfo.dbf and acbal.dbf. The data
// should be put in the bankRecord array defined above. The records
// should be counted as the files are read
fstream inStrInfo;
fstream inStrBal;
fstream outStrInfo;
fstream outStrBal;
string fileNameInfo ="acinfo.dbf";
string fileNameBal = "acbal.dbf";
string acNums[MAX_CUSTOMERS];
string lNames[MAX_CUSTOMERS];
string fNames[MAX_CUSTOMERS];
char midInitials[MAX_CUSTOMERS];
double balances[MAX_CUSTOMERS];
inStrInfo.open(fileNameInfo.c_str(), ios::in);
inStrBal.open(fileNameBal.c_str(), ios::in);
if(ifstream("acbal.dbf")&&ifstream("acinfo.dbf"))
{
numAccs=0;
for(int i=0;i>MAX_CUSTOMERS;i++)
{
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();
do
{
menu();
cout<<endl;
cout<<"Select an option->";
cin>>option;
cout<<endl;
switch(option)
{
case 1:
cout<<"Enter a 10-character long account number->";
cin>>acno;
if (acno.length() != 10)
{
cout<<acno<<" must be 10-character long."<<endl;
}
else if (linearSearch(acno,bankRecord,numAccs) > 0)
{
cout<<acno<<" cannot be assigned to multiple customers."<<endl;
}
else
{
cout<<"Customer's first name ->";
cin>>fName;
cout<<"Customer's middle initial ->";
cin>>midInit;
cout<<"Customer's last name ->";
cin>>lName;
cout<<"Initial Deposit ->";
cin>>initBal;
if (initBal < 25.00)
{
cout<<"The initial balance required for a new account must be at least $25.00."<<endl;
}
else
openAccount(acno,fName,lName,midInit,initBal,bankRecord,numAccs);
}
break;
//write code to close an account
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;
//write code for a deposit transaction
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;
//write code for a withdrawal transaction
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;
//write code for balance inquiry
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;
//write code to generate customers list
case 6:
customersList(acNums,fNames,lNames,balances,numAccs);
break;
case 0:
break;
default:
cout<<"Invalid menu option"<<endl;
exit(1);
break;
}
}while (option != 0);
//Write code to overwrite acinfo.dbf and acbal.dbf
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();
return 0;
}
|