fffunctions

master
m59637281 6 years ago
parent f08599eaf1
commit 21cf0f25ae

@ -1,4 +1,4 @@
typedef struct bankaccount//定义账户格式模块函数
typedef struct bankaccount//定义账户格式
{
int account;
int key;

@ -1,14 +1,29 @@
void del_account(FILE *fp,int accountnum)//删除账号信息模块
void del_account(FILE *fp,int accountnum)
{
int i;
if(search_account(fp,accountnum)==0)
printf("无法找到此账户!\n");
int i, key;
if(search_account(fp,accountnum,1)==0)
printf("无法找到此账户!\n");
else
{
for(i = 0;i<cur_account-1;i++)
if(accountcollection[i].account != accountnum)
fprintf(fp,"%d %d %s %.2f\n",
accountcollection[i].account,accountcollection[i].key,accountcollection[i].name,accountcollection[i].balance);
printf("删除成功!\n");
i = search_account(fp,accountnum,0) - 1;
printf("请输入密码\n");
scanf("%d",&key);
while (!search_key(fp, key, i) && key != 0)
{
system("cls");
printf("您输入的密码有误!\n请重新输入或输入0放弃删除\n");
scanf("%d", &key);
}
system("cls");
if (key)
{
for(i = 0;i<cur_account-1;i++)
if(accountcollection[i].account != accountnum)
fprintf(fp,"%d %d %s %.2f\n",
accountcollection[i].account,accountcollection[i].key,accountcollection[i].name,accountcollection[i].balance);
printf("注销成功!\n");
}
else
printf("注销失败!\n");
}
}

@ -1,4 +1,4 @@
void get_account(FILE *fp)//搜索账号信息模块函数
void get_account(FILE *fp)//查询账号信息
{
int accountnum;
int key;

@ -1,16 +1,35 @@
void insert_account(FILE *fp)//新建账户模块函数
void insert_account(FILE *fp, int accountnum)//新建账户
{
BANKACCOUNT newaccount;
newaccount.account = accountnum;
int subkey;
printf("请输入账号信息\n");
printf(">>账号:");
scanf("%d",&(newaccount.account));
printf(">>密码:");
printf(">>您的账号:");
printf("%d\n", accountnum);
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);
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("创建失败!");
}

@ -1,4 +1,4 @@
void list_account(FILE *fp)//列出所有账号信息模块函数
void list_account(FILE *fp)
{
int i =0;
printf("合计%d个账号:\n",cur_account-1);// cur_account减去多加的1
@ -10,3 +10,10 @@ void list_account(FILE *fp)//
printf("余额:%.2f\n",accountcollection[i].balance);
}
}
int search_key(FILE *fp,int key,int i)
{
if (accountcollection[i].key == key)
return 1;
else
return 0;
}

@ -1,16 +1,19 @@
int search_account(FILE *fp,int accountnum)//管理员调用模块函数
int search_account(FILE *fp,int accountnum,int flag)
{
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);
if(flag == 1)
{
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 i + 1;
}
}
return 0;

@ -0,0 +1,7 @@
int search_key(FILE *fp,int key,int i)
{
if (accountcollection[i].key == key)
return 1;
else
return 0;
}

@ -0,0 +1,7 @@
void store_account(FILE*fp)
{
int i = 0;
for(i = 0;i<cur_account-1;i++)
fprintf(fp,"%d %d %s %.2f\n",
accountcollection[i].account,accountcollection[i].key,accountcollection[i].name,accountcollection[i].balance);
}
Loading…
Cancel
Save