BankBalance Example Program
BankBalance Example Program
//Step 1
//Step 2
if (!infile)
//Step 3
{
cout << "Cannot open the input file." << endl;
cout << "Program terminates!!!" << endl;
return 1;
}
outfile.open("Ch5_money.out");
//Step 4
//Step 5
//Step 5
//Step 6
//Step 7
//Step 9
switch (transactionCode)
{
case 'D':
//Step 9.a
case 'd':
accountBalance = accountBalance
+ transactionAmount;
amountDeposited = amountDeposited
+ transactionAmount;
numberOfDeposits++;
break;
case 'I':
//Step 9.b
case 'i':
accountBalance = accountBalance
+ transactionAmount;
interestPaid = interestPaid
+ transactionAmount;
break;
case 'W':
//Step 9.c
case 'w':
accountBalance = accountBalance
- transactionAmount;
amountWithdrawn = amountWithdrawn
+ transactionAmount;
numberOfWithdrawals++;
if ((accountBalance < MINIMUM_BALANCE)
&& (!isServiceCharged))
{
accountBalance = accountBalance
- SERVICE_CHARGE;
isServiceCharged = true;
}
break;
default:
cout << "Invalid transaction code" << endl;
} //end switch
infile >> transactionCode >> transactionAmount;
}//end while
//Output Results
//Step 10
outfile << "Account Number: " << acctNumber << endl;
outfile << "Beginning Balance: $" << beginningBalance
<< endl;
outfile << "Ending Balance: $" << accountBalance
<< endl << endl;
outfile << "Interest Paid: $" << interestPaid << endl
<< endl;
outfile << "Amount Deposited: $" << amountDeposited
<< endl;
outfile << "Number of Deposits: " << numberOfDeposits
<< endl << endl;
outfile << "Amount Withdrawn: $" << amountWithdrawn
<< endl;
outfile << "Number of Withdrawals: "
<< numberOfWithdrawals << endl << endl;
if (isServiceCharged)
outfile << "Service Charge: $" << SERVICE_CHARGE
<< endl;
}
return 0;