商品信息管理系统C语言课程设计.docx
《商品信息管理系统C语言课程设计.docx》由会员分享,可在线阅读,更多相关《商品信息管理系统C语言课程设计.docx(19页珍藏版)》请在冰豆网上搜索。
商品信息管理系统C语言课程设计
#include
#include
#include
#include
#defineN100
structcommodity
{
charoption[20];
charname[20];
charprice[10];
charproduction_date[8];
charstale_date[8];
charfinished_goods[20];
charsaleroom[20];
};
voidprint_1();
voidcreate();
voidedit();
voidprint_2();/*invokedofedit*/
voidedit_add();/*invokedofedit*/
voidedit_modify();/*invokedofedit*/
voidedit_delete();/*invokedofedit*/
voiddelete_option();/*invokedof2delete*/
voiddelete_name();/*invokedof2delete*/
voidshow();
voidsearch();
voidsearch_option();/*invokedofsearch*/
voidsearch_name();/*invokedofsearch*/
main()
{
charchoose='\0',yes_no='\0';
do
{
print_1();
choose=getch();
switch(choose)
{
case'1':
create();break;/*createinformationofcommodity*/
case'2':
edit();break;/*editinformationofcommodity*/
case'3':
show();break;/*showinformationofcommodity*/
case'4':
search();break;/*searchinformationofcommodity*/
case'0':
exit(0);
default:
printf("\n%cisillegalityoption!
\n",choose);
}
printf("\nDoyouwanttocontinue(y/n)?
");
do
{
yes_no=getche();
}while(yes_no!
='Y'&&yes_no!
='y'&&yes_no!
='N'&&yes_no!
='n');
}while(yes_no=='Y'||yes_no=='y');
}
voidprint_1()/*showlimitingsurfaceofmenu*/
{
clrscr();/*clearnscreenoffunction*/
printf("********************************************************************************\n");
printf("**************Manage'systemofCommodityInformation*************\n");
printf("********************************************************************************\n");
printf("|***********************************************|\n");
printf("|Pleaseinputoptionnumber|\n");
printf("|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|\n");
printf("|1-----Createcommodityinformation|\n");
printf("|2-----Editcommodityinformation|\n");
printf("|3-----Showcommodityinformation|\n");
printf("|4-----Searchcommodityinformation|\n");
printf("|0-----Exitsystem|\n");
printf("|***********************************************|\n");
}
voidcreate()/*createinformationofcommodityforfunction*/
{
inti=0,j,num;
structcommoditytemp={0};
FILE*fp=NULL;
fp=fopen("D:
\\commodity.txt","w");
if(fp==NULL)
{
printf("\nFileofinformationofcommodityopeningfailed.\n");
return;
}
clrscr();/*clearnscreenoffunction*/
printf("Pleaseinputwanttoinputthenumberofgoods!
");
scanf("%d",&num);
for(j=1;num>=j;j++)
{
printf("\nPleaseinput%drecord:
\n",j);
printf("number:
");
do
{
gets(temp.option);
}while(strcmp(temp.option,"")==0);
printf("name:
");
gets(temp.name);
printf("price:
");
gets(temp.price);
printf("production:
");
gets(temp.production_date);
printf("stale_date:
");
gets(temp.stale_date);
printf("finished_goods:
");
gets(temp.finished_goods);
printf("saleroom:
");
gets(temp.saleroom);
fprintf(fp,"%s%s%s%s%s%s%s\n",temp.option,temp.name,temp.price,
temp.production_date,temp.stale_date,temp.finished_goods,temp.stale_date);
i++;
}
fclose(fp);
}
voidedit()/*editinformationofcommodityforfunction*/
{
charchoose='\0',yes_no='\0',pass[20]={0},old[20]={0},w;
inti=0,j,m=0;
FILE*fp_code;
fp_code=fopen("D:
\\code.txt","r");
if(fp_code==NULL)
{
printf("\nFileofcodeopeningfailed.\n");
return;
}
fscanf(fp_code,"%s",old);
fclose(fp_code);
for(j=0;j<=2;j++)
{
printf("Intputpassword:
");
i=0;
do
{
w=getch();
if(w!
='\r')
{
putch('*');
pass[i]=w;
i++;
}
else
break;
}while
(1);
if(strcmp(pass,old)==0)
break;
else
{
printf("\nYourcodeiswrong\n");
m++;
if(m>=3)
exit
(1);
}
}
do
{
print_2();
printf("");
choose=getch();
switch(choose)
{
case'1':
edit_add();break;/*addnewinformationofcommodity*/
case'2':
edit_modify();break;/*modifyinformationofcommodity*/
case'3':
edit_delete();break;/*deleteinformationofcommodity*/
case'0':
exit(0);
default:
printf("\n%cisillegalityoption!
\n",choose);
}
printf("\nDoyouwanttocontinue(y/n)?
");
do
{
yes_no=getche();
}while(yes_no!
='Y'&&yes_no!
='y'&&yes_no!
='N'&&yes_no!
='n');
}while(yes_no=='Y'||yes_no=='y');
}
voidprint_2()/*showlimitingsurfaceofmenu*/
{
clrscr();/*clearnscreenoffunction*/
printf("********************************************************************************\n");
printf("**************Manage'systemofCommodityInformation*************\n");
printf("********************************************************************************\n");
printf("|***********************************************|\n");
printf("|Pleaseinputoptionnumber|\n");
printf("|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|\n");
printf("|1-----Addcommodityinformation|\n");
printf("|2-----Modifycommodityinformation|\n");
printf("|3-----Deletecommodityinformation|\n");
printf("|0-----Exitsystem|\n");
printf("|***********************************************|\n");
}
voidedit_add()/*addnewinformationofcommodity*/
{
charc='\0';
intn=0;
structcommoditytemp={0},record[N]={0},*p=NULL;
FILE*fp=NULL;
fp=fopen("D:
\\commodity.txt","r");
if(fp==NULL)
{
printf("\nFileopeningfailed.\n");
return;
}
p=record;
while(feof(fp)==0)
{
fscanf(fp,"%s%s%s%s%s%s%s",p->option,p->name,p->price,p->production_date,p->stale_date,
p->finished_goods,p->saleroom);
p++;
n++;
}
fclose(fp);
do
{
printf("\nPleaseinputnewoption:
");
do
{
gets(temp.option);
}while(strcmp(temp.option,"")==0);
printf("Pleaseinputnewname:
");
gets(temp.name);
printf("Pleaseinputnewprice:
");
gets(temp.price);
printf("Pleaseinputnewproduction:
");
gets(temp.production_date);
printf("Pleaseinputnewstale_date:
");
gets(temp.stale_date);
printf("Pleaseinputnewfinished_goods:
");
gets(temp.finished_goods);
printf("Pleaseinputnewsaleroom:
");
gets(temp.saleroom);
for(p=record;pif(strcmp(temp.option,p->option)==0)
{
printf("\nTheoptionisrepeat,ifyouwanttoinputagain(y/n)?
");
do
{
c=getche();
}while(c!
='Y'&&c!
='y'&&c!
='N'&&c!
='n');
putchar('\n');
break;
}
if(p==record+n)
{
*p=temp;
break;
}
}while(c=='y'||c=='Y');
fp=fopen("D:
\\commodity.txt","w");
if(fp==NULL)
{
printf("\nFileopeningfailed.\n");
return;
}
for(p=record;pfprintf(fp,"\n%6s%10s%8s%8s%8s%8s%8s",p->option,p->name,p->price,p->production_date,p->stale_date,
p->finished_goods,p->saleroom);
fclose(fp);
}
voidedit_modify()/*modifyinformationofcommodity*/
{
charc='\0';
intn=0;
structcommodity*find=NULL,temp={0},record[100]={0},*p=NULL;
FILE*fp=NULL;
fp=fopen("D:
\\commodity.txt","r");
if(fp==NULL)
{
printf("\nFileopeningfailed.\n");
return;
}
p=record;
while(!
feof(fp))
{
fscanf(fp,"%s%s%s%s%s%s%s",p->option,p->name,p->price,p->production_date,p->stale_date,
p->finished_goods,p->saleroom);
p++;
n++;
}
fclose(fp);
if(n==0)
{
printf("\nNorecordinthisfile.\n");
return;
}
printf("\nPleaseinputyouwanttocommodity'option:
");
gets(temp.option);
for(p=record;pif(strcmp(temp.option,p->option)==0)
{
find=p;
break;
}
if(p==record+n)
{
printf("\nNothiscommodity.\n");
return;
}
do
{
printf("\nPleaseinputrightoption.:
");
do
{
gets(temp.option);
}while(strcmp(temp.option,"")==0);
printf("Pleaseinputrightname:
");
gets(temp.name);
printf("Pleaseinputrightprice:
");
gets(temp.price);
printf("Pleaseinputrightproduction:
");
gets(temp.production_date);
printf("Pleaseinputrightstale_date:
");
gets(temp.stale_date);
printf("Pleaseinputrightfinished_goods:
");
gets(temp.finished_goods);
printf("Pleaseinputrightsaleroom:
");
gets(temp.saleroom);
for(p=record;pif(strcmp(temp.option,p->option)==0&&(p!
=find))
{
printf("\nTheoptionisrepeat,doyouwanttocontinue?
(y/n)");
do
{
c=getche();
}while(c!
='Y'&&c!
='y'&&c!
='N'&&c!
='n');
putchar('\n');
break;
}
if(p==record+n)
{
*find=temp;
break;
}
}while((c=='y')||(c=='Y'));
fp=fopen("D:
\\commodity.txt","w");
if(fp==NULL)
{
printf("\nFileopeningisfailed.\n");
return;
}
for(p=record;pfprintf(fp,"\n%6s%10s%8s%8s%8s%8s%8s",p->option,p->name,p->price,p->production_date,p->stale_date,
p->finished_goods,p->saleroom);
fclose(fp);
}
voidedit_delete()/*deleteinformationofcommodity*/
{
charc='\0';
printf("\nAccordingtotheoption(o)todelete,deleteorbythename(n)?
");
c=getche();
if(c=='o'||c=='O')
delete_option();
else
if(c=='n'||c=='N')
delete_name();
else
printf("\nThischarisillegal.\n");
}
voiddelete_option()/*deleteinformationofcommoditybyoption*/
{
chartempoption[10]="";
intn=0;
structcommodityrecord[N]={0},*p=NULL,*k=NULL;
FILE*fp=NULL;
fp=fopen("D:
\\commodity.txt","r");
if(fp==NULL)
{
printf("\nFileopeningisfailed.\n");
return;
}
p=record;
while(!
feof(fp))
{
fscanf(fp,"%s%s%s%s%s%s%s",p->option,p->name,p->price,p->production_date,p->stale_date,
p->finished_goods,p->saleroom);
p++;
n++;
}
fclose(fp);
printf("\nPleaseinputyouwanttodeletetheoption:
");
gets(tempoption);
for(k=record;kif(strcmp(tempoption,k->option)==0)
break;
if(kfor(p=k;p*p=*(p+1);
else
printf("\nNosuchcommodify.\n");
fp=fopen("D:
\\commodi