简易水电费管理系统源程序代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
简易水电费管理系统源程序代码
法一:
#include
#include
#include
struct member
{char no[100];
char name[20];
char password[20];
float wfee;
float efee;
}memb;
void newadd(int n)
{ int t,i;
fseek(fp,0,SEEK_END);
printf(">>新添人数:");
scanf("%d",&t);
for(i=0;i { printf("新添第%d个成员:"); scanf("%s %s %s %f %f",memb.no,,memb.password,memb.wfee,memb.efee); fwrite(&memb,sizeof(struct member),1,fp); } } void look(int n) { char a[100]; printf(">>输入卡号:"); scanf("%s",a); int i=0; rewind(fp); while(1) { fread(&memb,sizeof(struct member),1,fp); if(feof(fp)||memb.no==a) break; i++; } if(!feof(fp)) { printf(">>卡号:"); printf("%s\n",memb.no); printf(">>姓名:"); printf("%s\n","); printf(">>水费:"); printf("%f\n",memb.wfee); printf(">>电费:"); printf("%f\n",memb.efee); } else printf(">>查无此人\n"); }; void delete(int n) { char c[100]; printf(">>删除的卡号:"); scanf("%s," c); if((fp1=fopen("temp.bin","wb"))==NULL) { printf(">>不能建立临时文件,无法删除\n"); } rewind(fp); while(1) { fread(&memb,sizeof(struct member),1,fp); if(feof(fp)) break; if(memb.no!=c) fwrite(&memb,sizeof(struct member),1,fp1);} fclose(fp1); fclose(fp); remove("member.bin"); rename("temp.bin","member.bin"); fp=fopen("member.bin","rb++");}; main() { char a[100]; char b[20]; FILE *fp; printf("欢迎进入水电费管理系统\n") int i=0,sel=1; if((fp=fopen("member.bin","wb++"))==NULL) { printf(">>不能建立member.bin文件\n"); return(0); } while(sel!=0) { printf("| 1 | 2 | 3 | 4 |\n"); printf("| ------------------------------------------------------------ |\n"); printf("|新添成员|查找个人信息|删除成员|退出|\n); fseek(fp,0,SEEK_END); scanf("%d",&sel); switch(sel) { case 1: newadd(sel); break; clscr(); exit(0); case 2: printf("请输入您的卡号:"); printf("%s",a); printf("请输入您的密码:"); puts(b); while(strcmp(a,memb.no)==0&&strcmp(b,memb.password)==0) look(sel); printf("您的输入有误\n"); break; clscr(); exit(0); case 3: delete(sel); break; clscr(); exit(0); } 法二: #include #include #include #include #include struct member {char no[100]; char name[20]; char password[20]; float wfee; float efee; }memb; void newadd(int n) { int t,i;FILE *fp; fp=fopen("e:\\member.bin","a"); fseek(fp,0,SEEK_END); printf(">>新添人数:"); scanf("%d",&t); for(i=0;i { printf("新添第%d个成员:",i+1); scanf("%s %s %s %f %f",memb.no,,memb.password,&memb.wfee,&memb.efee); fwrite(&memb,sizeof(struct member),1,fp);}fclose(fp); } void look(int n) { char a[100],b[20]; FILE *fp;int i; fp=fopen("e:\\member.bin","rb");