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 <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstdlib>
#include <stdlib.h>
using namespace std;
// Function Prototypes
void DisplayTitle();
float GetBegBal(string);
void DisplayBal(double);
string GetData(ifstream&);
double ProcessCheck(double, double);
double ProcessDeposit(double, double);
double ProcessATM(double, double);
double ProcessSvcChg(double);
//Global Constants
const double CHARGE = 10,
ATMFEE = 2;
struct totals{
double Credits,
Debits,
Service;
};
int main()
{
//Variable Declarations
int transCode;
double balance,
transAmt;
ifstream fin;
string input;
int space_position = input.find(' ');
int transCtr;
//Declared my structure
totals print;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
//Displays the title.
DisplayTitle();
//Opens the File.
fin.open("C:\\Users\\Kodi\\Desktop\\checkIn.dat");
//Creates a message if the file failed to open.
if (fin.fail( ))
{
cout << "Input file opening failed.\n";
system("pause");
exit(1);
}
//While it is not the end of file.
while(! fin.eof())
{
//Inputs the numbers into a string.
input = input + " " + GetData(fin);
}
//Closes the file.
fin.close();
balance = static_cast<double>(GetBegBal(input));
cout << balance;
cout << input;
system("pause");
/*for (int i = 0; i < 100; i++){
transCode = atoi(input.substr(0, space_position).c_str());
}*/
transCode = 0;
while(transCode != 0)
{
switch(transCode)
{
case 1:
balance = ProcessCheck(balance, transAmt);
print.Debits = print.Debits + transAmt;
break;
case 2:
balance = ProcessDeposit(balance, transAmt);
print.Credits = print.Credits + transAmt;
break;
case 3:
balance = ProcessATM(balance, transAmt);
print.Service = print.Service + ATMFEE;
print.Debits = print.Credits + transAmt;
break;
}
DisplayBal(balance);
if(balance < 0){
balance = ProcessSvcChg(balance);
print.Service = print.Service + CHARGE;
}
}
system("pause");
return 0;
}
void DisplayTitle()
{
cout << "\n Check Register\n\n";
}
float GetBegBal(string start)
{
float x;
int space_position = start.find('_');
x = atof(start.substr(0, space_position).c_str());
return x;
}
void DisplayBal(double x)
{
cout << "\t\tBalance = $" << setw(10) << x;
}
string GetData(ifstream& in)
{
string value;
in >> value;
return value;
}
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);
}
|