《ATMC语言编程源代码(共16页).doc》由会员分享,可在线阅读,更多相关《ATMC语言编程源代码(共16页).doc(16页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上#include /*引用库函数*/#include#include#include#include#define ZHANGHUSHU 10#define JIAOYISHU 20int caidan();/*登录注册菜单*/void zhuce();void denglu();void baocunshuju();int menu();/*主菜单*/void cunkuan();void qukuan();void zhuanzhang();void chaxun();void xiugaimima();struct JiaoYi /*定义交易结构体*/ char
2、 shijian50;/*时间*/ char leixing3;/*类型*/ float jine; /*金额*/ float yue;/*余额*/;struct ZhangHu /*定义账户结构体*/char xingming17;/*姓名*/char zhanghao12;/*账号*/char shenfenzheng19; /*身份证*/char mima7; /*密码*/float yue; /*余额*/struct JiaoYi jiaoyiJIAOYISHU; /*在账户的结构体中在定义交易的结构体*/int jiaoyishu;struct ZhangHu zhanghuZHAN
3、GHUSHU; /*定义账户数来确定账户这一结构体中有多少个体*/int j; /*当前账户*/int zhanghushu;int k;/*交易帐号*/int jiaoyishu;void xianshizhanghu();int caidan()/*菜单函数*/ char c; do system(cls); /*每次选择运行前清屏*/ printf(tt =欢迎使用ATM系统=nn); /*菜单选择*/ printf(tt * 1. 注册* *n); printf(tt * 2. 登录 *n); printf(tt * 3. 保存数据 *n); printf(tt * 0. 退出 *n)
4、; printf(tt =n); printf(ttt请作出选择(0-3):); c=getchar(); /*读入选择*/ while(c3); return(c-0); /*c变为空后返回重新选择*/*根据主菜单的返回值来确定主函数的值*/void zhuce()printf(ntt请输入姓名:); scanf(%s,zhanghuzhanghushu.xingming); printf(ntt请输入帐号:); scanf(%s,zhanghuzhanghushu.zhanghao); do printf(ntt请输入身份证:); scanf(%s,zhanghuzhanghushu.sh
5、enfenzheng); if(strlen(zhanghuzhanghushu.shenfenzheng)=18) break; else printf(ntt身份证必须是18,请重新输入!); while(1); do printf(ntt请输入密码:); scanf(%s,zhanghuzhanghushu.mima); if(strlen(zhanghuzhanghushu.mima)=6) break; else printf(ntt密码必须是6位,请重新输入!); while(1); zhanghuzhanghushu.yue=0; zhanghuzhanghushu.jiaoyi
6、shu=0; zhanghushu+; xianshizhanghu();void xianshizhanghu() /*显示账户函数来显示所输入的账户*/ int i; for(i=0;izhanghushu;i+) printf(nnt帐号t姓名t身份证tt密码t余额n); printf(t%st%st%st%st%.2fn,zhanghui.zhanghao,zhanghui.xingming,zhanghui.shenfenzheng,zhanghui.mima,zhanghui.yue); system(pause); void denglu() /*登录函数*/ char zhan
7、ghao12,mima7; int i=0; int mimacishu=1; printf(ntt请输入帐号:); scanf(%s,zhanghao); while(strcmp(zhanghao,zhanghui.zhanghao)!=0&izhanghushu) i+; /*/ if(i=zhanghushu) return; do printf(ntt请输入密码:); scanf(%s,mima); if(strcmp(mima,zhanghui.mima)!=0) if(mimacishu=3) printf(你已输入错误三次,你不能在输.); system(pause); ret
8、urn; else printf(密码错误请重新输入:); mimacishu+; else break; while(1); for(;) switch(menu() /*选择判断*/ case 1: cunkuan(); break; case 2: qukuan(); break; case 3: zhuanzhang(); break; case 4: chaxun(); break; case 5: xiugaimima(); break; case 0: return; void baocunshuju()/*保存数据*/ int i,j; FILE *fp; char filen
9、ame20; printf(ttt将数据保存到一个文本文件中n);/*输入文件名*/ printf(ttt请输入文件名); fflush(stdin); scanf(%s,filename); if(fp=fopen(filename,w)=NULL)/*打开文件*/ printf(无法创建此文件n); system(pause); return; fprintf(fp,%dn,zhanghushu);/*循环写入数据*/ printf(t帐号tt姓名tt身份证tt密码t余额t交易数); for(i=0;izhanghushu;i+) fprintf(fp,t%15s%10s%20s%10st
10、%10.2ft%5dn,zhanghui.zhanghao,zhanghui.xingming,zhanghui.shenfenzheng,zhanghui.mima,zhanghui.yue,zhanghui.jiaoyishu); for(j=0;jzhanghui.jiaoyishu;j+) fprintf(fp,%30s%10s%10.2f%10.2fn,zhanghui.jiaoyij.shijian,zhanghui.jiaoyij.leixing,zhanghui.jiaoyij.jine,zhanghui.jiaoyij.yue); fclose(fp);void duqush
11、uju() int i,j; FILE *fp; char filename20; printf(nnnt请输入欲读入数据的文件名:n); fflush(stdin); gets(filename); if(strlen(filename)=0) return; else if(fp=fopen(filename,r)=NULL)/*打开文件*/ printf(无法打开此文件n); system(pause); return; else printf(tt成功打开文件.n); getch(); fscanf(fp,%dn,zhanghushu); for(i=0;izhanghushu;i+)
12、 fscanf(fp,%15s%10s%20s%10ft%10f%5dn, zhanghui.zhanghao, zhanghui.xingming, zhanghui.shenfenzheng, zhanghui.mima, &zhanghui.yue, &zhanghui.jiaoyishu); for(j=0;jzhanghui.jiaoyishu;j+) fgets(zhanghui.jiaoyij.shijian,30,fp); fscanf(fp,%5s%10ft%10fn,zhanghui.jiaoyij.leixing, &(zhanghui.jiaoyij.jine), &(
13、zhanghui.jiaoyij.yue); fclose(fp);int menu() char c; do system(cls); printf(nnt= 欢迎使用 XXX银行ATM =nn); 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(ttt请作出选择(1-7):);
14、c=getchar(); /*读入选择*/ system(pause); while(c7); return(c-0); /*c变为空后返回重新选择*/void cunkuan() /*存款函数*/ float cunkuanjine;/*输入的存款金额*/ int k; int i; char t30; time_t rawtime; struct tm *timeinfo; time(&rawtime); timeinfo=localtime(&rawtime); strcpy(t,asctime(timeinfo); for(i=0;ti!=0;i+) if(ti=n) ti=0; br
15、eak; printf(请输入存款金额(存款金额必须大于0,不超过10000,必须是100元的面额n); scanf(%f,&cunkuanjine); if(cunkuanjine1000|(int)cunkuanjine%100!=0) printf(金额不符合要求,请重新选择); return; else k=zhanghuj.jiaoyishu; strcpy(zhanghuj.jiaoyik.shijian,t); strcpy(zhanghuj.jiaoyik.leixing,存); zhanghuj.jiaoyik.jine=cunkuanjine; zhanghuj.yue+=
16、cunkuanjine; zhanghuj.jiaoyik.yue=zhanghuj.yue; zhanghuj.jiaoyishu+; printf(nttt您本次存了%.2f元n,cunkuanjine); printf(nttt您的余额为%.2f元n,zhanghuj.yue); printf(n时间为:%sn,zhanghuj.jiaoyik.shijian); printf(n类型为:%sn,zhanghuj.jiaoyik.leixing); system(pause); void qukuan() /*取款函数*/int k;/*交易下标*/ float qukuanjine;
17、int i; char t30; time_t rawtime; struct tm *timeinfo; time(&rawtime); timeinfo=localtime(&rawtime); strcpy(t,asctime(timeinfo); for(i=0;ti!=0;i+) if(ti=n) ti=0; break; printf( 取款服务 n); printf(t=请选择服务=n); printf(t* *n); printf(t* 1 100 2 200 *n); printf(t* *n); printf(t* 3 500 4 1000 *n); printf(t* *
18、n); printf(t* 5 其他金额 6 返回主菜单 *n); printf(t* *n); printf(t=n); scanf(%f,&qukuanjine); if(qukuanjine10000|(int)qukuanjine%100!=0) printf(金额不符合要求,请重新选择); return; else if(zhanghuj.yuequkuanjine) printf(你的账户余额不足,不能完成这项操作。); return; k=zhanghuj.jiaoyishu; strcpy(zhanghuj.jiaoyik.shijian,t); strcpy(zhanghuj
19、.jiaoyik.leixing,取); zhanghuj.jiaoyik.jine=qukuanjine; zhanghuj.yue-=qukuanjine; zhanghuj.jiaoyik.yue=zhanghuj.yue; zhanghuj.jiaoyishu+; printf(nttt您本次取款%.2f元n,qukuanjine); printf(nttt您的余额为%.2f元n,zhanghuj.yue); printf(n时间为:%sn,zhanghuj.jiaoyik.shijian); printf(n类型为:%sn,zhanghuj.jiaoyik.leixing); sys
20、tem(pause); void zhuanzhang() float zhuanzhangjine; int i; int l=0; char t30,zhuanzhangzhanghao12; char sign=n; time_t rawtime; struct tm *timeinfo; time(&rawtime); timeinfo=localtime(&rawtime); strcpy(t,asctime(timeinfo); for(i=0;ti!=0;i+) if(ti=n) ti=0; printf(请输入你要转入的帐号:); scanf(%s,zhuanzhangzhan
21、ghao); while(strcmp(zhanghul.zhanghao,zhuanzhangzhanghao)!=0&lzhanghushu) l+; if(l=zhanghushu) printf(你输入的用户不存在!n); system(pause); return; printf(n该账户户主姓名为%sn,是否确认转账Y/N?,zhanghuj.xingming); scanf(tt%c,&sign); /*输入判断*/ if(sign!=y&sign!=Y) /*判断*/ return; else do printf(n请输入转账金额(大于100不超过5000):); scanf(
22、%f,&zhuanzhangjine); if(zhuanzhangjine5000) printf(输入金额不对,请重新输入!); system(pause); return; if(zhanghuj.yue=0|zhanghuj.yuezhuanzhangjine) printf(账户余额不足n); system(pause); return; else k=zhanghuj.jiaoyishu; strcpy(zhanghuj.jiaoyik.shijian,t); strcpy(zhanghuj.jiaoyik.leixing,转账); zhanghuj.jiaoyik.jine=zh
23、uanzhangjine; zhanghuj.yue-=zhuanzhangjine; zhanghuj.jiaoyik.yue=zhanghuj.yue; zhanghuj.jiaoyishu+; printf(ntt你本次转了%0.2f元n,zhuanzhangjine); printf(ntt你的余额为%0.2f元n,zhanghuj.yue); printf(ntt时间为:%sn,zhanghuj.jiaoyik.shijian); printf(ntt类型为:%sn,zhanghuj.jiaoyik.leixing); system(pause); while(0); printf(
24、nntt转账成功nn); system(pause); void xiugaimima() /*修改密码函数*/ char mima17,mima27; do do printf(nnntt请输入密码:); scanf(%s,mima1); if(strlen(mima1)=6) break; else printf(nntt密码必须是6位,请重新输入!); while(1); do printf(nnntt请确认密码:); scanf(%s,mima2); if(strlen(mima2)=6) break; else printf(输入密码必须是6位请输入密码:); while(1); i
25、f(strcmp(mima1,mima2)=0 ) /*判断第二次输入的密码是否与第一次的一致*/ break; else printf(nntt*|两次密码不相等请重新输入:nn); while(1); strcpy(zhanghuj.mima,mima1); printf(nntt修改密码成功nn); getch(); system(pause);int chaxuncaidan();/*查询菜单*/void chaxunyue();void chaxuncunkun();void chaxunqukun();void chaxunzhuangzhan();void chaxunjiaoy
26、i();void duqushuju();void chaxun() /*查询函数*/ for(;) switch(chaxuncaidan() /*选择判断*/ case 1: chaxunyue(); break; case 2: chaxuncunkun(); break; case 3: chaxunqukun(); break; case 4: chaxunzhuangzhan(); break; case 5: chaxunjiaoyi(); break; case 0: return; int chaxuncaidan()/*菜单函数*/char c; do system(cls
27、); /*每次选择运行前清屏*/ printf(tt *查询菜单*nn); /*菜单选择*/ printf(tt *| 1. 查询余额|n); printf(tt *| 2. 查询存款记录|n); printf(tt *| 3. 查询取款记录|n); printf(tt *| 4. 查询转账记录|n); printf(tt *| 5. 查询交易情况|n); printf(tt *| 0. 退出 |n); printf(tt *n); printf(ttt请作出选择(0-5):); c=getchar(); /*读入选择*/ while(c5); return(c-0); /*c变为空后返回重新
28、选择*/ void chaxunyue()/*查询余额函数*/ printf(nt您的余额为%.2f元n,zhanghuj.yue); system(pause);void chaxuncunkun() /*查询存款函数*/ int i; printf(tt *存款查询记录*nn); printf(t帐号t姓名t交易类型t交易时间tt金额t余额n); for(i=0;izhanghuj.jiaoyishu;i+) if(strcmp(zhanghuj.jiaoyii.leixing,存)=0) printf(t%st%st%st%st%.2ft%.2fnn,zhanghuj.zhanghao,
29、 zhanghuj.xingming,zhanghuj.jiaoyii.leixing, zhanghuj.jiaoyii.shijian,zhanghuj.jiaoyii.jine, zhanghuj.jiaoyii.yue); else; system(pause);void chaxunqukun() /*查询取款函数*/ int i; printf(tt *取款查询记录*nn); printf(t帐号t姓名t交易类型t交易时间tt金额t余额n); for(i=0;izhanghuj.jiaoyishu;i+) if(strcmp(zhanghuj.jiaoyii.leixing,取)=0) printf(t%st%st%st%st%.2ft%.2fnn,zhanghuj.zhanghao, zhanghuj.xingming,zhanghuj.jiaoyii.leixing, zhanghuj.jiaoyii.shijian,zhanghuj.jiaoyii.jine, zhanghuj.jiaoyii.yue); else; system(pause);void chaxunzhuangz
限制150内