唯品会系统分析与设计 - 图文 下载本文

内容发布更新时间 : 2024/5/4 18:00:38星期一 下面是文章的全部内容请认真阅读。

printf(\文件%s打不开\\n\ exit(1); }

printf(\序号\\t名称\\t价格\\t折扣\\t会员价\\n\while(fread(&show,sizeof(product),1,fp)!=0)

printf(\w.memberprice); fclose(fp); }

1.2、商品初始化界面

2、增加商品信息

2.1、增加商品信息代码如下:

void addgoods() { FILE *fp; product tmps,show; char datafile[40]=\ int count=0; fp=fopen(datafile,\ if(fp==NULL) { printf(\文件%s打不开\\n\ exit(1); } printf(\请输入商品的序号、名称、价格、折扣、会员价\\n\ while(count<=size) { printf(\请输入商品的序号:\ scanf(\ if(tmps.number==0) break; printf(\请输入商品的名称:\

scanf(\ printf(\请输入商品的价格:\ scanf(\ printf(\请输入商品的折扣:\ scanf(\ tmps.memberprice=tmps.price*tmps.discount; if(fwrite(&tmps,sizeof(product),1,fp)!=1) { printf(\文件%s打不开\\n\ exit(1); } count++; } if(count>size) printf(\输入数据已满\\n\ fclose(fp); printf(\所输入商品的信息如下:\\n\ fp=fopen(datafile,\ if(fp==NULL) { printf(\文件%s打不开\\n\ exit(1); } printf(\序号\\t名称\\t价格\\t折扣\\t会员价\\n\ while(fread(&show,sizeof(product),1,fp)!=0) printf(\w.memberprice); fclose(fp); }

2.2、增加商品信息界面

3、修改商品信息

3.1、修改商品信息代码如下:

void modifygoods() {

FILE *fp;

product tmps,s[size],show,temp;

char name[9],next,datafile[40]=\ int recnumber,i,result=0;

float price,discount,memberprice; begin:

printf(\请输入要修改商品的名称\ scanf(\

fp=fopen(datafile,\ if(fp==NULL) {

printf(\文件%s打不开\\n\ exit(1); }

while(feof(fp)==0) { if(fread(&temp,sizeof(product),1,fp)!=0) { if(strcmp(temp.name,name)==0) result=1; } }

if(result==0) { printf(\要修改的商品%s不存在\\n\ fclose(fp); goto begin; }

fp=fopen(datafile,\if(fp==NULL) {

printf(\文件%s打不开\\n\ exit(1); }

recnumber=0;

while((fread(&tmps,sizeof(product),1,fp))!=0) { if(strcmp(tmps.name,name)==0) { printf(\请输入要修改商品%s的价格\\n\ scanf(\

printf(\请输入要修改商品的折扣价\\n\ scanf(\ memberprice=price*discount; s[recnumber].number=tmps.number; strcpy(s[recnumber].name,tmps.name); s[recnumber].price=price; s[recnumber].discount=discount; s[recnumber].memberprice=memberprice; recnumber++; } else { s[recnumber].number=tmps.number; strcpy(s[recnumber].name,tmps.name); s[recnumber].price=tmps.price; s[recnumber].discount=tmps.discount; s[recnumber].memberprice=tmps.memberprice; recnumber++; } } fclose(fp); fp=fopen(datafile,\ if(fp==NULL) { printf(\文件%s打不开\\n\ exit(1); } for(i=0;i

fclose(fp); printf(\修改成功!\\n\ printf(\是否继续修改(y/n)\\n\ next=getche(); if(next=='y'||next=='Y') goto begin; printf(\所修改商品的信息如下:\\n\ fp=fopen(datafile,\ if(fp==NULL)

{ printf(\文件%s打不开\\n\ exit(1); } printf(\序号\\t名称\\t价格\\t折扣\\t会员价\\n\ while(fread(&show,sizeof(product),1,fp)!=0) printf(\w.memberprice); fclose(fp); }

3.2、修改商品信息界面

4、删除商品信息

4.1、删除商品信息代码如下:

void delgoods() {

FILE *fp; product tmps,s[size],show,temp; char name[9],next,datafile[40]=\ int recnumber,i,result=0; float price,discount,memberprice; begin:

printf(\请输入要删除商品名称:\ scanf(\ fp=fopen(datafile,\ if(fp==NULL) { printf(\文件%s打不开\\n\ exit(1); }