diff --git a/account.txt b/account.txt new file mode 100644 index 0000000..0545106 --- /dev/null +++ b/account.txt @@ -0,0 +1 @@ +123456 456456 zm 12.56 \ No newline at end of file diff --git a/bankstandard.c b/bankstandard.c new file mode 100644 index 0000000..e77c5f1 --- /dev/null +++ b/bankstandard.c @@ -0,0 +1,375 @@ +#include +#include +#include +#include +#define BUFFERSIZE 1024 +#define MAXACCOUNT 1000 +#define ADMINISTRATIOR 123456 + +typedef struct bankaccount//定义账户格式 +{ + int account; + int key; + char name[32]; + float balance; +}BANKACCOUNT; +BANKACCOUNT accountcollection[MAXACCOUNT]; +int cur_account = 0; + + +void insert_account(FILE *fp, int accountnum)//新建账户 +{ + BANKACCOUNT newaccount; + newaccount.account = accountnum; + int subkey; + + printf("请输入账号信息\n"); + printf(">>您的账号为:"); + printf("%d\n", accountnum); + printf(">>请您输入密码:"); + scanf("%d",&(newaccount.key)); + system("cls"); + printf("请您再次输入刚才的密码:\n"); + do{ + scanf("%d", &subkey); + getchar(); + if (subkey == newaccount.key) + break; + else + printf("两次的密码不一样!\n请再次输入第一次的密码或输入0退出注册\n"); + }while (subkey != 0); + if (subkey != 0) + { + printf("密码设置成功!\n 请您完善个人信息\n"); + printf(">>姓名:"); + scanf("%s",newaccount.name); + printf(">>请您输入初始余额:"); + scanf("%f",&(newaccount.balance)); + fseek(fp,0L,SEEK_END); + fprintf(fp,"%d %d %s %.2f\n",newaccount.account,newaccount.key,newaccount.name,newaccount.balance); + printf("账户创建成功!\n"); + } + else + printf("创建失败!"); +} +void store_account(FILE*fp) +{ + int i = 0; + for(i = 0;i 0) + { + switch(i) + { + case 1: + if(!(fp = fopen("account.txt","a+"))) + { + printf("打开账户文件失败!\n"); + exit(0); + } + printf("请您输入初始账户:\n"); + scanf("%d", &accountnum); + while (search_account(fp,accountnum,0) && accountnum != 0) + { + printf("该账户号已被占用!\n您可以继续输入账户号或连续输入两次0结束创建。\n"); + scanf("%d\n", &accountnum); + } + if(accountnum != 0) + insert_account(fp, accountnum); + else + printf("创建失败!\n"); + printf("点击回车返回主菜单!\n感谢您的使用!"); + getch(); + fclose(fp); + break; + + case 2: + if(!(fp = fopen("account.txt","r"))) + { + printf("该系统暂无用户信息!\n"); + exit(0); + } + printf("请输入管理员密码:\n"); + long int n; + scanf("%ld", &n); + while (n != ADMINISTRATIOR) + { + printf("请输入正确的密码或输入0返回上一层:\n"); + scanf("%ld", &n); + if (n == 0) + break; + } + if (n != 0) + { + + get_account(fp); + list_account(fp); + fclose(fp); + printf("点击回车结束本次操作!\n感谢您的使用!\n"); + getch(); + } + break; + + case 3: + printf("请输入账号:\n"); + scanf("%d",&accountnum); + if(!(fp = fopen("account.txt","r"))) + { + printf("打开账户文件失败!\n"); + exit(0); + } + get_account(fp); + if(!search_account(fp,accountnum,1)) + printf("此账户不存在:%d\n",accountnum); + fclose(fp); + printf("点击回车结束本次操作!\n感谢您的使用!"); + getch(); + break; + + case 4: + printf("请输入账号:\n"); + scanf("%d",&accountnum); + if(!(fp = fopen("account.txt","r"))) + { + printf("打开账户文件失败!\n"); + exit(0); + } + get_account(fp); + fclose(fp); + if(!(fp = fopen("account.txt","w+"))) + { + printf("打开账户文件失败!\n"); + exit(0); + } + del_account(fp,accountnum); + fclose(fp); + printf("点击回车结束本次操作!\n感谢您的使用!"); + getch(); + break; + + case 5: + printf("请输入账号\n"); + scanf("%d",&accountnum); + if(!(fp = fopen("account.txt","r"))) + { + printf("打开账户文件失败!\n"); + exit(0); + } + get_account(fp); + fclose(fp); + if(!(fp = fopen("account.txt","w+"))) + { + printf("打开账户文件失败!\n"); + exit(0); + } + if(search_account(fp,accountnum,0)) + { + int i = search_account(fp,accountnum, 0) - 1; + int key; + do{ + printf("请输入正确的密码或输入0退出该功能项:"); + scanf("%d", &key); + system("cls"); + if(search_key(fp, key, i)) + break; + }while ( key != 0); + while (key != 0) + { + system("cls"); + printf("********************************************\n"); + printf("请输入开头的数字选择您要进行的操作\n"); + printf("0 :退出选择\n"); + printf("1 :取款\n"); + printf("2 :存款\n"); + printf("********************************************\n"); + scanf("%d", &key); + system("cls"); + if (key >= 0&&key <=2) + { + switch(key) + { + case 1: + printf("请您输入您要取出的金额:"); + scanf("%f", &withdraw); + if(accountcollection[i].balance > withdraw) + { + accountcollection[i].balance -= withdraw; + printf("\n您现在的余额为 %.2f¥\n", accountcollection[i].balance); + } + else + printf("您的余额不足\n"); + printf("点击回车继续操作\n"); + getch(); + break; + + + case 2: + printf("请您输入您要存入的金额:"); + scanf("%f", &store); + accountcollection[i].balance += store; + printf("\n您现在的余额为 %.2f¥\n", accountcollection[i].balance); + printf("点击回车继续操作\n"); + getch(); + break; + + + default : + printf("感谢使用\n"); + break; + } + } + else + { + printf("无效指令,请输入1 —2中的任意一个整数.\n"); + printf("点击回车继续操作\n"); + getch(); + } + } + } + else + printf("账户不存在\n"); + store_account(fp); + fclose(fp); + printf("点击回车继续操作\n"); + getch(); + break; + + + default: + printf("感谢您的使用!\n"); + break; + } + } + else + { + printf("无效指令,请输入1 —6中的任意一个整数.\n"); + printf("点击回车继续操作\n"); + getch(); + } + +}while(i != 6); + + return 0; +} + diff --git a/bankstandard.exe b/bankstandard.exe new file mode 100644 index 0000000..c28c52c Binary files /dev/null and b/bankstandard.exe differ diff --git a/bankstandard.o b/bankstandard.o new file mode 100644 index 0000000..00f09c5 Binary files /dev/null and b/bankstandard.o differ diff --git a/define_struct.c b/define_struct.c new file mode 100644 index 0000000..a289aa8 --- /dev/null +++ b/define_struct.c @@ -0,0 +1,9 @@ +typedef struct bankaccount//定义账户格式 +{ + int account; + int key; + char name[32]; + float balance; +}BANKACCOUNT; +BANKACCOUNT accountcollection[MAXACCOUNT]; +int cur_account = 0; diff --git a/del_account.c b/del_account.c new file mode 100644 index 0000000..774aa15 --- /dev/null +++ b/del_account.c @@ -0,0 +1,14 @@ +void del_account(FILE *fp,int accountnum)//删除账号信息模块 +{ + int i; + if(search_account(fp,accountnum)==0) + printf("无法找到此账户!\n"); + else + { + for(i = 0;i>账号:"); + scanf("%d",&(newaccount.account)); + printf(">>密码:"); + scanf("%d",&(newaccount.key)); + printf(">>姓名:"); + scanf("%s",newaccount.name); + printf(">>余额:"); + scanf("%f",&(newaccount.balance)); + fseek(fp,0L,SEEK_END); + fprintf(fp,"%d %d %s %.2f\n",newaccount.account,newaccount.key,newaccount.name,newaccount.balance); +} diff --git a/list_account.c b/list_account.c new file mode 100644 index 0000000..4a43e49 --- /dev/null +++ b/list_account.c @@ -0,0 +1,12 @@ +void list_account(FILE *fp)//列出所有账号信息模块函数 +{ + int i =0; + printf("合计%d个账号:\n",cur_account-1);// cur_account减去多加的1 + for(i = 0;i< cur_account-1;i++) + { + printf("账户:%d:\n",i+1); + printf("账号:%d\n",accountcollection[i].account); + printf("姓名:%s\n",accountcollection[i].name); + printf("余额:%.2f\n",accountcollection[i].balance); + } +} diff --git a/search_account.c b/search_account.c new file mode 100644 index 0000000..185596f --- /dev/null +++ b/search_account.c @@ -0,0 +1,17 @@ +int search_account(FILE *fp,int accountnum)//管理员调用模块函数 +{ + int i =0; + for(i = 0;i< cur_account-1;i++) + { + if(accountcollection[i].account == accountnum) + { + printf("账户:%d:\n",i+1); + printf("账号:%d\n",accountcollection[i].account); + printf("姓名:%s\n",accountcollection[i].name); + printf("余额:%.2f\n",accountcollection[i].balance); + + return 1; + } + } + return 0; +} diff --git a/search_key.c b/search_key.c new file mode 100644 index 0000000..2a489e2 --- /dev/null +++ b/search_key.c @@ -0,0 +1,7 @@ +int search_key(FILE *fp,int key,int i) +{ + if (accountcollection[i].key == key) + return 1; + else + return 0; +} diff --git a/store_account.c b/store_account.c new file mode 100644 index 0000000..2868153 --- /dev/null +++ b/store_account.c @@ -0,0 +1,7 @@ +void store_account(FILE*fp) +{ + int i = 0; + for(i = 0;i