#include
#define ZHANGHUSHU 10 #define JIAOYISHU 20
int caidan();/*登录注册菜单*/ void zhuce(); void denglu();
void baocunshuju();
int menu();/*主菜单*/ void cunkuan(); void qukuan();
void zhuanzhang(); void chaxun();
void xiugaimima();
struct JiaoYi /*定义交易结构体*/ {
char shijian[50];/*时间*/ char leixing[3];/*类型*/ float jine; /*金额*/ float yue;/*余额*/ };
struct ZhangHu /*定义账户结构体*/ {
char xingming[17];/*姓名*/ char zhanghao[12];/*账号*/
char shenfenzheng[19]; /*身份证*/ char mima[7]; /*密码*/ float yue; /*余额*/
struct JiaoYi jiaoyi[JIAOYISHU]; /*在账户的结构体中在定义交易的结构体*/
int jiaoyishu; };
struct ZhangHu zhanghu[ZHANGHUSHU]; /*定义账户数来确定账户这一结构体中有多少个体*/
int j; /*当前账户*/ int zhanghushu; int k;/*交易帐号*/ int jiaoyishu;
void xianshizhanghu();
int caidan()/*菜单函数*/ {
char c; do {
system(\); /*每次选择运行前清屏*/
printf(\欢迎使用ATM系统===============\\n\\n\); /*菜单选择*/
printf(\注册* *\\n\);
printf(\登录 *\\n\);
printf(\保存数据 *\\n\);
printf(\退出 *\\n\);
printf(\
===============================================\\n\); printf(\请作出选择(0-3):\); c=getchar(); /*读入选择*/ }
while(c<'0'||c>'3');
return(c-'0'); /*c变为空后返回重新选择*/ }/*根据主菜单的返回值来确定主函数的值*/
void zhuce() {
printf(\请输入姓名:\);
scanf(\,zhanghu[zhanghushu].xingming); printf(\请输入帐号:\);
scanf(\,zhanghu[zhanghushu].zhanghao); do {
printf(\请输入身份证:\);
scanf(\,zhanghu[zhanghushu].shenfenzheng); if(strlen(zhanghu[zhanghushu].shenfenzheng)==18) break; else
printf(\身份证必须是18,请重新输入!\); }
while(1); do
{ printf(\请输入密码:\);
scanf(\,zhanghu[zhanghushu].mima); if(strlen(zhanghu[zhanghushu].mima)==6) break; else
printf(\密码必须是6位,请重新输入!\); }
while(1);
zhanghu[zhanghushu].yue=0;
zhanghu[zhanghushu].jiaoyishu=0; zhanghushu++;
xianshizhanghu(); }
void xianshizhanghu() /*显示账户函数来显示所输入的账户*/ {
int i;
for(i=0;i printf(\帐号\\t姓名\\t身份证\\t\\t密码\\t余额\\n\); printf(\,zhanghu[i].zhanghao,zhanghu[i].xingming,zhanghu[i].shenfenzheng,zhanghu[i].mima,zhanghu[i].yue); system(\); } } void denglu() /*登录函数*/ { char zhanghao[12],mima[7]; int i=0; int mimacishu=1; printf(\请输入帐号:\); scanf(\,zhanghao); while(strcmp(zhanghao,zhanghu[i].zhanghao)!=0&&i if(i==zhanghushu) return; do { printf(\请输入密码:\); scanf(\,mima); if(strcmp(mima,zhanghu[i].mima)!=0) { if(mimacishu==3) { printf(\你已输入错误三次,你不能在输.\); system(\); return; } 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 filename[20]; printf(\将数据保存到一个文本文件中\\n\);/*输入文件名*/ printf(\请输入文件名\); fflush(stdin); scanf(\,filename); if((fp=fopen(filename,\))==NULL)/*打开文件*/ { printf(\无法创建此文件\\n\); system(\); return; } fprintf(fp,\,zhanghushu);/*循环写入数据*/ printf(\帐号\\t\\t姓名\\t\\t身份证\\t\\t密码\\t余额\\t交易数\); for(i=0;i fprintf(fp,\,zhanghu[i].zhanghao,zhanghu[i].xingming,zhanghu[i].shenfenzheng,zhanghu[i].mima,zhanghu[i].yue,zhanghu[i].jiaoyishu); for(j=0;j fprintf(fp,\,zhanghu[i].jiaoyi[j].shijian,zhanghu[i].jiaoyi[j].leixing,zhanghu[i].jiaoyi[j].jine,zhanghu[i].jiaoyi[j].yue); } fclose(fp); } void duqushuju() { int i,j;