include.docx
- 文档编号:9889220
- 上传时间:2023-02-07
- 格式:DOCX
- 页数:38
- 大小:31.18KB
include.docx
《include.docx》由会员分享,可在线阅读,更多相关《include.docx(38页珍藏版)》请在冰豆网上搜索。
include
#include"stdio.h"
#include"string.h"
#defineSPBstructseller_fit_building
#defineBUDstructbuilding
#definePEJstructfit
#defineXSSstructseller
intm;
SPB/*定义结构体spb代表销售商—配件—建筑工地*/
{
intseller_num;
intfit_num;
intbuilding_num;
intcount;
}spb[100];
BUD/*定义结构体bud代表建筑工地*/
{intnum;
charname[20];
charcity[20];
}bud[100];
PEJ/*定义结构体pej代表配件*/
{
intnum;
charname[20];
charcoulor[20];
intweight;
charmakeplace[20];
}pej[100];
XSS/*定义结构体xss代表销售商*/
{
intnum;
charname[20];
charstate[20];
charcity[20];
}xss[100];
2、主函数
主函数一般设计得比较简单,只提供输入,功能处理和输出部分的函数调用.其中各功能模块用菜单方式选择.
[程序]
voidTextOut(){/*主功能菜单*/
printf("\t\t*************MUNU**********\n\n");
printf("\t\tCheckdata-------------0.\n\n");
printf("\t\tAdddata-------------1.\n\n");
printf("\t\tupdatedata-------------2.\n\n");
printf("\t\tdeletedata-------------3.\n\n");
printf("\t\texit---------------4.\n\n");
printf("\t\t***************************\n\n");
}
main(){
intch;
TextOut();
scanf("%d",&ch);
while(ch!
=4){/*对选择的数字做判断*/
if(ch==0){/*检查模块*/
IndexFile(Choise());
printf("Youhavesuccessfullyindexthereader!
\n");
TextOut();
scanf("%d",&ch);
continue;
}
if(ch==1){/*增加模块*/
enter();
printf("Youhavesuccessfullyaddareader!
\n");
TextOut();
scanf("%d",&ch);
continue;
}
if(ch==2){/*更新模块*/
UpdateFile(Choise());
printf("Youhavesuccessfullyupdatethelist!
\n");
TextOut();
scanf("%d",&ch);
continue;
}
if(ch==3){/*删除模块*/
DeleteFile(Choise());
printf("Youhavesuccessfullyoutputthelist!
\n");
TextOut();
scanf("%d",&ch);
continue;
}
elsereturn;
}
}
3各功能模块设计
(1)增加模块
voidinput_spb(inti)/*输入结构体结点spb的信息*/
{
printf("seller'snumber:
\n");
scanf("%d",&spb[i].seller_num);
printf("fit'snumber:
\n");
scanf("%d",&spb[i].fit_num);
printf("building'snumber:
\n");
scanf("%d",&spb[i].building_num);
printf("count'snumber:
\n");
scanf("%d",&spb[i].count);
}
voidinput_bud(inti)/*输入结构体结点bud的信息*/
{
printf("building'snumber:
\n");
scanf("%d",&bud[i].num);
printf("name:
\n");
scanf("%s",&bud[i].name);
printf("city:
\n");
scanf("%s",&bud[i].city);
}
voidinput_pej(inti)/*输入结构体结点pej的信息*/
{
printf("fit'snumber:
\n");
scanf("%d",&pej[i].num);
printf("name:
\n");
scanf("%s",&pej[i].name);
printf("coulor:
\n");
scanf("%s",&pej[i].coulor);
printf("weight:
\n");
scanf("%d",&pej[i].weight);
printf("makeplace:
\n");
scanf("%s",&pej[i].makeplace);
}
voidinput_xss(inti)/*输入结构体结点xss的信息*/
{
printf("number:
\n");
scanf("%d",&xss[i].num);
printf("name:
\n");
scanf("%s",&xss[i].name);
printf("state:
\n");
scanf("%s",&xss[i].state);
printf("city:
\n");
scanf("%s",&xss[i].city);
}
voidenter()/*输入文件信息*/
{
inti,c;
do
{
puts("\nenterby=>\n\n1)spb2)bud3)pej4)xss5)exit");
printf("whichyouneeded?
:
\n");
scanf("%d",&c);
if(c<1||c>5)
puts("\nChioseerror!
Pleaseagain!
");
}
while(c<1||c>5);
printf("Howmangdates?
:
\n");
scanf("%d",&m);
for(i=0;i { printf("Input%dthdate\n",i+1); switch(c) { case1: input_spb(i);break; case2: input_bud(i);break; case3: input_pej(i);break; case4: input_xss(i);break; } } switch(c) { case1: if(i! =0)save_spb(m,spb);break; case2: if(i! =0)save_bud(m,bud);break; case3: if(i! =0)save_pej(m,pej);break; case4: if(i! =0)save_xss(m,xss);break; } } intChoise(){/*选择要操作的文件*/ intj; printf("ifyouwanttomanipulatefilespb.txt.pleasepress1.\n"); printf("ifyouwanttomanipulatefilebud.txt.pleasepress2.\n"); printf("ifyouwanttomanipulatefilepej.txt.pleasepress3.\n"); printf("ifyouwanttomanipulatefilexss.txt.pleasepress4.\n"); scanf("%d",&j); returnj; } voidsave_spb(intm,SPB*curr){/*将结构体spb的结点保存在文件spb.txt中*/ FILE*fp; inti; if((fp=fopen("spb.txt","at"))==NULL) printf("\nCannotopenfile\n"); for(i=0;i fprintf(fp,"%10d%10d%10d%10d\n" curr[i].seller_num,curr[i].fit_num,curr[i].building_num,curr[i].count); fclose(fp); } voidsave_bud(intm,BUD*curr){/*将结构体bud的结点保存在文件bud.txt中*/ FILE*fp; inti; if((fp=fopen("bud.txt","at"))==NULL) printf("\nCannotopenfile\n"); for(i=0;i fprintf(fp,"%10d%20s%20s\n" curr[i].num,curr[i].name,curr[i].city); fclose(fp); } voidsave_pej(intm,PEJ*curr){/*将结构体pej的结点保存在文件pej.txt中*/ FILE*fp; inti; if((fp=fopen("pej.txt","at"))==NULL) printf("\nCannotopenfile\n"); for(i=0;i fprintf(fp,"%10d%20s%20s%10d%20s\n" curr[i].num,curr[i].name,curr[i].coulor,curr[i].weight,curr[i].makeplace); fclose(fp); } voidsave_xss(intm,XSS*curr){/*将结构体xss的结点保存在文件xss.txt中*/ FILE*fp; inti; if((fp=fopen("xss.txt","at"))==NULL) printf("\nCannotopenfile\n"); for(i=0;i fprintf(fp,"%10d%20s%20s%20s\n" curr[i].num,curr[i].name,curr[i].state,curr[i].city); fclose(fp); } (2)删除模块 voidDeleteFile(intm){/*删除文件信息*/ SPBcurrnode1; BUDcurrnode2; PEJcurrnode3; XSScurrnode4; inti=0,j=0; intnum; charname[20]; FILE*fp; if(m==1){/*删除文件spb.txt信息*/ printf("pleaseinputtheseller_numofspb: \n"); scanf("%d",&num); if((fp=fopen("spb.txt","rt+"))==NULL){ printf("%s\n","CannotopenthefileorCannotfindthefile.pleasecheckout."); } i=ftell(fp); fscanf(fp,"%d%d%d%d" &currnode1.seller_num,&currnode1.fit_num,&currnode1.building_num,&currnode1.count); j=ftell(fp); j=j-i; rewind(fp); while(! feof(fp)){ fscanf(fp,"%d%d%d%d" &currnode1.seller_num,&currnode1.fit_num,&currnode1.building_num,&currnode1.count); if(feof(fp)) break; if(num==currnode1.seller_num){ fseek(fp,-j,1); fprintf(fp,"%10d%10d%10d%10d\n" 0,0,0,0); fseek(fp,2L,1); } } } if(m==2){/*删除文件bud.txt信息*/ printf("pleaseinputthenumofbud: \n"); scanf("%d",&num); if((fp=fopen("bud.txt","rt+"))==NULL){ printf("%s\n","CannotopenthefileorCannotfindthefile.pleasecheckout."); } i=ftell(fp); fscanf(fp,"%d%s%s" &currnode2.num,currnode2.name,currnode2.city); j=ftell(fp); j=j-i; rewind(fp); while(! feof(fp)){ fscanf(fp,"%d%s%s" &currnode2.num,currnode2.name,currnode2.city); if(feof(fp)) break; if(num==currnode2.num){ fseek(fp,-j,1); fprintf(fp,"%10d%20s%20s\n" 0,"NULL","NULL"); fseek(fp,2L,1); } } } if(m==3){/*删除文件pej.txt信息*/ printf("pleaseinputthenumofpej: \n"); scanf("%d",&num); if((fp=fopen("pej.txt","rt+"))==NULL){ printf("%s\n","CannotopenthefileorCannotfindthefile.pleasecheckout."); } i=ftell(fp); fscanf(fp,"%d%s%s%d%s" &currnode3.num,currnode3.name,currnode3.coulor &currnode3.weight,currnode3.makeplace); j=ftell(fp); j=j-i; rewind(fp); while(! feof(fp)){ fscanf(fp,"%d%s%s%d%s" &currnode3.num,currnode3.name,currnode3.coulor &currnode3.weight,currnode3.makeplace); if(feof(fp)) break; if(num==currnode3.num){ fseek(fp,-j,1); fprintf(fp,"%10d%20s%20s%10d%20s\n" 0,"NULL","NULL",0,"NULL"); fseek(fp,2L,1); } } } if(m==4){/*删除文件xss.txt信息*/ printf("pleaseinputthenumofxss: \n"); scanf("%d",&num); if((fp=fopen("xss.txt","rt+"))==NULL){ printf("%s\n","CannotopenthefileorCannotfindthefile.pleasecheckout."); } i=ftell(fp); fscanf(fp,"%d%s%s%s" &currnode4.num,currnode4.name,currnode4.state,currnode4.city); j=ftell(fp); j=j-i; rewind(fp); while(! feof(fp)){ fscanf(fp,"%d%s%s%s" &currnode4.num,currnode4.name,currnode4.state,currnode4.city); if(feof(fp)) break; if(num==currnode4.num){ fseek(fp,-j,1); fprintf(fp,"%10d%20s%20s%20s\n" 0,"NULL","NULL","NULL"); fseek(fp,2L,1); } } } } (3)检索模块 voidIndexFile(intm){/*检索文件信息*/ SPBcurrnode1; BUDcurrnode2; PEJcurrnode3; XSScurrnode4; inti=0,j=0; intnum; charname[20]; intsn,fn,bn,co,nd,np,wp,nx; charnad[20],cd[20],nap[20],cop[20],mp[20],sx[20],cx[20]; FILE*fp; if(m==1){/*检索文件spb.txt中的信息*/ printf("ifyouwanttoindexseller_numofspb,pleasepress1.\n"); printf("ifyouwanttoindexfit_numofspb,pleasepress2.\n"); printf("ifyouwanttoindexbuilding_numofspb,pleasepress3.\n"); printf("ifyouwanttoindexcountofspb,pleasepress4.\n"); scanf("%d",&num); if(num==1){/*按销售者编号检索文件spb.txt中的信息*/ printf("pleaseinputtheseller_numofspbyouwanttoindex.\n"); scanf("%d",&sn); if((fp=fopen("spb.txt","rt+"))==NULL){ printf("%s\n","CannotopenthefileorCannotfindthefile.pleasecheckout."); } i=ftell(fp); fscanf(fp,"%d%d%d%d" &currnode1.seller_num,&currnode1.fit_num,&currnode1.building_num &currnode1.count); j=ftell(fp); j=j-i; rewind(fp); while(! feof(fp)){ fscanf(fp,"%d%d%d%d" &currnode1.seller_num,&currnode1.fit_num,&currnode1.building_num,&currnode1.count); if(feof(fp)) break; if(sn==currnode1.seller_num){ printf("%10d%10d%10d%10d\n" currnode1.seller_num,currnode1.fit_num,currnode1.building_num,currnode1.count); } } } if(num==2){/*按零件编号检索文件spb.txt中的信息*/ printf("pleaseinputthefit_numofspbyouwanttoindex.\n"); scanf("%d",&fn); if((fp=fopen("spb.txt","rt+"))==NULL){ printf("%s\n","CannotopenthefileorCannotfindthefile.pleasecheckout."); } i=ftell(fp); fscanf(fp,"%d%d%d%d" &currnode1.seller_num,&currnode1.fit_num,&currnode1.building_num &currnode1.count); j=ftell(fp); j=j-i; rewind(fp); while(! feof(fp)){ fscanf(fp,"%d%d%d%d" &currnode1.seller_num,&currnode1.fit_num,&currnode1.building_num,&currnode1.count); if(feof(fp)) break; if(fn==currnode1.fit_num){ printf("%10d%10d%10d%10d\n" currnode1.seller_num,currnode1.fit_num,currnode1.building_num,cur
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- include