ATMC语言编程源代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#includestdio.h/*引用库函数*/#includestdlib.h#includestring.h#includeconio.h#includetime.h#defineZHANGHUSHU10#defineJIAOYISHU20intcaidan();/*登录注册菜单*/voidzhuce();voiddenglu();voidbaocunshuju();intmenu();/*主菜单*/voidcunkuan();voidqukuan();voidzhuanzhang();voidchaxun();voidxiugaimima();structJiaoYi/*定义交易结构体*/{charshijian[50];/*时间*/charleixing[3];/*类型*/floatjine;/*金额*/floatyue;/*余额*/};structZhangHu/*定义账户结构体*/{charxingming[17];/*姓名*/charzhanghao[12];/*账号*/charshenfenzheng[19];/*身份证*/charmima[7];/*密码*/floatyue;/*余额*/structJiaoYijiaoyi[JIAOYISHU];/*在账户的结构体中在定义交易的结构体*/intjiaoyishu;};structZhangHuzhanghu[ZHANGHUSHU];/*定义账户数来确定账户这一结构体中有多少个体*/intj;/*当前账户*/intzhanghushu;intk;/*交易帐号*/intjiaoyishu;voidxianshizhanghu();intcaidan()/*菜单函数*/{charc;do{system(cls);/*每次选择运行前清屏*/printf(\t\t=================欢迎使用ATM系统===============\n\n);/*菜单选择*/printf(\t\t*1.注册**\n);printf(\t\t*2.登录*\n);printf(\t\t*3.保存数据*\n);printf(\t\t*0.退出*\n);printf(\t\t===============================================\n);printf(\t\t\t请作出选择(0-3):);c=getchar();/*读入选择*/}while(c'0'||c'3');return(c-'0');/*c变为空后返回重新选择*/}/*根据主菜单的返回值来确定主函数的值*/voidzhuce(){printf(\n\t\t请输入姓名:);scanf(%s,zhanghu[zhanghushu].xingming);printf(\n\t\t请输入帐号:);scanf(%s,zhanghu[zhanghushu].zhanghao);do{printf(\n\t\t请输入身份证:);scanf(%s,zhanghu[zhanghushu].shenfenzheng);if(strlen(zhanghu[zhanghushu].shenfenzheng)==18)break;elseprintf(\n\t\t身份证必须是18,请重新输入!);}while(1);do{printf(\n\t\t请输入密码:);scanf(%s,zhanghu[zhanghushu].mima);if(strlen(zhanghu[zhanghushu].mima)==6)break;elseprintf(\n\t\t密码必须是6位,请重新输入!);}while(1);zhanghu[zhanghushu].yue=0;zhanghu[zhanghushu].jiaoyishu=0;zhanghushu++;xianshizhanghu();}voidxianshizhanghu()/*显示账户函数来显示所输入的账户*/{inti;for(i=0;izhanghushu;i++){printf(\n\n\t帐号\t姓名\t身份证\t\t密码\t余额\n);printf(\t%s\t%s\t%s\t%s\t%.2f\n,zhanghu[i].zhanghao,zhanghu[i].xingming,zhanghu[i].shenfenzheng,zhanghu[i].mima,zhanghu[i].yue);system(pause);}}voiddenglu()/*登录函数*/{charzhanghao[12],mima[7];inti=0;intmimacishu=1;printf(\n\t\t请输入帐号:);scanf(%s,zhanghao);while(strcmp(zhanghao,zhanghu[i].zhanghao)!=0&&izhanghushu)i++;/**/if(i==zhanghushu)return;do{printf(\n\t\t请输入密码:);scanf(%s,mima);if(strcmp(mima,zhanghu[i].mima)!=0){if(mimacishu==3){printf(你已输入错误三次,你不能在输.);system(pause);return;}else{printf(密码错误请重新输入:);mimacishu++;}}elsebreak;}while(1);for(;;){switch(menu())/*选择判断*/{case1:cunkuan();break;case2:qukuan();break;case3:zhuanzhang();break;case4:chaxun();break;case5:xiugaimima();break;case0:return;}}}voidbaocunshuju()/*保存数据*/{inti,j;FILE*fp;charfilename[20];printf(\t\t\t将数据保存到一个文本文件中\n);/*输入文件名*/printf(\t\t\t请输入文件名);fflush(stdin);scanf(%s,filename);if((fp=fopen(filename,w))==NULL)/*打开文件*/{printf(无法创建此文件\n);system(pause);return;}fprintf(fp,%d\n,zhanghushu);/*循环写入数据*/printf(\t帐号\t\t姓名\t\t身份证\t\t密码\t余额\t交易数);for(i=0;izhanghushu;i++){fprintf(fp,\t%15s%10s%20s%10s\t%10.2f\t%5d\n,zhanghu[i].zhanghao,zhanghu[i].xingming,zhanghu[i].shenfenzheng,zhanghu[i].mima,zhanghu[i].yue,zhanghu[i].jiaoyishu);for(j=0;jzhanghu[i].jiaoyishu;j++)fprintf(fp,%30s%10s%10.2f%10.2f\n,zhanghu[i].jiaoyi[j].shijian,zhanghu[i].jiaoyi[j].leixing,zhanghu[i].jiaoyi[j].jine,zhanghu[i].jiaoyi[j].yue);}fclose(fp);}voidduqushuju(){inti,j;FILE*fp;charfilename[20];printf(\n\n\n\t请输入欲读入数据的文件名:\n);fflush(stdin);gets(filename);if(strlen(filename)==0)return;elseif((fp=fopen(filename,r))==NULL)/*打开文件*/{printf(无法打开此文件\n);system(pause);return;}else{printf(\t\t成功打开文件.\n);getch();}fscanf(fp,%d\n,zhanghushu);for(i=0;izhanghushu;i++){fscanf(fp,%15s%10s%20s%10f\t%10f%5d\n,zhanghu[i].zhanghao,zhanghu[i].xingming,zhanghu[i].shenfenzheng,zhanghu[i].mima,&zhanghu[i].yue,&zhanghu[i].jiaoyishu);for(j=0;jzhanghu[i].jiaoyishu;j++){fgets(zhanghu[i].jiaoyi[j].shijian,30,fp);fscanf(fp,%5s%10f\t%10f\n,zhanghu[i].jiaoyi[j].leixing,&(zhanghu[i].jiaoyi[j].jine),&(zhanghu[i].jiaoyi[j].yue));}}fclose(fp);}intmenu(){charc;do{system(cls);printf(\n\n\t=================欢迎使用XXX银行ATM==================\n\n);printf(\t=====================请选择服务=====================\n);printf(\t**\n);printf(\t*1实时存款2取款服务*\n);printf(\t**\n);printf(\t*3转账服务4查询*\n);printf(\t**\n);printf(\t*5修改密码6退出*\n);printf(\t**\n);printf(\t====================================================\n);printf(\t\t\t请作出选择(1-7):);c=getchar();/*读入选择*/system(pause);}while(c'1'||c'7');return(c-'0');/*c变为空后返回重新选择*/}voidcunkuan()/*存款函数*/{floatcunkuanjine;/*输入的存款金额*/intk;inti;chart[30];time_trawtime;structtm*timeinfo;time(&rawtime);timeinfo=localtime(&rawtime);strcpy(t,asctime(timeinfo));for(i=0;t[i]!='\0';i++)if(t[i]=='\n'){t[i]='\0';break;}printf(请输入存款金额(存款金额必须大于0,不超过10000,必须是100元的面额\n);scanf(%f,&cunkuanjine);if(cunkuanjine=0||cunkuanjine1000||(int)cunkuanjine%100!=0){printf(金额不符合要求,请重新选择);return;}else{k=zhanghu[j].jiaoyishu;strcpy(zhanghu[j].jiaoyi[k].shijian,t);strcpy(zhanghu[j].jiaoyi[k].leixing,存);zhanghu[j].jiaoyi[k].jine=cunkuanjine;zhanghu[j].yue+=cunkuanjine;zhanghu[j].jiaoyi[k].yue=zhanghu[j].yue;zhanghu[j].jiaoyishu++;printf(\n\\t\t\t您本次存了%.2f元\n,cunkuanjine);printf(\n\\t\t\t您的余额为%.2f元\n,zhanghu[j].yue);printf(

1 / 16
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功