Applet: The process of simulating the withdrawal of ATM machines
1). Define two arrays that can hold 5 number of shapes, one for holding 5 people's card number, and one for saving the corresponding card number of the password
2). Determine whether the input card number is in the array.
3). If you enter a password in the array, determine if the password corresponding to the card number matches.
4). To determine the password, only 3 times the wrong password is allowed within 24 hours. Input errors should prompt for the remaining number of inputs, 3 times the error is entered in 24 hours to not allow the operation of the card.
5). The correct password allows the user to do the corresponding operation of the account.
6). Pay attention to the withdrawal limit.
7). The function for an ATM machine is the cycle of the process, that is, each customer will follow the above operation, a user operation is completed, the next user can also do the corresponding operation.
1. function Declaration section:
<span style= "FONT-SIZE:14PX;" >//randomly generates a card number void Inputcard (int m[],int count);//randomly generates a password void inputpwd (int m[],int count);//randomly generate moneyvoid inputmoney (int m[], int count);//Determine if the card number is correct bool Iscard (int m[],int count,int username);//output card number and password void outputcard_pd (int m[], int count);// Determine if the password is correct bool ispwd (int password, int pwd);//Get password int requestpwd (int username, int m[], int count) according to account number;//withdrawal operation INT Outputmone Y (int a, int b);//Transfer operation BOOL Tranmoney (int a, int m[], int count);//deposit Operation int Cunmoney (int a, int b);</span>
2. Corresponding method implementation
<span style= "FONT-SIZE:14PX;" > #import <foundation/foundation.h>//random input void Inputvalue (float a[], int count) {for (int i = 0; i < count; I + +) {A[i] = Arc4random ()% (40-20 + 1) + 20.5; }}//Ascending method void Tempsort (float a[], int x, int y) {if (a[x] > A[y]) {Float temp = a[x]; A[X] = A[y]; A[y] = temp; }}//sort function void sort (float a[], int count) {for (int i = 0; i < count-1; i++) {for (int j = 0; J < Count -1-i; J + +) {//Transposition method Tempsort (A, J, j+1); }}}//output void Outputvalue (float a[], int count) {printf ("\ n"); for (int i = 0; i < count; i++) {printf ("%.1f", A[i]); }}//randomly generated card number void Inputcard (int m[],int count) {for (int i = 0; i < count; i++) {M[i] = Arc4random ()% (9000 -1000 + 1) + 1000; }}//randomly generates the password void inputpwd (int m[],int count) {for (int i = 0; i < count; i++) {M[i] = Arc4random ()% (200- 100 + 1) + 100; }}//randomly generated moneyvoid inPutmoney (int m[],int count) {for (int i = 0; i < count; i++) {M[i] = Arc4random ()% (10000-10 + 1) + 10; }}//determine if the card number is correct bool Iscard (int m[],int count, int username) {BOOL flag = no; for (int i = 0; i < count; i++) {if (username = = M[i]) {flag = YES; }} return flag;} Determine if the password is correct bool ispwd (int password, int. pwd) {BOOL flag = NO; if (password = = pwd) {flag = YES; } return flag; Output card number and password void outputcard_pd (int m[], int count) {for (int i = 0; i < count; i++) {printf ("%4d", M[i]); } printf ("\ n");} Get the password subscript by account number. int requestpwd (int username,int m[],int count) {int index = 0; for (int i = 0; i < count; i++) {if (username = = M[i]) {index = i; }} return index;} Withdrawal operation int Outputmoney (int a, int b) {int x = a-A; A = x; return x;} Deposit operation int Cunmoney (int a, int b) {int x = a + b; A = x; return x;} </span>
3. Function Realization
<span style= "FONT-SIZE:14PX;" > #import <foundation/foundation.h>int Main (int argc, const char * argv[]) {//define 2 shaped array int username[5] = {0};//defines an array and initializes it to 0 int password[5] = {0}; int money[5] = {0};//account balance Inputcard (username, 5); Random card number inputpwd (password, 5); Random password Inputmoney (money, 5); Random Money OUTPUTCARD_PD (username, 5); Remove card number OUTPUTCARD_PD (password, 5); Remove password OUTPUTCARD_PD (money, 5); Random Money int Card_jie[5] = {0, 0, 0, 0, 0};//holds the blocked card number. while (1) {//Dead loop. int user = 0; Define card number initialization, int s = 0;//if S is 1, freeze, if 0, continue while (1) {printf ("Please enter bank card number: \ n"); scanf ("%d", &user); Enter the card number if (Iscard (username, 5, user)) {//Determine if the card number exists in printf ("card number is correct!\n"); Break End Loop}else{printf ("The card does not exist, please re-enter \ n"); }} Int J = requestpwd (user, username, 5); Get the subscript int for the app user name pwd = 0; Define the variable password, initialize it to 0//determine if the card freezes for (int i = 0; i < 5; i++) {if (card_jie[i] = = Username[j]) {//Determine if the password exists s = 1; If the stored freeze card number is in an array with this card number s = 1; printf ("Your card has been frozen and cannot be manipulated within 24 hours \"); Break }}//user name is correct, operation. if (Iscard (username, 5, user)) {if (s = = 0) {//Is not frozen. Account correct for (int i = 3; I >= 0; i--) {printf ("Please enter password: \ n"); scanf ("%d", &pwd); if (Ispwd (Password[j], pwd)) {//Judgment Password printf ("The password you entered is correct \ n"); Break } else {if (i = = 1) {///third time printf ("Password is wrong, you have entered 3 times and cannot operate within 24 hours. \ n"); When the card freezes, the freeze card number is stored in the array for (int i = 0; i < 5; i++) { if (card_jie[i] = = 0) { Card_jie[i] = Username[j]; If 0, the card number is saved in the array//printf ("ASDASD =%d\n", card_jie[i]); The break;//cycle ends and is stored. }} break; printf ("You entered the password is not correct, you have%d chances, please re-enter \ n", i-1); }}}}//When the account password is correct int x = Money[j]; Define the variable x, assigning the value after the money operation to X. if (Iscard (username, 5, user)) {if (Ispwd (Password[j], pwd) {//user name password is correct, do so. while (1) {int num = 0; printf ("Choose what you want to do: 1." Check the Balance 2. Withdrawals 3. Transfer 4. Deposit 5. Exit \ n "); scanf ("%d", &num); if (num = = 1) {//Query balance operation printf ("Your account balance is:%d\n", X); } else if (num = = 2) {//withdrawal int Mon = 0; printf ("Please enter the amount you want to withdraw: \ n"); scanf ("%d", &mon); if (x < Mon) {printf ("Your balance is insufficient!"); } else {x = Outputmoney (x, Mon);//Withdrawals printf ("Successful withdrawal, card balance:%d\n", X); }} else if (num = = 3) {//Transfer print F ("Please enter the account card number you want to transfer: \ n"); int phone = 0; scanf ("%d", &phone); if (Iscard (username, 5, phone)) {int c = requestpwd (phone, username, 5);//pass the card number to get the subscript of the card number. printf ("Please enter the amount you want to transfer: \ n"); int m = 0; scanf ("%d", &m); if (M > x) {printf ("Insufficient balance, you cannot transfer \ n"); } else { x = x-m; MONEY[C] = Money[c] + m; Add the amount of money to the other account. printf ("Transfer success!, you have the remaining balance:%d\n", X); }} else {printf ("you entered an incorrect card number \ n"); }} else if (num = = 4) {//Deposit printf ("Please enter the amount you want to deposit: \ n"); int y = 0; scanf ("%d", &y); x = Cunmoney (x, y);//Deposit Operation printf ("Deposit successful, your balance is:%d\n", X); } else if (num = = 5) {//exit money[j] = x;//When it is launched, replace the original balance with the operation. Break }}}}} return 0;} </span>
"Learning iOS: C language" applet: Implementing ATM functions like ATMs.