commit c38cefc722e739dcf46674726ea3e28fa21a7e27 Author: Von L鈥楬ospital <44203525+2456178759@users.noreply.github.com> Date: Mon Jan 14 19:40:01 2019 +0800 final diff --git a/account.txt b/account.txt new file mode 100644 index 0000000..2213ce2 --- /dev/null +++ b/account.txt @@ -0,0 +1 @@ +132 12 123 123.00 diff --git a/banktest.c b/banktest.c new file mode 100644 index 0000000..e77c5f1 --- /dev/null +++ b/banktest.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/banktest.exe b/banktest.exe new file mode 100644 index 0000000..677612f Binary files /dev/null and b/banktest.exe differ diff --git a/banktest.o b/banktest.o new file mode 100644 index 0000000..81ce31a Binary files /dev/null and b/banktest.o differ