1、C语言程序仓库管理系统#include#include#include#includestructInfo charnum20;charname20; intprice;intamount;charmenu()/*菜单选择函数*/charn;/*n记录选择的菜单*/system(cls);puts(tt欢迎来到仓库货物管理系统);puts(tt*MENU*n);puts(tt*1.录入货物信息*n);puts(tt*2.显示货物信息*n);puts(tt*3.查找货物信息*n);puts(tt*4.修改货物信息*n);puts(tt*5.删除货物信息*n);puts(tt*6.退出系统*n);
2、puts(tt*n);puts(*);printf(*请选择你要输入数(1-6):*n);puts(*);while(1) n=getchar(); getchar(); if(n6) puts(*);printf(*出错了!请再次输入(1-6):*n);puts(*); elsebreak;returnn;voidappend()/*货物信息输入函数*/structInfoinfo;FILE*fp;charch;if(fp=fopen(F:testfilemolde123.txt,wb)=NULL)printf(*n);printf(*不能打开文件!*n);printf(*n);getch(
3、);exit(1);doprintf(tnum:);gets(info.num);printf(tname:);gets(info.name);printf(tprice:);scanf(%d,&info.price);printf(tamount:);scanf(%d,&info.amount);getchar();fwrite(&info,sizeof(info),1,fp);printf(*n);printf(*还需要输入吗?(Y/N):*n);printf(*n);ch=getchar();getchar();while(ch=Y|ch=y);fclose(fp);voidprintf
4、1()printf(*n);printf(tt%-10st%-10st%-10st%-10sn,num,name,price,amountn); printf(*n);voidprintf2(structInfoinfo)printf(-n);printf(tt%-10st%-10st%-10dt%-10dn,info.num,info.name,info.price,info.amount);printf(-n);voiddisplay()/*货物信息显示函数*/structInfoinfo;FILE*fp;intm=0;if(fp=fopen(F:testfilemolde123.txt,
5、rb)=NULL)printf(*);printf(*不能打开文件!*);printf(*);getch();exit(1);while(fread(&info,sizeof(info),1,fp)=1)m+; if(m=1) printf1(); printf2(info); if(m!=0)&(m%10=0) printf(*n); printf(*输入任何键继续*);printf(*n); getch(); puts(nn); printf1(); fclose(fp);printf(*n);printf(*总共有%d条记录在其中!*n,m);printf(*n);getch();voi
6、dsearch()/*货物信息查询函数*/structInfoinfo;FILE*fp;intflag;/*flag为1按编号查询,flag为2按姓名查询*/inttotal=0;/*记录符合条件的记录的个数*/charch10;charf;if(fp=fopen(F:testfilemolde123.txt,rb)=NULL)printf(*n);printf(*t不能打开文件!*n);printf(*n);getch();exit(1);dorewind(fp);printf(*n); printf(*查询通过(1:编号2:姓名):*n);printf(*n); while(1) scan
7、f(%d,&flag); getchar(); if(flag2) printf(*n); printf(*出错了!请再次输入1:编号2:姓名*n); printf(*n); else break; if(flag=1)/*按编号进行查询*/ printf(*n);printf(*请输入你要查询的编号:*n);printf(*n); gets(ch); total=0;/*符合条件的记录数*/while(fread(&info,sizeof(info),1,fp)=1) if(strcmp(ch,info.num)=0) total+; if(total=1) printf1(); print
8、f2(info); else/*按姓名进行查询*/ printf(*n);printf(*请输入你要查询的姓名:*n);printf(*n); gets(ch); total=0;while(fread(&info,sizeof(info),1,fp)=1) if(strcmp(ch,info.name)=0) total+; if(total=1) printf1(); printf2(info); printf(*n); printf(*总共有%d记录在其中!*n,total);printf(*n);printf(*n); printf(*还需要查询吗?(Y/N):*n); printf(
9、*n); f=getchar(); getchar();while(f=Y|f=y);fclose(fp);voidmodify()/*货物信息修改函数*/structInfoinfo; FILE*fp1,*fp2; intflag; charch10; charf; do if(fp1=fopen(F:testfilemolde123.txt,rb)=NULL) printf(*n);printf(*不能打开文件!*n); printf(*n);getch();exit(1); if(fp2=fopen(F:testfilemolde456.txt,wb)=NULL) printf(*n);
10、printf(*不能打开文件!*n); printf(*n);getch();exit(1); printf(*n); printf(*请输入你要修改的货物编号:*n);printf(*n); gets(ch); flag=0;while(fread(&info,sizeof(info),1,fp1)=1) if(strcmp(ch,info.num)=0) printf1(); printf2(info);printf(*n); printf(*请输入新的信息:*n);printf(*n);printf(tnum:);gets(info.num);printf(tname:);gets(in
11、fo.name);printf(tprice:);scanf(%d,&info.price);printf(tamount:);scanf(%d,&info.amount);getchar(); flag=1; fwrite(&info,sizeof(info),1,fp2); fclose(fp1); fclose(fp2); if(flag=1) printf(*n);printf(*修改成功!*n); printf(*n); remove(F:testfilemolde123.txt); rename(F:testfilemolde456.txt,F:testfilemolde123.t
12、xt); else printf(*n); printf(*不能找到这个记录!*n);printf(*n); printf(*n); printf(*还修改其他吗?(Y/N):*n); printf(*n); f=getchar(); getchar(); while(f=y|f=Y);voidDelete()/*货物信息删除函数*/structInfoinfo; FILE*fp1,*fp2; intflag; charch10; charf; do if(fp1=fopen(F:testfilemolde123.txt,rb)=NULL) printf(*n);printf(*t不能打开文件
13、!*n);printf(*n);getch();exit(1); if(fp2=fopen(F:testfilemolde456.txt,wb)=NULL) printf(*n);printf(*t不能打开文件!*n);printf(*n);getch();exit(1); printf(*n);printf(*请输入你需要删除货物的编号:*n);printf(*n); gets(ch); flag=0;while(fread(&info,sizeof(info),1,fp1)=1) if(strcmp(ch,info.num)=0) printf1(); printf2(info); fla
14、g=1; break; elsefwrite(&info,sizeof(info),1,fp2); fclose(fp1); fclose(fp2); if(flag=1) printf(*n);printf(*删除成功!*n);printf(*n); remove(F:testfilemolde123.txt); rename(F:testfilemolde456.txt,F:testfilemolde123.txt); else printf(*n); printf(*不能找到这个记录!*n);printf(*n); printf(*n); printf(*还删除其他吗?(Y/N):*n)
15、; printf(*n); f=getchar(); getchar(); while(f=y|f=Y);voidmain()/*主函数*/while(1) inta; charf; charch10; charnum20=12345; printf(pleaseinputthesecret:n); scanf(%s,ch); if(strcmp(num,ch)=0) a=1; if(a=1) printf(npleaseenterinthetelproject!n); f=getchar(); getchar(); break; else printf(nthesecretiserror); printf(pleaseinputtherightsecret); while(1) switch(menu()case1:append();break;case2:display();break;case3:search();break;case4:modify();break;case5:Delete();break; case6:exit(0);break;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1