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
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int MAX = 100;
struct ACCOUNT
{
int accNum;
string name;
double balance;
double acclimit;
};
// make functions prototypes
void sort(ACCOUNT , int );
int toSearch(ACCOUNT, int , int );
ACCOUNT Accounts(istream& , ACCOUNT& );
void PrintSingle(ostream& , int , double , double , ACCOUNT);
void Payment(istream& , ostream& , ACCOUNT, int );
int main()
{
// make calls here
return 0;
}
void sort(ACCOUNT cust[], int size)
{
ACCOUNT t;
for (int i = 0; i < size; i++)
{
for(int j = i + 1; j < size; j++)
{
if(cust[i].accNum > cust[j].accNum)
{
t.accNum = cust[i].accNum;
cust[i].accNum = cust[j].accNum;
cust[j].accNum = t.accNum;
t.name = cust[i].name;
t.balance = cust[i].balance;
t.acclimit = cust[i].acclimit;
cust[i].name = cust[j].name;
cust[i].balance = cust[j].balance;
cust[i].acclimit = cust[j].acclimit;
cust[j].name = t.name;
cust[j].balance = t.balance;
cust[j].acclimit = t.acclimit;
}
}
}
}
int toSearch(ACCOUNT cust[], int size, int target)
{
int beg = 0, end = size-1;
int mid = (beg + end) / 2;
if (target == cust[end].accNum)
{
return end;
}
if (target == cust[beg].accNum)
{
return beg;
}
while(beg < end)
{
if(target == cust[mid].accNum)
{
return mid;
}
else if(cust[mid].accNum > target)
{
end = mid;
}
else
{
beg = mid + 1;
}
mid = (beg + end)/2;
}
return -1;
}
ACCOUNT Accounts(istream& in, ACCOUNT& customers)
{
in >> customers.accNum;
in >> customers.name;
in >> customers.balance;
in >> customers.acclimit;
return customers;
}
void PrintSingle(ostream& out, int loc, double oldBal, double amount, ACCOUNT customers[])
{
out << left<< setw(10) << "Account"<< "|\t"<< setw(10)<< "Old Balance"<<"|\t"<< setw(10)<< "New Balance"<<"|\t"<< setw(10)<<"Credit Limit\n";
out <<"-------------------------------------------------------------\n";
out << setw(10)<< customers[loc].accNum <<"|\t"<< setw(10)<< oldBal<<" |\t"<< setw(10)<< customers[loc].balance<<" |\t";
out << setw(10)<< customers[loc].acclimit << endl;
}
void Payment(istream& in, ostream& out, ACCOUNT customers[], int count)
{
double amount, oldBal;
int target, loc;
in >> target >> amount;
loc = toSearch(customers, count, target);
if(loc == -1)
{
out << "Account " << target << " not found." << endl;
return;
}
oldBal = customers[loc].balance;
customers[loc].balance -= amount;
out << "\n\n*Paying $" << amount << " to Account " << target << endl;
PrintSingle(out, loc, oldBal, amount, customers);
}
|