This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA
{,}"); = 1-9"); = b account balance"); d deposit"); n new account"); t bank totals");
Project Four – DME
Page 9/11
printf("\n printf("\n return;
w x
withdrawal"); delete account");
} // set atm account, code, and amount variables atm = INTEGER(argv[1]); account = INTEGER(argv[2]); code = argv[3][0]; amount = (argc < 5) ? 0 : INTEGER(argv[4]); if ((atm < 1) || (atm > NUM_ATMS)) { printf("\n **Illegal ATM"); return; } // send message to atm sprintf(buf, "%c,%d,%d", code, account, amount); printf("\n CLI: Send to ATM%d '%s'", atm, buf); POSTMESSAGE(CLI, atm, buf); return; } // end ATM // ************************************************************************** void CL4_listMessages(int argc, char* argv[]) { int i; for (i=0; i%d:%s", i, messages[i].from, messages[i].to, messages[i].msg); SWAP; } return; } // end messages // ************************************************************************** void CL4_stress1(int argc, char* argv[]) // stress1 { char buf[sizeof(Message)]; printf("\nCreate new account 1111 with $111"); POSTMESSAGE(CLI,1,"n,1111,111"); printf("\nCreate new account 2222 with $222"); POSTMESSAGE(CLI,2,"n,2222,222"); printf("\nDeposit $2000 to account 1111"); POSTMESSAGE(CLI,1,"d,1111,2000"); printf("\nWithdraw $22 from account 2222"); POSTMESSAGE(CLI,2,"w,2222,22"); printf("\nRequest balance of account 1111"); POSTMESSAGE(CLI,1,"b,1111"); printf("\nWithdraw $1111 from account 1111"); POSTMESSAGE(CLI,1,"w,1111,1111"); printf("\nRequest balance of account 1111"); POSTMESSAGE(CLI,1,"b,1111");
BYU, CS 345
Project Four – DME
Page 10/11
printf("\nRequest balance of account 2222"); POSTMESSAGE(CLI,2,"b,2222"); printf("\nDeposit $1800 to account 222"); POSTMESSAGE(CLI,2,"d,2222,1800"); printf("\nRequest balance of account 2222"); POSTMESSAGE(CLI,2,"b,2222"); printf("\n Account Summary:"); POSTMESSAGE(CLI,1,"t,9999"); CL4_listMessages(argc, argv); return; } // end stress1 // ************************************************************************** void CL4_stress2(int argc, char* argv[]) // stress2 { char buf[sizeof(Message)]; int a, atm; #define startAccount 1001 #define endAccount 1009 //define accounts 1001 thru 1009 with $100 in each for (atm=1,a=startAccount; a<=endAccount; atm++,a++) { sprintf(buf, "%c,%d,%d", 'n', a, 100); POSTMESSAGE(CLI,atm,buf); } // deposit $9 to 1st account, $18 to 2nd, ... for (atm=1; atm<10; atm++) { for (a=startAccount; a<=endAccount; a++) { sprintf(buf, "%c,%d,%d", 'd', a, a-startAccount+1); POSTMESSAGE(CLI,atm,buf); } } // withdraw $8 from 1st, $16 from 2nd, ... for (atm=1,a=startAccount; a<=endAccount; atm++,a++) { sprintf(buf, "%c,%d,%d", 'w', a, (a-startAccount+1)*8); POSTMESSAGE(CLI,atm,buf); } // withdrawal $100 from each account for (atm=1,a=startAccount; a<=endAccount; atm++,a++) { sprintf(buf, "%c,%d,%d", 'w', a, 100); POSTMESSAGE(CLI,atm,buf); } // examine results thru atms for (atm=1,a=startAccount; a<=endAccount; atm++,a++) { sprintf(buf, "%c,%d", 'b', a); POSTMESSAGE(CLI,atm,buf); } // get bank summary POSTMESSAGE(CLI,1,"t,9999"); CL4_listMessages(argc, argv); return; } // end stress2
BYU, CS 345
Project Four – DME
Page 11/11