6、银行账户信息管理
问题描述:
已知一银行有 5 个客户(客户信息为:编号、客户姓名、客户地址、客户电话、账户总金额(最
开始为 0))。设计一程序,完成以下功能。
1) 存款:输入客户编号、存款金额、存款日期,完成存款功能,需要判断客户编号是否存在,
存款金额是否大于 0,存款日期格式是否合法(格式为:YYYY-MM-DD,如 2009-01-02))。
2) 取款:输入客户编号、存款金额、取款日期,完成取款功能,需要判断客户编号是否存在,
取款金额是否大于 0,取款金额是否小于客户的账户总金额,取款日期格式是否合法(格
式为:YYYY-MM-DD,如 2009-01-02))。
3) 查询指定客户的余额
4) 查询指定客户的存款记录
5) 查询指定客户的取款记录
提示:
l 定义一个日期结构体保存日期,具体信息为:年、月、日
l 判断存款日期和取款日期的格式是否合法时,需要判断长度是否为 10,第 5 位和第 8 位是
否为’-’,字符,将 1-4 位表示的年份,6-7 位表示的月份,9-10 位表示的日期分别转换
成整数。判断是否满足构成日期的条件闰年月份只能是 1-12 之间的数,如果是闰年,二月
可以是 29 天否则不能大于 28,1,3,5,7,8,10,12 月可以是 31 天,其余只能小于等
于 30(建议写成函数)。
l 定义个长度为 5 的结构体数组保存客户信息,具体为:编号、客户姓名、客户地址、客户
电话、账户总金额。最开始为账户总金额 0。
l 定义一个链表保存客户的存、取款记录,具体信息为:编号、日期、操作类别、金额。可
以设计操作类别为 1 表示存款,-1 表示为取款,每次输入存款信息时,将存款金额累加到
账户总金额,每次取款时,从账户总金额减去取款金额
各位好心人,希望能在周五10点前给我,不然我要挂科了!!!
我编的程序,指针不对!!!交不了,要重修啊!!!
重修伤不起啊!!!
C语言编银行信息管理系统
答案:2 悬赏:50
解决时间 2021-03-15 04:00
- 提问者网友:余味
- 2021-03-14 17:57
最佳答案
- 二级知识专家网友:猖狂的痴情人
- 2021-03-14 18:06
请将我采纳为最佳答案后联系我,谢谢!
全部回答
- 1楼网友:单身小柠`猫♡
- 2021-03-14 19:29
#include
#include
#include
#include
char cfile[] = "date.txt";
struct bank
{
char id[10+1];
char psw[6+1];
double money;
};
welcome1()
{
printf("\n\n\t\t欢迎使用虚拟银行自动取款机服务!\t\t\n\n");
printf("请选择功能:\n");
printf("\n=================================================\n");
printf(" || 请输入序号 ||\n");
printf(" || 1.新用户开户。 ||\n");
printf(" || 2.老用户登陆。 ||\n");
printf(" || 3.退出系统。 ||\n");
printf("=================================================\n");
}
welcome2()
{
printf("\n\n\t\t注册须知\n\n");
printf("**************************************************\n");
printf("* 1.请填写您的真实资料! *\n");
printf("* 2.开户首期必须存入100元以上 *\n");
printf("**************************************************\n");
}
welcome3()
{
printf("\n\n\t\t\3 欢迎进入虚拟银行系统 \3\n\n");
printf("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n");
printf("\1\1\t 请选择功能:1.取款(最多透资2000); \1\1\n");
printf("\1\1\t 2.存款; \1\1\n");
printf("\1\1\t 3.查询余额; \1\1\n");
printf("\1\1\t 4.修改密码; \1\1\n");
printf("\1\1\t 5.返回主页面; \1\1\n");
printf("\1\1\t 任意键退出. \1\1\n");
printf("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n");
}
int search(char* user, char* pwd, char* real_pwd)
{
file* file;
char user_buff[256], pwd_buff[256];
file = fopen(cfile, "r");
if (!file) return 0;
while (!feof(file))
{
if (fscanf(file, "%s%s\n", user_buff, pwd_buff) == eof) return 0;
if (!strcmp(user_buff, user))
{
if (real_pwd) strcpy(real_pwd, pwd_buff);
return 1;
}
}
fclose(file);
return 0;
}
int add(char* user, char* pwd, double coin_n)
{
file* file;
file = fopen(cfile, "a");
if (!file) return 0;
fprintf(file, "%s %s %.2lf\n", user, pwd, coin_n);
fclose(file);
return 0;
}
int wenjian(char* user, char* pwd,double coin)
{
if (search(user, pwd, null)) return 0;
else add(user, pwd, coin);
return 1;
}
zhuce()
{
struct bank *p;
int i=0,k=0,judge1,judge2;
char name[30];
char sex,ch;
char sh[18];
int n;
p=(struct bank*)malloc(sizeof(struct bank));
welcome2();
printf("请输入您的名字(纯英文):");
gets(name);
printf("请输入您的性别(男:1 女2):");
fflush(stdin);
scanf("%c",&sex);
fflush(stdin);
printf("请输入您的身份证号码:");
gets(sh);
for(n=0;n='0'&&name[n]<='9')
{
printf("您输入的名字有误!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
}
if(sex!='1'&&sex!='2')
{
printf("您输入的性别不对!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
if(strlen(sh)!=18)
{
printf("您输入的身份证号码不全!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
for(n=0;n57)
{
printf("您输入的身份证号码非法!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
else
{
if(sh[18]!='x'&&sh[18]<48&&sh[18]>57)
{
printf("您输入的身份证号码非法!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
}
}
printf("请输入您的帐号(10位纯数字):\n");
fflush(stdin);
scanf("%s",p->id);
fflush(stdin);
while(i id))
{
if((p->id[i] < 48) || (p->id[i] > 57))
{
judge1=0;
}
i++;
}
while(strlen(p->id)!=10 ||judge1==0)
{
printf("您输入的帐号不正确,必须为10位纯数字!");
printf("请重新输入(10位纯数字):");
fflush(stdin);
scanf("%s",p->id);
fflush(stdin);
}
printf("请输入您的密码(6位纯数字):\n");
fflush(stdin);
scanf("%s",p->psw);
fflush(stdin);
while(k psw))
{
if((p->psw[k] < 48) || (p->psw[k] > 57))
{
judge2=0;
}
k++;
}
while(strlen(p->psw)!=6 ||judge2==0)
{
printf("您输入不正确!密码必须为6位纯数字!\n");
printf("请重新输入密码(6位纯数字):");
fflush(stdin);
scanf("%s",p->psw);
fflush(stdin);
}
printf("请输入您的首期存款:");
fflush(stdin);
scanf("%lf",&p->money);
fflush(stdin);
while((p->money)<100)
{
printf("您必须存入100元以上,请重新输入:");
fflush(stdin);
scanf("%lf",&p->money);
fflush(stdin);
}
if (wenjian(p->id,p->psw,p->money))
{
system("cls");
printf("注册成功!");
printf("您的注册信息如下,请牢记:\n");
printf("名字:");
puts(name);
printf("性别代码:%c\n",sex);
printf("身份证号码:");
puts(sh);
printf("帐号:");
puts(p->id);
printf("密码:");
puts(p->psw);
printf("您帐户里的余额为:%.2lf\n",p->money);
printf("请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
else
{
system("cls");
printf("您输入的帐号已经存在!注册失败!\n");
printf("请选择:按1返回主页面. 按任意键退出:");
scanf("%c",&ch);
if(ch=='1'){system("cls");main();}
else exit(0);
}
}
gongneng(char account[10+1],char password[6+1],double money)
{
file *ps;
struct bank xin[1000];
int k=0,b=0;
char mima[6+1],chiose,x;
char count[10+1],word[6+1];
double inmoney,outmoney,addmoney;
welcome3();
fflush(stdin);
scanf("%c",&chiose);
fflush(stdin);
ps=fopen(cfile,"r");
if (!ps)
{
printf("不能打开文件!按任意键退出!");
fflush(stdin);
scanf("%c",&x);
fflush(stdin);
exit(0);
}
if(chiose=='1')
{
printf("输入您的取款金额:");
fflush(stdin);
scanf("%lf",&outmoney);
fflush(stdin);
while(!feof(ps))
{
fscanf(ps, "%s %s %lf",&xin[k].id,&xin[k].psw,&xin[k].money);
k++;
}
fclose(ps);
ps=fopen(cfile,"wb");
if (!ps)
{
printf("不能打开文件!按任意键退出!");
fflush(stdin);
scanf("%c",&x);
fflush(stdin);
exit(0);
}
while(!feof(ps))
{
//printf("%s %s %.2lf\n",xin[b].id,xin[b].psw,xin[b].money);
if ((strcmp(account, xin[b].id)==0)&&(strcmp(password, xin[b].psw)==0))
{
xin[b].money=xin[b].money-outmoney;
}
printf("%.2lf\n",xin[b].money);
fprintf(ps, "%s %s %.2lf\n", xin[b].id, xin[b].psw, xin[b].money);
b++;
}
}
}
denglu()
{
file *fp;
char account[10+ 1],password[6 + 1],h;
int m=0;
char real_account[10+ 1];
char real_password[6 + 1];
double real_money_o=0.0;
printf("请输入您的帐号(10位纯数字):");
gets(account);
printf("请输入您的密码(6位纯数字):");
gets(password);
fp = fopen(cfile, "r");
if (!fp)
{
printf("不能打开文件!按任意键退出!");
fflush(stdin);
scanf("%c",&h);
fflush(stdin);
exit(0);
}
while (m<=2)
{
while(fscanf(fp, "%s %s %lf", &real_account, &real_password,&real_money_o) != eof)
{
if ((strcmp(real_account, account)==0)&&(strcmp(real_password, password)==0))
{
system("cls");
printf("登陆成功!");
gongneng(real_account,real_password,real_money_o);
fclose(fp);
return 0;
}
}
rewind(fp);
printf("您输入的帐号不存在或密码不正确!\n请重新输入:\n");
m++;
printf("请输入您的帐号(10位纯数字):");
fflush(stdin);
gets(account);
fflush(stdin);
printf("请输入您的密码(6位纯数字):");
fflush(stdin);
gets(password);
fflush(stdin);
}
fclose(fp);
printf("您输入帐号密码不正确已经3次,您被强制退出系统(按任意键退出)!");
fflush(stdin);
scanf("%c",&h);
fflush(stdin);
exit(0);
}
int main()
{
char chiose;
welcome1();
scanf("%c",&chiose);
getchar();
if(chiose <='0' ||chiose>='4')
{
while(chiose <='0' || chiose>='4')
{
printf("您的输入有误,请重新输入:");
scanf("%c",&chiose);
getchar();
}
}
if(chiose=='1')
{
system("cls");
zhuce();
}
if(chiose=='2')
{
system("cls");
denglu();
}
if(chiose=='3')
{
printf("谢谢您的使用!");
exit(0);
}
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯