|
|
#include<stdio.h>
|
|
|
#include<stdlib.h>
|
|
|
#include<string.h>
|
|
|
#include<conio.h>
|
|
|
#define BUFFERSIZE 1024
|
|
|
#define MAXACCOUNT 1000
|
|
|
#define ADMINISTRATIOR 123456
|
|
|
|
|
|
int main(void)
|
|
|
{
|
|
|
FILE *fp;
|
|
|
int accountnum;
|
|
|
int i;
|
|
|
float withdraw, store;
|
|
|
|
|
|
do
|
|
|
{
|
|
|
system("cls"); //清屏
|
|
|
puts("********************************************");
|
|
|
puts("可选操作: ");
|
|
|
puts("1 : 创建新账户 ");
|
|
|
puts("2 : 管理员权限 ");
|
|
|
puts("3 : 查询账户 ");
|
|
|
puts("4 : 注销账户 ");
|
|
|
puts("5 : 存取款 ");
|
|
|
puts("6 : 结束使用 ");
|
|
|
puts("********************************************");
|
|
|
printf("请选择功能:");
|
|
|
scanf("%d",&i);
|
|
|
system("cls"); //清屏
|
|
|
if (i < 7 && 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;
|
|
|
}
|