//Chkgacct.h//chkgacct classes
#ifndef chkgacct_h # define chkgacct_h
class ChkgAcct {public: ChkgAcct (); void deposit (double amt); bool checkWithdraw (double amt); bool atmWithdraw (double amt); double getBalance (); int setTrack (int type, double amt); // push the type and amt into track void getTrack (int i, int & cTracktype, double & cTrackamt); // pop type and amount of number i transaction private: double balance; int Tracktype [51]; // store the type of transaction double Trackamt [51] ; // store the amount}; # endif // chkgacct.cpp
#include "chkgacct.h" #include
Chkgacct () {balance = 100.0; for (int i = 1; i <= 50; i ) {trackType [i] = 0; trackamt [i] = 0; // Initialize the track}
Void Chkgacct :: Deposit (double amt) {balance = Balance Amt;}
Bool Chkgacct :: CheckwithDraw (Double AMT) {ix (AMT <= Balance) {Balance = Balance-amt; Return True;} else {balance = balance-10; return false;}}
Bool Chkgacct :: AtmwithDraw (Double AMT) {IF (AMT <= Balance) {Balance = Balance-AMT-1; Return True;} else returnaf false;}
Double Chkgacct :: getBalance () {Return Balance;
INT Chkgacct :: setTrack (int type, double amt) {static int = 0; // store the Total Times of the Transaction i ; if (i <= 50) {TrackType [i] = type; trackamt [i] = Amt;} // if the Times of the Transaction is Less Than 50 else /// if is more Than 50, IE 51, Using Push {i = 50; for (int J = 1; j <50; j ) {TRACKTYPE [J] = TrackType [J 1]; TrackAMT [J] = TRACKAMT [J 1];} TrackType [50] = Type; TRACKAMT [50] = Amt;} Return i;}
void ChkgAcct :: getTrack (int i, int & cTracktype, double & cTrackamt) {cTracktype = Tracktype [i]; cTrackamt = Trackamt [i];} // client.cpp // create 10 account to test # include "ChkgAcct.h" #include
Using namespace std;
Int main () {Chkgacct Client [10]; int accessid; // the id of account
INT TYPE; // Type of Transaction Double Amount = 0; // Amount of Transaction Int TypeGet; // Type of Transaction Got from Every Account Double AmountGet; // Amount of Transaction Got from Every Account
CHAR CH, FLAG; String Str; // Store Input as The String Type of Amount /// DO Start Loop DO {Str = ""; System ("CLS"); // Function To Clear The ScreeM Cout << * ******************************************** << Endl COUT << "please input your account id, from 0 to 9:" << Endl; cout << "INPUT:"; // 1 make sure the input is 0 to 9 int i = 0; do {ch = getch (); If (CH> = '0' && ch <= '9') {PUTCHAR (CH); i ;}} while (i <1); Accountid = CH-'0 '; cout << end1; // ~ 1
IF (Accountid> = 0 && Accountid <= 9) cout << "Account" << Accountid << ", You Have: << Client [Accountid] .getBalance () <<" l.. g et e e N '; // set the flag to test if the client want to quit
Do {cout << "************************************************** *** "<< endl; cout <<" please choose the type your transaction: / n "<<" 1, deposit / n "<<" 2, checkwithdrawal / n "<<" 3, atmwithdrawal / n " << "4, Check Account / N" << "5, Recent 50 Transactions" << endl; cout << "6-9, to logout" << Endl; cout << "Input:"; // ~ 2 Make Sure THE INPUT IS NUMBER INT I = 0; Do {CH = Getch (); if (CH> = '0' && Ch <= '9') {PUTCHAR (CH); i ;}} While (i <1) ; Type = ch-'0 '; cout << Endl; // ~ 2 IF (Type> = 1 && type <= 3) {cout << "*************** ****************************** "<< endl; cout <<" Input the Amount (Positive Value): "<< Endl; cout << "INPUT:"; // 3 Make Sure The First Number is not zero do {ch = getch ();} while (ch == '0' || CH <= '0' || CH> '9'); Str = CH; PUTCHAR (CH); I = 1; / ~ 3 // 4 Make Sure Input is Number, and Enter Means Finish Do {CH = Getch (); if (CH> = '0' && ch <= '9' && ch! = 13) {PUTCHAR (CH); STR = STR CH; I ; } // ignore other input} while (ch! = 13); cout << endl; // ~ 4
//5 translate string to double amount = 0; for (int J = 0; j
/ 6 CHECK IF the Client Want to Cancel / and The Input IS Y / N COUT << Endl << "Are you Sure? Y / N: << Endl; i = 0; do {CH = getCH (); if (CH == 'Y' || CH == 'N') {PUTCHAR (CH); I ;}} while (i <1); cout << Endl; / ~ 6 if (CH == 'n') {System ("CLS"); COUT << "You Cancel the Transaction" << Endl; Continue;}} // end of iFSystem ("CLS"); cout << ********* ************************************* "<< endl; switch (type) {casse 1: {Client [ACCOUNTID] .Deposit (amount); cout << "succeed!" << endl; cout << "you Deposit" << Amount << "$." << Endl; client [accountid] .SetTrack (1 Amount); /// set the track with type and amount} Break;
Case 2: {if (! client [accountid] .checkwithdraw (amount)) {cout << "fail!" << endl; cout << "Your Account Do Not", "<< Endl; cout <<" $ 10.00 Service Charge Is Deducted! "<< Endl; Client [Accountid] .SetTrack (4, Amount);} else {cout <<" succeed! "<< endl; cout <<" you withdraw "<< Amount <<" $. "<< Endl; client [accountid] .Settrack (2, Amount);}}
Case 3: {if (! client [accountid) .atmwithdraw (amount)) {cout << "fail!" << endl; cout << "Your Account Do Not" "" << Endl; Client [AccountId] .SetTrack (5, Amount);} else {cout << "succeed!" << endl; cout << "you withdraw" << Amount << "$." << Endl; cout << "a $ 1 service charge IS Deducted "<< Endl; Client [Accountid] .SetTrack (3, Amount);}} Break; Case 4: {COUT <<" You have: "<< Client [Accountid] .getBalance () <<" $ " << "" left. "<< Endl;} Break; Case 5: {// 7 Output the resent transaction for (INT i = 50; i> = 1; i -) {client [accountid] .gettrack (i, TYPEGET, AMOUNTGET; IF (Typeget> 0 && Typeget <6) {switch (Typeget) {casse 1: cout << i << ", deposient:"; Break; Case 2: COUT << i << ", checkwithdraw:" Break; Case 3: COUT << i << ", amtwithdraw:"; Break; Case 4: COUT << i << ", Fail CheckwithDraw:"; Break; Case 5: cout << i << ", fail Atmwithdraw: "; Break;} cout << Amountge T << "$." << endl;}} // ~ 7} Break;