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
|
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
struct bankRec
{
int transaction;
double bankBalance;
};
// Function Prototypes
bankRec BuildRec(ifstream&);
void DisplayRec(bankRec);
void displayTitle();
double getBegBal(bankRec);
void displayBal(double);
void getData(bankRec&, int& , double&);
double processCheck(double, double);
double processDeposit(double, double);
double processATM(double, double);
double processSvcChg(double);
//Global Constants
const double CHARGE = 10,
ATMFEE = 2;
int main()
{
//Variable Declarations
bankRec emp;
int transCode;
double balance,
transAmt;
//file loading
ifstream inFile;
inFile.open("D:\\checkIn.dat");
if(inFile.fail())
{
cout << "The file didn't load";
}
else
cout <<"the file loaded";
while(! inFile.eof())
{
emp = BuildRec(inFile);
//DisplayRec(emp);
}
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
displayTitle();
balance = getBegBal(emp);
getData(emp,transCode, transAmt);
while(transCode != 0)
{
switch(transCode)
{
case 1: balance = processCheck(balance, transAmt); break;
case 2: balance = processDeposit(balance, transAmt); break;
case 3: balance = processATM(balance, transAmt); break;
}
displayBal(balance);
if(balance < 0)
balance = processSvcChg(balance);
getData(emp, transCode,transAmt);
}
inFile.close();
system("pause");
return 0;
}
bankRec BuildRec(ifstream& inFile)
{
bankRec temp;
inFile >> temp.transaction >> temp.bankBalance;
return temp;
}
void DisplayRec(bankRec temp)
{
cout << temp.transaction << setw(4) << temp.bankBalance << endl;
}
void displayTitle()
{
cout << "\n Check Register\n\n";
}
double getBegBal(bankRec temp)
{
double bal;
cout << " Enter beginning balance ";
bal=temp.bankBalance;
cout << bal;
return bal;
}
void displayBal(double x)
{
cout << "\t\tBalance = $" << setw(10) << x;
}
void getData(bankRec& temp, int& code, double& amt)
{
cout << "\n\n Enter transaction code (0 to exit) ";
code=temp.transaction;
cout << code;
if(code > 0)
{
cout << "\n Enter transaction amount ";
amt=temp.bankBalance;
cout << amt;
}
}
double processCheck(double bal, double amt)
{
cout << "\n Check = " << setw(10) << amt;
return (bal - amt);
}
double processDeposit(double bal, double amt)
{
cout << "\n Deposit = " << setw(10) << amt;
return (bal + amt);
}
double processATM(double bal, double amt)
{
cout << "\n ATM = " << setw(10) << amt;
bal = bal - amt;
displayBal(bal);
bal = bal - ATMFEE;
cout << "\n ATM Fee = " << setw(10) << ATMFEE;
return (bal);
}
double processSvcChg(double bal)
{
cout << "\n Service chg =" << setw(8) << CHARGE;
bal = bal - CHARGE;
displayBal(bal);
return (bal);
}
|