c语言课程设计取款机程序(带文件的)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
/* Note:Your choice is C IDE */
#include "stdio.h"
#include "graphics.h"
#include "string.h"
#define REN 2
struct yonghu
{char kahao[10];
char mima[8];
long yue;
}yh[REN];
int i,k,h,m,a;
FILE *fp;
main()
{
void guanliyuanyanzheng();
void guanliyuancaozuo();
void kahaoyanzheng();
void mimayanzheng();
void qukuan();
void zhuanzhang();
void xiugaimima(); /*函数的声明*/
/*##################提供以管理员身份进入,将信息的输入程序与该程序合并。避免繁琐####################*/
printf("please choose the identify to enter\n");
printf("1): administrator\n\n");
printf("2): user\n");
printf("1 or 2 ?\n");
scanf("%d",&a);
clrscr();
if(a==1)
{
guanliyuanyanzheng();
guanliyuancaozuo();
}
kahaoyanzheng();
mimayanzheng();
/*#########################################卡号,密码都正确以后进行业务操作######################################*/
if(i!=3)
{
clrscr();
while(1) /*功能列表*/
{
printf("1). take money\n\n\n");
printf("2). see how much money the card has\n\n\n");
printf("3). change the password\n\n\n");
printf("4).give money to other card\n\n\n");
printf("5). take back the card\n\n\n");
printf("please enter the number of these functions:");
scanf("%d",&a);
while(a>5||a<1) /*限制非法输入*/
{
printf("you enter the wrong mumber! please enter again:\n");
scanf("%d",&a);
clrscr();
}
clrscr();
switch(a) /*#######################使用switch转换语句,进行业务选择#############################*/
{
case 1: qukuan();
break;
case 2: printf("doing with the application,please wait for a minute......\n\n\n");
printf("your card has %ld yuan\n\n\n",yh[k].yue);
clrscr();
break;
case 3: xiugaimima();
break;
case 4: zhuanzhang();
break;
case 5: goto end;
}
printf("press 1 to return , press 2 to take card away:"); /*提示用户继续还是 退卡*/
scanf("%d",&m);
clrscr();
if(m==2)
goto end;
}
}
else
printf("sorry!your card had been closed!\n\nplease go to the bank nearby to open it...\n\n\n"); /*密码三次输入不正确,卡被锁死,无法使用,需要到附近银行开通*/
end:printf("please take your card back...\n\n");
}
void guanliyuanyanzheng()
{ long key;
printf("please enter the administrator's password:");
scanf("%ld",&key);
clrscr();
i=0;
while(key!=520658)
{
printf("the password you entered is wrong,\n\n\n please entered new:");
i++;
if(i==3)
{ printf("because of the three times wrong password enter\n\n\n,you are forced to out!!!");
printf("press anykey to out...");
getch();
clrscr();
exit(0);
}
scanf("%ld",&key);
clrscr();
}
}
void guanliyuancaozuo()
{
clrscr();
for(i=0;i
printf("please input number %d user' informations:\n\n\n\n",i+1);
printf("please input card number:\n\n");
scanf("%s",yh[i].kahao);
printf("please input password:\n\n");
scanf("%s",yh[i].mima);
printf("please input the money:\n\n");
scanf("%ld",&yh[i].yue);
clrscr();
}
printf("dear administrator: please enter the user's informations:\n");
if((fp=fopen("yonghu.dat","wb"))==NULL) /* 打开文件*/
{
printf("cannot open file\n");
return;
}
for(i=0;i
if(fwrite(&yh[i],sizeof(struct yonghu),1,fp)!=1)
printf("file write error\n");
}
fclose(fp);
printf("congratulations! write to file successly!\n\n");
printf("press any key to continue...");
getch();
clrscr();
}
void kahaoyanzheng()
{ char kahao[10];
if((fp=fopen("yonghu.dat","rb"))==NULL)
{printf("cannot open file\n");
return; /*文件打开失败 就返回 结束*/
}
for(i=0;i
fclose(fp); /*关闭文件*/
printf("please input card number:");
scanf("%s",kahao);
clrscr();
for(i=0;i
if(strcmp(kahao,yh[i].kahao)==0)
{ k=i;
break;
}
if(i==REN-1)
{printf("sorry,the card number you entered is not registered!!!\n\n\n");
printf("press anykey to exit...");
getch(); /*敲击键盘继续,目的是看到上一个printf的内容*/
clrscr();
exit(0);
}
}
}
void mimayanzheng()
{ char mima[8];
printf("please input the password:");
scanf("%s",mima);
clrscr();
i=1;
while(strcmp(mima,yh[k].mima)!=0&&i<=2) /* 密码验证*/
{
printf("the password is wrong,please enter new:\n");
scanf("%s",mima);
clrscr();
i++;
}
}
void qukuan()
{ int a,q;
printf("how money do you want to take ?\n\n\n"); /*列出需要取的钱数*/
printf(" 1) 100\n\n\n 2) 200\n\n\n 3) 400\n\n\n 4) 500\n\n\n");
printf(" 5) other money\n");
printf("please enter the number represent money (1 to 5 ?):");
scanf("%d",&a);
clrscr();
while(a>5||a<1) /*限制非法输入*/
{ printf("you enter the wrong mumber! please enter again:\n\n");
scanf("%d",&a);
clrscr();
}
switch(a) /*使用switch语句,进行相关操作*/
{ case 1: printf("doing with the application,please wait for a minute......\n\n\n");
yh[k].yue=yh[k].yue-100;break;
case 2: printf("doing with the application,please wait for a minute......\n\n\n");
yh[k].yue=yh[k].yue-200;break;
case 3: printf("doing with the application,please wait for a minute......\n\n\n");
yh[k].yue=yh[k].yue-400;break;
case 4: printf("doing with the application,please wait for a minute......\n\n\n");
yh[k].yue=yh[k].yue-500;break;
case 5: printf("please enter the how money do you want ?\n");
scanf("%d",&q);
while(1) /*对取的钱数进行限制,必须时整百 而且 一次取款小于5000*/
{ if(q%100==0&&q<=5000&&q<=yh[k].yue)
{ printf("doing with the application,please wait for a minute......\n\n\n");
yh[k].yue=yh[k].yue-q;
break;
}
else
{ printf("doing with the application,please wait for a minute......\n\n\n");
printf("failed! sorry,please enter the money again:\n\n\n");
scanf("%d",&q);
clrscr();
}
}
}
if((fp=fopen("yonghu.dat","wb"))==NULL) /*操作完成后立即将信息写入文件,避免损失*/
{
printf("cannot open file\n");
return;
}
for(i=0;i
if(fwrite(&yh[i],sizeof(struct yonghu),1,fp)!=1)
printf("file write error\n");
}
fclose(fp);
printf("success!please take away your money in 30 seconds...\n\n\n"); /*写入成功后方可拿到钱*/
getch(); /*敲击键盘继续,目的是看到上一个p
rintf的内容*/
clrscr();
}
void zhuanzhang()
{ long money;
char kahao[10],kahao2[10];
printf("please enter card number:\n");
r: scanf("%s",kahao);
clrscr();
for(i=0;i
if(strcmp(kahao,yh[i].kahao)==0)
{ h=i;
break;
}
if(i==REN-1)
{
printf("sorry,the card number you entered is not been registered!!!\n\n");
printf("please enter the card number new:\n");
scanf("%s",kahao);
i=0; /*此处让变量i值复原,再次执行循环*/
}
}
printf("please enter the card number again:\n");
scanf("%s",kahao2);
clrscr();
if(strcmp(kahao2,kahao)!=0) /*检查两次输入的卡号是否一致,不一致重新输入*/
{
printf("two times entered the different card number!\n\n please enter the card number new:\n");
goto r;
}
printf("please enter the money you want to give:\n");
scanf("%ld",&money);
clrscr();
while(1) /*当输入的钱数为整百并且小于2万时,方可通过.否则由else 返回重新输入*/
{
if(money<=20000&&money<=yh[k].yue)
{
printf("you want to give %d yuan ?\n(1) yes (2) no\n",money); /*等待用户确认*/
printf("please enter 1 or 2 ?\n");
scanf("%d",&m);
clrscr();
if(m==2) /*回答no时,返回重新输入*/
{
printf("please enter card number new:\n");
goto r;
}
printf("doing with the application,please wait for a minute......\n\n\n");
yh[k].yue=yh[k].yue-money; /*让卡上的钱数相应的减少与增加*/
yh[h].yue=yh[h].yue+money;
if((fp=fopen("yonghu.dat","wb"))==NULL) /* 立即写入文件*/
{
printf("cannot open file\n");
return;
}
for(i=0;i
if(fwrite(&yh[i],sizeof(struct yonghu),1,fp)!=1)
printf("file write error\n");
}
fclose(fp);
printf("success!\n"); /*写入成功,提示success!*/
getch();
clrscr();
break;
}
else
{
printf("failed! sorry,please e
nter the money again:\n");
scanf("%ld",&money);
}
}
}
void xiugaimima()
{ char mima[8],mima2[8];
printf("please enter new password:");
shuru: scanf("%s",mima);
clrscr();
while(strlen(mima)!=6) /*限制密码长度,只允许6位密码*/
{
printf("the password you entered is not right,please enter new: ");
scanf("%s",mima);
clrscr();
}
printf("please enter the password again;");
scanf("%s",mima2);
clrscr();
if(strcmp(mima,mima2)!=0) /*检查两次输入的密码是否一致*/
{
printf("two times enter the diffrent password,\n\n\nplease enter password new:");
goto shuru;
}
strcpy(yh[k].mima,mima);
if((fp=fopen("yonghu.dat","wb"))==NULL) /*操作完成后立即将信息写入文件,避免损失*/
{
printf("cannot open file\n");
return;
}
for(i=0;i
if(fwrite(&yh[i],sizeof(struct yonghu),1,fp)!=1)
printf("file write error\n");
}
fclose(fp);
printf("success! you have succeeded to change the password!\n\nplease remember the new password!\n\nand remember to use the new password next time...");
getch(); /*敲击键盘继续,目的是在清屏前看到上一个printf的内容*/
clrscr();
}