资源描述:
《图书管理系统实训.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、#include#include#include#definesize100typedefstruct{longnumber;//»áÔ±µÄÐòºÅcharname[9];//»áÔ±µÄÃû×Öcharps[7];//»áÔ±µÄÃÜÂëintpower;//»áÔ±µÄȨÏÞ}huiyuan;typedefstruct{longnumber;//ͼÊéµÄÐòºÅcharname[100];//ͼÊéµÄÃû³Æfloatprice;//ͼÊéµÄ¼Û¸ñfl
2、oatmemberprice;//ͼÊéµÄ»áÔ±¼Û}books;voidinitbooks(){FILE*fp;bookstmps,show;chardatafile[40]="books";intcount=0;fp=fopen(datafile,"wb+");if(fp==NULL){printf("Îļþ%s´ò²»¿ª",datafile);exit(1);}printf("ÇëÄúÊäÈëͼÊéµÄÐòºÅ¡¢Ãû³Æ¡¢¼Û¸ñ");while(count<=size){printf("ÇëÄú
3、ÊäÈëͼÊéµÄÐòºÅ:");scanf("%ld",&tmps.number);if(tmps.number==0)break;printf("ÇëÄúÊäÈëͼÊéµÄÃû³Æ:");scanf("%s",tmps.name);printf("ÇëÄúÊäÈëͼÊéµÄ¼Û¸ñ:");scanf("%f",&tmps.price);tmps.memberprice=tmps.price*0.8f;if(fwrite(&tmps,sizeof(books),1,fp)!=1){printf("Îļþ%s´ò²»¿ª
4、n",datafile);exit(1);}count++;}if(count>size)printf("ÊäÈëÊý¾ÝÒÑÂú");fclose(fp);printf("ËùÊäÈëͼÊéÐÅÏ¢ÈçÏÂ:");fp=fopen(datafile,"rb");if(fp==NULL){printf("Îļþ%s´ò²»¿ª",datafile);exit(1);}printf("ÐòºÅtÃû³Æt¼Û¸ñt»áÔ±¼Û");while(fread(&show,sizeof(books),1,fp)!
5、=0)printf("%ldt%st%.1ft%.1f",show.number,show.name,show.price,show.memberprice);fclose(fp);}voidaddbooks(){FILE*fp;bookstmps,show;chardatafile[40]="books";intcount=0;fp=fopen(datafile,"ab+");if(fp==NULL){printf("Îļþ%s´ò²»¿ª",datafile);exit(1);}printf("ÇëÊäÈëͼ
6、ÊéµÄÐòºÅ¡¢Ãû³Æ¡¢¼Û¸ñ");while(count<=size){printf("ÇëÊäÈëͼÊéµÄÐòºÅ:");scanf("%ld",&tmps.number);if(tmps.number==0)break;printf("ÇëÊäÈëͼÊéµÄÃû³Æ:");scanf("%s",tmps.name);printf("ÇëÊäÈëͼÊéµÄ¼Û¸ñ:");scanf("%f",&tmps.price);tmps.memberprice=tmps.price*0.8f;if(fwrite
7、(&tmps,sizeof(books),1,fp)!=1){printf("Îļþ%s´ò²»¿ª",datafile);exit(1);}count++;}if(count>size)printf("ÊäÈëÊý¾ÝÒÑÂú");fclose(fp);printf("ËùÊäÈëͼÊéÐÅÏ¢ÈçÏÂ:");fp=fopen(datafile,"rb");if(fp==NULL){printf("Îļþ%s´ò²»¿ª",datafile);exit(1);}printf("ÐòºÅtÃû³Æt¼Û¸
8、ñt»áÔ±¼Û");while(fread(&show,sizeof(books),1,fp)!=0)printf("%ldt%st%.1ft%.1f",show.number,show.name,show.price,show.