<> Main functional modules :
one , Login interface
From left to right : The first eleven digits represent the account number , The next six digits represent the account password , Account balance with decimal point , Next 1 The representative account is normal (3 The representative's account has been reported lost ), hinder 1 The representative is the administrator's account , If yes 2 Represents an ordinary user account .
two , Ordinary users
It has six functions
three , administrators
It also has six functions
<> The automatic withdrawal has two interfaces: administrator and ordinary user , The code is as follows :
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <conio.h> #
include <time.h> #include <windows.h> using namespace std;
/*flagI Mark current login account ,flagN Mark account for current transfer */ int flagI, flagN; int userID = 0; int
UserNumber= 0; struct User // Don't move the position of the variable here { char name[50]; // account number double money;
// amount of money int flag; // Can the account be used normally , 1 Can express ,2 Indicates freezing ,3 Means to report the loss ,, wait , You can define it yourself ; int d; // Account type char
key[50]; // password } user[10000]; void ChuCun() // Update user information { FILE* fp; if ((fp = fopen(
"user.txt", "w")) != NULL) { for(int i=1; i<=UserNumber; i++) { fwrite(&user[i],
sizeof(struct User), 1, fp); } fclose(fp); } else printf(" User information update failed "); } void
TiQu() // Extract user information { UserNumber = 0; FILE* fp; if ((fp = fopen("user.txt", "r")) !=
NULL) { while (!feof(fp)) { fread(&user[++UserNumber], sizeof(struct User), 1,
fp); } fclose(fp); } else printf(" Failed to load user information "); UserNumber--; // } void drawmoney(
)// function 1: Withdrawal business { int a, i; char c; while (1) { printf("\t Please enter your withdrawal amount ( Whole hundred ):"); scanf(
"%d", &a); if (a > user[userID].money) printf("\t Insufficient account balance , Please re-enter !\n"); else if (a <
0 || a % 100 != 0) printf("\t Incorrect input , Please re-enter !\n"); else break; } getchar(); user[
userID].money -= a; printf("\t Withdrawal succeeded , Please keep your money !\n"); printf("\t Print voucher ? y/n "); scanf
("%c", &c); getchar(); if (c == 'Y' || c == 'y') { printf("\t Printing, please wait .....\n\t\t"
); for (i = 0; i < 10; i++) { printf("■"); Sleep(200); } printf("\n"); ChuCun();
printf("\t printing complete , Please keep your slip \n"); printf("\t Please press Enter Key exit \n"); getchar(); } else { printf
("\t Please press Enter Key exit \n"); getchar(); } } void savemoney()// function 2: Deposit business { int a, i; char c
; while (1) { printf("\t Please enter your deposit amount ( Whole hundred ):"); scanf("%d", &a); if (a < 0 || a % 100
!= 0) printf("\t Incorrect input , Please re-enter !\n"); else break; } getchar(); user[userID].money +=
a; printf("\t Deposit successful \n"); printf("\t Print voucher ? y/n "); scanf("%c", &c); getchar(); if
(c == 'Y' || c == 'y') { printf("\t Printing, please wait .....\n\t\t"); for (i = 0; i < 10; i++
) { printf("■"); Sleep(200); } printf("\n"); ChuCun(); printf("\t printing complete , Please keep your slip \n"
); printf("\t Please press Enter Key exit \n"); getchar(); } else { printf("\t Please press Enter Key exit \n");
getchar(); } } void showmoney()// function 3: Check the balance { printf("\t user name :%s\n", user[userID].
name); printf("\t Account balance :%.2lf\n", user[userID].money); printf("\t Please press Enter Key return \n");
getchar(); } char* get_password()// Asterisk password acquisition function ; { int i = 0; char a[50]; char ch =
'\0'; while (ch != '\r') { ch = _getch();// Receives a character from the keyboard without echo , if (ch == 8) //8 It's backspace
ASSIC code . { a[--i] = '\0'; putchar(8); putchar(' '); putchar(8); } else { if (ch
== '\r') break; a[i++] = ch; printf("*");// Output asterisk } } a[i] = '\0'; printf("\n");
return &a[0]; } void updatekey()// function 4: Password modification service { char ch[10]; char str[10]; int i;
printf("\t Please enter your initial password :"); strcpy(ch, get_password()); while (1) { if (strcmp(ch,
user[userID].key) != 0) { printf("\t Your initial password is entered incorrectly. Please re-enter it :"); strcpy(ch, get_password(
)); } else break; } while (1) { printf("\t Please enter the password you want to change :"); strcpy(ch,
get_password()); printf("\t Please enter the password you want to change again :"); strcpy(str, get_password()); if (
strcmp(ch, str) == 0) { strcpy(user[userID].key, ch); printf("\t Modifying for you , please wait a moment \n\t")
; for (i = 0; i < 10; i++) { printf("■"); Sleep(200); } ChuCun(); printf(
"\n\t Password modified successfully \n"); printf("\t Please press enter to exit \n"); getchar(); break; } else printf(
"\t Your two passwords are inconsistent , Please re-enter !\n"); } } void transfer() // function 5: transfer accounts { char a[50]; while (1)
{ printf(" Please enter the account of the transferor :"); scanf("%s", a); int flag = 0; for (int i = 1; i <=
UserNumber; i++) { if (strcmp(a, user[i].name) == 0) { flag = i; break; } } if (
flag== 0) { printf(" Payee is not in this bank or does not exist , Transfer failed \n"); while (1) { printf(
"1. Re enter account number \n2. sign out \n Please enter the number :"); int b=0; scanf("%d", &b); if (b == 2) return; else if
(b == 1) break; else printf(" Wrong number \n"); } } else if (flag == userID) { printf(
" This transfer is transferred to you by yourself , Given your mindless behavior , This transfer will be charged 2.50 RMB handling fee \n Please enter the transfer amount :"); double s=0; int x = 0; while
(1) { if (x) printf(" Sorry, your credit is running low , Please re-enter the transfer amount :"); x = 0; scanf("%lf", &s); if (user[userID
].money - 2.50 < s) x = 1; if (!x) { printf(" The transfer amount is :%.2f\n Confirm transfer y/n (n Will return to the menu )", s)
; char f[5]; scanf("%s", f); if (f[0] == 'n' || f[0] == 'N') return; user[flag].
money+= s; user[userID].money -= ( s + 2.50 ); ChuCun(); printf(" Transfer succeeded \n"); Sleep
(800); return; } } } else { printf(" Please enter the transfer amount :"); double s=0; //scanf("%lf",&s);
int x = 0; while (1) { if (x){ printf(" Sorry, your credit is running low , Re enter transfer amount y/n(n Will return to the menu )"); char ff[5];
scanf("%s",ff); if(ff[0]=='n' || ff[0]=='N') return ; else printf(" Re enter transfer amount \n");
} x = 0; scanf("%lf", &s); if (user[userID].money - 2.50 < s) x = 1; if (!x) {
printf(" The transfer amount is :%.2f\n Confirm transfer y/n (n Will return to the menu )", s); char f[5]; scanf("%s", f); if (f[0]
== 'n' || f[0] == 'N') return; user[flag].money += s; user[userID].money -= s;
ChuCun(); printf(" Transfer succeeded \n"); Sleep(800); return; } } } } } void exitsystem()
// function 6: Exit the system { system("cls"); ChuCun(); printf("\n"); printf(" Please press Enter Key exit \n");
getchar(); } int login() // Login function ; { char a[50]; char b[50]; int count = 0, i,
flag= 0; while (1) { printf("\t Please enter your user name :"); scanf("%s", a); printf("\t Please enter your password :"
); strcpy(b, get_password()); int fff = 0; for (int i = 1; i <= UserNumber; i++)
{ if (strcmp(a, user[i].name) == 0 && strcmp(b, user[i].key) == 0) { fff = 1;
userID= i; } } if (!fff) printf("\t User name or password input error ! Please re-enter !\n"); else if(user[userID].
flag==3){ printf(" The user has reported the loss , Please log in again !\n"); system("pause"); return 1; } else if(user[
userID].flag==2){ printf(" The user has been frozen , Please log in again !\n"); system("pause"); return 1; } else
{ printf("\t\t\t Logging in Please wait \n"); printf("\t\t\t"); for (i = 0; i < 8; i++) { printf
("■"); Sleep(100); // Let the system stay here 500 Running after milliseconds . } printf("\n"); break; } count++; if (
count== 3) { printf("\t\t You have entered an error more than three times , The system has exited !\n"); system("color 4a"); flag = 1;
break; } } return flag; } void wel()// Welcome interface ; { printf("\t\t\t Welcome, welcome, welcome \n"); } void
menu()// Main menu ; { printf("1. withdraw money \n"); printf("2. deposit \n"); printf("3. Check the balance \n"); printf(
"4. Change Password \n"); printf("5. transfer accounts \n"); printf("6. Exit the system \n"); } void menu1() { printf(
"1. View user information \n"); printf("2. report the loss \n"); printf("3. Report the loss \n"); printf("4. Open an account \n"); printf(
"5. Modify user password \n"); printf("6. Exit the system \n"); } void ChaXunYongHuXinXi() // Query user information { while (
1) { printf(" Please enter the account of the user you want to find :"); char s[50]; scanf("%s", s); int flag = 0; for (int
i= 1; i <= UserNumber; i++) { if (strcmp(s, user[i].name) == 0) { flag = i;
break; } } if (flag == 0) { printf(" user does not exist , Do you want to find it again y/n \n"); char f[5]; scanf("%s",
f); if (f[0] == 'n' || f[0] == 'N') return; } else if (user[flag].d == 1) {
printf(" Administrator account , No permission to view \n Do you want to find it again y/n \n"); char f[5]; scanf("%s", f); if (f[0] == 'n'
|| f[0] == 'N') return; } else { printf(" query was successful \n"); printf(" account number :%s\n", user[flag].
name); //printf(" password :%s\n", user[flag].key); printf(" deposit :%.2f\n", user[flag].money
); printf(" Account status :%d , ( 1. normal 2. frozen 3. report the loss )\n", user[flag].flag); printf(
" Press any key to return to the menu \n"); getchar(); getchar(); return; } } } void GuaShi() // report the loss { while (
1) { printf(" Please enter the account of the user to report the loss :"); char s[50]; scanf("%s", s); int flag = 0; for (int
i= 1; i <= UserNumber; i++) { if (strcmp(s, user[i].name) == 0) { flag = i;
break; } } if (flag == 0) { printf(" user does not exist , Do you want to find it again y/n \n"); char f[5]; scanf("%s",
f); if (f[0] == 'n' || f[0] == 'N') return; } else if (user[flag].d == 1) {
printf(" Administrator account , No permission to view \n Do you want to find it again y/n \n"); char f[5]; scanf("%s", f); if (f[0] == 'n'
|| f[0] == 'N') return; } else { printf(" query was successful \n"); printf(" account number :%s\n", user[flag].
name); //printf(" password :%s\n", user[flag].key); printf(" deposit :%.2f\n", user[flag].money
); printf(" Account status :%d , ( 1. normal 2. frozen 3. report the loss )\n", user[flag].flag); printf(" Whether to report the loss y/n
(n Will return to the menu )"); char f[5]; scanf("%s", f); if (f[0] == 'n' || f[0] == 'N') return;
else { user[flag].flag = 3; ChuCun(); } printf(" Successful loss reporting \n Press any key to return to the menu \n"); getchar();
getchar(); return; } } } void JieGuaShi() // Report the loss { while (1) { printf(
" Please enter the account of the user to report the loss :"); char s[50]; scanf("%s", s); int flag = 0; for (int i = 1; i
<= UserNumber; i++) { if (strcmp(s, user[i].name) == 0) { flag = i; break; } }
if (flag == 0) { printf(" user does not exist , Do you want to find it again y/n \n"); char f[5]; scanf("%s", f); if (f[
0] == 'n' || f[0] == 'N') return; } else if (user[flag].d == 1) { printf(
" Administrator account , No permission to view \n Do you want to find it again y/n \n"); char f[5]; scanf("%s", f); if (f[0] == 'n' || f[0]
== 'N') return; } else { printf(" query was successful \n"); printf(" account number :%s\n", user[flag].name);
//printf(" password :%s\n", user[flag].key); printf(" deposit :%.2f\n", user[flag].money);
printf(" Account status :%d , ( 1. normal 2. frozen 3. report the loss )\n", user[flag].flag); printf(" Whether to report the loss y/n
(n Will return to the menu )"); char f[5]; scanf("%s", f); if (f[0] == 'n' || f[0] == 'N') return;
else { user[flag].flag = 1; ChuCun(); } printf(" Successful loss reporting \n Press any key to return to the menu \n"); getchar();
getchar(); return; } } } void KaiHu() // Open an account { printf(" Account opening .....\n"); Sleep(1000);
int id = UserNumber + 1; while (1) { for (int i = 0; i < 11; i++) { user[id].
name[i] = rand()%9+1+'0'; } user[id].name[11] = '\0'; int flag = 0; for (int i =
1; i <= UserNumber; i++) { if (strcmp(user[id].name, user[i].name) == 0) { flag
= i; break; } } if (!flag)break; } printf(" Account opened successfully , Account is :%s\n", user[id].name); while
(1) { user[id].d = 2; user[id].flag = 1; user[id].money = 0.01; strcpy(user[id].
key,"111111"); char ss[50], cc[50]; while (1) { printf(" Please enter the account password :"); strcpy(ss,
get_password()); if (strlen(ss) != 6) { printf(" Password must be 6 position , Please re-enter your password \n"); memset(ss,
'\0', sizeof(char) * 50); } else { printf(" Please enter the account password again :"); strcpy(cc, get_password
()); if (strcmp(ss, cc) != 0) { printf(" The two passwords are inconsistent \n Please re-enter your password \n"); memset(ss, 0,
sizeof(ss)); memset(cc, 0, sizeof(cc)); } else { strcmp(user[id].key, ss);
UserNumber++; ChuCun(); printf(" Password set successfully \n, Account opened successfully \n Press any key to return \n"); getchar(); getchar();
return; } } } } } void XiuGaiYongHuMiMa() // Modify user password { while (1) { printf(
" Please enter the account of the user to change the password :"); char s[50]; scanf("%s", s); int flag = 0; for (int i = 1; i
<= UserNumber; i++) { if (strcmp(s, user[i].name) == 0) { flag = i; break; } }
if (flag == 0) { printf(" user does not exist , Do you want to find it again y/n \n"); char f[5]; scanf("%s", f); if (f[
0] == 'n' || f[0] == 'N') return; } else if (user[flag].d == 1) { printf(
" Administrator account , No permission to view \n Do you want to find it again y/n \n"); char f[5]; scanf("%s", f); if (f[0] == 'n' || f[0]
== 'N') return; } else { printf(" query was successful \n"); printf(" account number :%s\n", user[flag].name);
//printf(" password :%s\n", user[flag].key); printf(" deposit :%.2f\n", user[flag].money);
printf(" Account status :%d , 1. normal 2. frozen 3. report the loss \n", user[flag].flag); printf(" Modify password y/n
(n Will return to the menu )"); char f[5]; scanf("%s", f); if (f[0] == 'n' || f[0] == 'N') return;
else { char ss[50],cc[50]; while (1) { printf(" Please enter the new account password :"); strcpy(ss,
get_password()); if (strlen(ss) != 6) { printf(" Password must be 6 position , Please re-enter your new password \n"); memset(ss,
'\0', sizeof(char) * 50); } else { printf(" Please enter the new account password again :"); strcpy(cc,
get_password()); if (strcmp(ss, cc) != 0) { printf(" The two passwords are inconsistent , Password change failed \n Please re-enter your password \n");
memset(ss,0,sizeof(ss)); memset(cc,0,sizeof(cc)); } else { strcpy(user[flag].key
,ss); ChuCun(); printf(" Password modified successfully , Press any key to return \n"); getchar(); getchar(); return; } } } }
} } } void init() { UserNumber = 1; strcpy(user[1].name,"11111111111"); strcpy(
user[1].key,"123456"); user[1].money = 0.01; user[1].flag = 1; user[1].d = 1;
ChuCun(); return; } int main() { /* init(); return 0;*/// These two sections run once first , Comment out after running once .
srand((int)time(0)); TiQu();// Load user information system("color f"); while(1) { system("cls")
; for (int i = 1; i <= UserNumber; i++) { printf("-%s-%s-%.2f-%d-%d-\n", user[i]
.name, user[i].key, user[i].money, user[i].flag, user[i].d); } wel(); printf(
"\t\t\t Confirm login ?Y/N "); char c; scanf("%c", &c); getchar(); if (c == 'n' || c == 'N'
) { exitsystem(); break; } else { int f; system("cls"); // Clear screen printf(
"\t\t\t Entering , please wait a moment .......\n\n"); Sleep(800); printf("
*******************************\n"); printf(" * Welcome ATM Counter machine *\n"); f = login();
system("cls"); if (f == 1) { printf(" Exiting system ...."); Sleep(3000); exitsystem(); }
else { if (user[userID].d == 2) { while (1) { menu(); // menu printf("\n\t Please enter code :");
int m; scanf("%d", &m); getchar(); if (m == 1) { Sleep(500); drawmoney(); system
("cls"); } else if (m == 2) { Sleep(500); savemoney(); system("cls"); } else if
(m == 3) { Sleep(500); showmoney(); system("cls"); } else if (m == 4) { Sleep(
500); updatekey(); system("cls"); } else if (m == 5) { Sleep(500); transfer();
system("cls"); } else if (m == 6) { exitsystem(); break; } } } else if (user[
userID].d == 1) { while (1) { menu1(); // menu printf("\n\t Please enter code :"); int m; scanf(
"%d", &m); getchar(); if (m == 1) { Sleep(500); ChaXunYongHuXinXi(); system(
"cls"); } else if (m == 2) { Sleep(500); GuaShi(); system("cls"); } else if (m
== 3) { Sleep(500); JieGuaShi(); system("cls"); } else if (m == 4) { Sleep(500);
KaiHu(); system("cls"); } else if (m == 5) { Sleep(500); XiuGaiYongHuMiMa();
system("cls"); } else if (m == 6) { exitsystem(); break; } } } } } ChuCun(); }
return 0; }
Technology