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
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct bankAcct
{
int AccountID;
int Type;
double Balance;
int Term;
string AccountType;
};
// return 0 (non-negative), 1 (negative) or -1 (AccountID not found)
// sz == numbrer of accounts in the array
int updateBankDetails( bankAcct Acct[], int sz, int acno, double amount );
// sz == numbrer of accounts in the array
void printBankDetails( const bankAcct Acct[], int sz );
int main()
{
const int MAXSZ = 20 ;
bankAcct Acct[MAXSZ] ;
int sz = 3 ;
for(int i = 0; i < sz ; ++i )
{
cout << "Please enter your account ID: ";
cin >> Acct[i].AccountID;
cout << "Current = 1, Savings = 2, Fixed Deposit = 3"<<endl;
cout << "Please enter your account Type: ";
cin >> Acct[i].Type;
if(Acct[i].Type == 1)
{
Acct[i].AccountType = " Current";
}
else if(Acct[i].Type == 2)
{
Acct[i].AccountType = " Savings";
}
else if(Acct[i].Type == 3)
{
Acct[i].AccountType = "Fixed D";
}
cout << "Please key in your account Balance: ";
cin >> Acct[i].Balance;
cout << "Please key in your term(Months): ";
cin >> Acct[i].Term;
}
printBankDetails( Acct, sz );
cout << "\nEnter your AccountID : ";
int account_number ;
cin >> account_number ;
cout << "Enter Your Amount to Update : ";
double amount ;
cin >> amount;
int result = updateBankDetails( Acct, sz, account_number, amount);
if( result == 0 ) cout << "0 = Updated balance is zero or positive! " << endl;
else if( result == 1 ) cout << "1 = Updated balance is negative! " << endl;
else cout << "-1 = AccountID not found!" << endl;
}
// sz == numbrer of accounts in the array
void printBankDetails( const bankAcct Acct[], int sz )
{
cout << "\nDetails Are as Shown Below" << endl;
cout << "AccID AccType Balance Term" << endl;
cout << "----- ------- ------- ----" << endl;
for( int c = 0; c < sz ; ++c )
{
cout << Acct[c].AccountID << setw(15) << Acct[c].AccountType << setw(10) << fixed << setprecision(2) << Acct[c].Balance << setw(7) << Acct[c].Term << endl;
}
}
// locate and return the posion of the accounrt in the array
// return -1 if not found
// sz == numbrer of accounts in the array
int find_account( const bankAcct Acct[], int sz, int ac_no )
{
for(int i = 0; i < sz ; ++i )
if( Acct[i].AccountID == ac_no ) return i ;
return -1 ; // not found
}
// return 0 (non-negative), 1 (negative) or -1 (AccountID not found)
// sz == numbrer of accounts in the array
int updateBankDetails( bankAcct Acct[], int sz, int acno, double amount )
{
int pos = find_account( Acct, sz, acno ) ;
if( pos == -1 ) return -1 ;
Acct[pos].Balance = Acct[pos].Balance + amount ;
return Acct[pos].Balance < 0 ? 1 : 0 ;
}
|