活期储蓄账目管理系统.docx
- 文档编号:1988442
- 上传时间:2022-10-25
- 格式:DOCX
- 页数:14
- 大小:16.90KB
活期储蓄账目管理系统.docx
《活期储蓄账目管理系统.docx》由会员分享,可在线阅读,更多相关《活期储蓄账目管理系统.docx(14页珍藏版)》请在冰豆网上搜索。
活期储蓄账目管理系统
#include
usingnamespacestd;
#include
#include
#include
#definefile"temp.txt"//数据存储的文件名
structuser//用户类型定义(账号,,号,余额)
{
intid;
charname[20];
charperson_num[19];
doublemoney;
};
voidadd()//添加用户资料
{
cout<<"***添加用户***"< cout<<"---------------------------------------------"< structusergetuser(); intcount();//函数目的: 计算文件中的记录数目以生成自动账号 FILE*fp; intnumber; structusertemp; if((fp=fopen(file,"ab"))==NULL) { cout<<"cannotopenfile! "< exit (1); } temp=getuser();//读取用户名 number=count(); temp.id=number+1;//生成自动账号 fwrite(&temp,sizeof(structuser),1,fp); cout<<"添加用户成功! "< fclose(fp); } intcount()//函数目的: 计算文件中的记录总数 { FILE*fp; intnum; structusertemp; num=0; if((fp=fopen(file,"rb"))==NULL) { cout<<"cannotopenfile! "< exit (1); } while(fread(&temp,sizeof(structuser),1,fp)) { num++; } fclose(fp); returnnum; } structusergetuser() { voidgetname(char*name); voidgetperson_num(char*person_num); structusertemp; cout<<"请输入用户(字符数<20): ";//读取相关开户信息 getname(temp.name); cout<<"请输入用户: "; getperson_num(temp.person_num); cout<<"输入开户金额: "; do{//判断开户金额(>=100) cin>>temp.money; fflush(stdin); if((temp.money)<100.0) cout<<"开户金额不能小于100"< else break; cout<<"重新输入开户金额: "; }while (1); returntemp; } voidgetname(char*name)//函数功能: 读取用户(字符数<20) { do{ scanf("%s",name); fflush(stdin); if(strlen(name)==0) cout<<"不能为空! "< else if(strlen(name)>=20) cout<<"不能超过20个字符! "< else break; cout<<"重新输入: "; }while (1);//循环以保证读入数据有效 } voidgetperson_num(char*person_num)//函数功能: 读取用户(15位或者18位) { do{ inti,mark; charch; for(i=0,mark=0;;i++)//输入有效性判断(只能是数字) if((ch=getchar())! ='\n') { if(ch<='9'&&ch>='0') person_num[i]=ch; else { cout<<"只能是数字! "< mark=1; break; } } else break; person_num[i]='\0'; if(mark==1) continue; if(strlen(person_num)! =15&&strlen(person_num)! =18) cout<<"只能是15位,或者18位! \n"; else break; cout<<"重新输入: "; }while (1);//循环以保证读入数据有效 } voidselect_name()//按照查询账户余额 { voidgetname(char*name); cout<<"***按照查询账户余额***"< cout<<"账号"<<"用户"<<""<<"存款余额"< cout<<"---------------------------------------------"< FILE*fp; structusertemp; charname[20]; if((fp=fopen(file,"rb"))==NULL) { cout<<"cannotopenfile! "< exit (1); } cout<<"输入要查询的: ";//调用读取用户名函数 getname(name); while(fread(&temp,sizeof(structuser),1,fp))//循环读取每一条记录判断是否为要查看的记录 if(strcmp(temp.name,name)==0) { cout< } fclose(fp); } voidselect_id()//按照账号查询账户余额 { intcount(); cout<<"***按照编号查询账户余额***"< cout<<"编号"<<"用户"<<""<<"存款余额"< cout<<"---------------------------------------------"< FILE*fp; structusertemp; inti,maxnum; if((fp=fopen(file,"rb"))==NULL) { cout<<"cannotopenfile! "< exit (1); } maxnum=count(); cout<<"输入要查询账号: ";//判断账号是否在记录中 cin>>i; if(i<1||i>maxnum) { cout<<"你要查询的账号不存在! "; return; } while(fread(&temp,sizeof(structuser),1,fp))//循环读取每一条记录判断是否为要查看的记录 if(temp.id==i) { cout< } fclose(fp); } voiddisplay()//显示用户资料 { cout<<"***用户资料显示***"< cout<<"账号"<<"用户"<<""<<"存款余额"< cout<<"---------------------------------------------"< FILE*fp; structusertemp; if((fp=fopen(file,"rb"))==NULL) { cout<<"cannotopenfile! "< exit (1); } while(fread(&temp,sizeof(structuser),1,fp)) { cout< } fclose(fp); } voidsave_money()//函数功能: 按账号存款 { cout<<"***用户存款业务***"< cout<<"---------------------------------------------"< intcount(); FILE*fp; inti,num,mark; structuser*temp; num=count();//根据记录数申请空间 temp=(structuser*)malloc(num*sizeof(structuser)); if((fp=fopen(file,"rb"))==NULL) { cout<<"cannotopenfile! "< exit (1); } for(i=0;i fread(&temp[i],sizeof(structuser),1,fp); fclose(fp); cout<<"输入要存款账号: ";//读取存款账号 cin>>mark; if(mark<1||mark>num) { cout<<"你要存款账号不存在! "; return; } if((fp=fopen(file,"wb"))==NULL)//写方式打开文件,覆盖原文件中的容 { cout<<"cannotopenfile! "< exit (1); } for(i=0;i { if(temp[i].id==mark) { doublemoney=0; cout<<"输入要存入的金额: "; cin>>money; if(money<=0) { cout<<"只能为正数! "< money=0; } temp[i].money+=money;//修改该用户的信息 } fwrite(&temp[i],sizeof(structuser),1,fp); } fclose(fp); free(temp); cout<<"你存款业务已办妥! "< } voidget_money()//函数功能: 用户取款 { cout<<"***用户取款业务***"<
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 活期 储蓄 账目 管理 系统
![提示](https://static.bdocx.com/images/bang_tan.gif)