📄 main.c
字号:
printf("\n\t\t 登陆失败!任意键继续...");
}
getchar();
return checkdenglu;
}
///////////////任意指定对商品进行价格排序 11
void chaxunzhidingjiage(struct shangpin shangp[],int count)
{
struct shangpin sp[MAXLENTH];
struct shangpin sptemb;
int total=-1;
int i=0,j=0;
int low,high;
printf("\n\t\t 请输入最底价格:");
scanf("%d",&low);
printf("\n\t\t 请输入最高价格:");
scanf("%d",&high);
for(i=0;i<count;i++)
{
if(shangp[i].price>low && shangp[i].price<high)
{
total=total+1;
sp[total]=shangp[i];;
}
}
for(i=0;i<total;i++)
{
for(j=total;j>i;j--)
if(sp[j-1].price>sp[j].price)
{
sptemb=sp[j];
sp[j]=sp[j-1];
sp[j-1]=sptemb;
}
}
for(i=0;i<=total;i++)
{
printf("\n\t\t _________________________________");
printf("\n\t\t 商品编号:%d",sp[i].id);
printf("\n\t\t 商品名称:%s",sp[i].spname);
printf("\n\t\t 商品价格:%.2f",sp[i].price);
printf("\n\t\t 商品库存:%d",sp[i].kucun);
}
printf("\n\t\t 查询完成,按任意键继续其他操作....");
getchar();getchar();
}
///////////////查询给定数值段中库存最高的商品信息 7
void chaxunduankucun(struct shangpin shangp[],int count)
{
struct shangpin MAXsp;
int i=0;
int low,high;
int zhaodao=-1;
mylabel1:
mylabel2:
printf("\n\t\t 请输入最小库存:");
scanf("%d",&low);getchar();
if(low<0)
{
printf("\n\t\t 最小库存不能小于0!!");
goto mylabel2;
}
mylabel3:
printf("\n\t\t 请输入最大库存:");
scanf("%d",&high);getchar();
if(high<0)
{
printf("\n\t\t 最大库存不能小于0!!");
goto mylabel3;
}
if(low>high)
{
printf("\n\t\t 最小库存不能大于最大库存!!");
goto mylabel1;
}
for(i=0;i<count;i++)
{
if(shangp[i].kucun>=low && shangp[i].kucun<=high)
{
MAXsp=shangp[i];
zhaodao=1;
if(MAXsp.kucun<shangp[i].kucun)
{
MAXsp=shangp[i];
}
}
}
if(zhaodao==-1)
{
printf("\n\t\t 给定数值段中的库存不在所有商品的库存内\n");
}
else
{
printf("\n\t\t 给定数值段中库存最高的商品信息如下:");
printf("\n\t\t _________________________________");
printf("\n\t\t 商品编号:%d",MAXsp.id);
printf("\n\t\t 商品名称:%s",MAXsp.spname);
printf("\n\t\t 商品价格:%.2f",MAXsp.price);
printf("\n\t\t 商品库存:%d",MAXsp.kucun);
printf("\n\t\t _________________________________");
}
printf("\n\t\t 查询完成,按任意键继续其他操作....");
getchar();
}
///////////////查询所有商品信息 2
void chaxunshuoyou(struct shangpin shangp[],int count)
{
int i;
if(count==0)
{
printf("\n\t\t 你没有导入商品信息/你没有登记商品信息\n");
printf("\n\t\t 按任意键继续其他操作....");
getchar();
}
else
{
system("cls");//清屏
printf("\n\t\t 所有商品信息如下:");
for(i=0;i<count;i++)
{
printf("\n\t\t _________________________________");
printf("\n\t\t 商品编号:%d",shangp[i].id);
printf("\n\t\t 商品名称:%s",shangp[i].spname);
printf("\n\t\t 商品价格:%.2f",shangp[i].price);
printf("\n\t\t 商品库存:%d",shangp[i].kucun);
printf("\n\t\t _________________________________");
}
printf("\n\t\t 查询完成,按任意键继续其他操作....");
getchar();
}
}
///////////////输出库存小于某个值的所有商品信息并排序输出 9
void chaxunxiaoyudingkucun(struct shangpin shangp[],int count)
{
struct shangpin sp[MAXLENTH];
struct shangpin sptemb;
int total=-1;
int i=0,j=0;
int kucun=0;
mylabel1:
printf("\n\t\t 请输入最高库存:");
scanf("%d",&kucun);getchar();
if(kucun<0)
{
printf("\n\t\t 价格不能小于0!!");
goto mylabel1;
}
for(i=0;i<count;i++)
if(shangp[i].kucun<=kucun)
{
total=total+1;
sp[total]=shangp[i];
}
for(i=0;i<total;i++)
for(j=total;j>i;j--)
if(sp[j-1].kucun>sp[j].kucun)
{
sptemb=sp[j];
sp[j]=sp[j-1];
sp[j-1]=sptemb;
}
if(total<0)
{
system("cls");
printf("\n\n\n\n\n\n\n");
printf("\n\t\t 这个库存段没有商品\n\n");
printf("\n\t\t 查询完成,按任意键继续其他操作...."); getchar();
}
else
{
system("cls");
printf("\n\t\t 商品信息如下:");
for(i=0;i<=total;i++)
{
printf("\n\t\t _________________________________");
printf("\n\t\t 商品编号:%d",sp[i].id);
printf("\n\t\t 商品名称:%s",sp[i].spname);
printf("\n\t\t 商品价格:%.2f",sp[i].price);
printf("\n\t\t 商品库存:%d",sp[i].kucun);
printf("\n\t\t _________________________________");
}
printf("\n\t\t 查询完成,按任意键继续其他操作....");
getchar();
}
}
///////////////插入商品信息 3
int charu(struct shangpin shangp[],int count)
{
int j=0;
int bianhao=1;
struct shangpin shangptemb;
int weizhi=0;
printf("\n\t\t 提示:编号为0时,退出插入商品信息\n");
mylabe11:
printf("\n\t\t 请输入要插入的位置:");
scanf("%d",&weizhi);
if(weizhi>count+1)
{
printf("\n\t\t 插入位置错误!!\n");
goto mylabe11;
}
mylabe2:
printf("\n\t\t 请输入商品编号:");
scanf("%d",&shangptemb.id);getchar();
bianhao=jiancebianhao(shangp,shangptemb.id,count);// 检测是否存在相同的商品
if(bianhao==-1)
{
printf("\n\t\t 该编号已经存在!!\n");
goto mylabe2;
}
if(shangptemb.id==0) // 按0退出插入商品信息
return count;
printf("\n\t\t 请输入商品名:");
scanf("%s",&shangptemb.spname);getchar();
mylabel2:
printf("\n\t\t 请输入商品单价(元):");
scanf("%f",&shangptemb.price);getchar();
if(shangptemb.price<=0)
{
printf("\n\t\t 单价不可以小于等于0");
goto mylabel2;
}
mylabel3:
printf("\n\t\t 请输入商品库存:");
scanf("%d",&shangptemb.kucun);getchar();
if(shangptemb.kucun<0)
{
printf("\n\t\t 库存不可以小于0");
goto mylabel3;
}
for(j=count;j>weizhi-1;j--)
{
shangp[j]=shangp[j-1];
}
shangp[weizhi-1]=shangptemb;
count++;
printf("\n\t\t 插入完成,按任意键继续其他操作....");
getchar();
return count;
}
///////////////查询给定库存的商品信息 5
void chaxundingkucun(struct shangpin shangp[],int count)
{
int i=0;
int kucun=0;
int zhaodao=-1;
mylabel:
printf("\n\t\t 请输入要查找的商品的库存:");
scanf("%d",&kucun);
if(kucun<0)
{
printf("\n\t\t 库存不可以小于0!!\n");
goto mylabel;
}
for(i=0;i<count;i++)
{
if(shangp[i].kucun==kucun)
{
printf("\n\t\t _________________________________");
printf("\n\t\t 商品编号:%d",shangp[i].id);
printf("\n\t\t 商品名称:%s",shangp[i].spname);
printf("\n\t\t 商品价格:%.2f",shangp[i].price);
printf("\n\t\t 商品库存:%d",shangp[i].kucun);
printf("\n\t\t _________________________________");
zhaodao=1;
}
}
if(zhaodao==-1)
{
printf("\n\t\t 没有找到!!\n");
}
printf("\n\t\t 查询完成,按任意键继续其他操作....");
getchar();getchar();
}
///////////////输出价格高于某个值的所有商品按价格排序输出 8
void chaxundayudingjiage(struct shangpin shangp[],int count)
{
struct shangpin sp[MAXLENTH];
struct shangpin sptemb;
int total=-1;
int i=0,j=0;
int price=0;
mylabel1:
printf("\n\t\t 请输入最底价格:");
scanf("%d",&price);getchar();
if(price<0)
{
printf("\n\t\t 价格不能小于0!!");
goto mylabel1;
}
for(i=0;i<count;i++)
if(shangp[i].price>=price)
{
total=total+1;
sp[total]=shangp[i];
}
for(i=0;i<total;i++)
for(j=total;j>i;j--)
if(sp[j-1].price>sp[j].price)
{
sptemb=sp[j];
sp[j]=sp[j-1];
sp[j-1]=sptemb;
}
if(total<0)
{
system("cls");
printf("\n\n\n\n\n\n\n");
printf("\n\t\t 这个价格段没有商品\n\n");
printf("\n\t\t 查询完成,按任意键继续其他操作...."); getchar();
}
else
{
system("cls");
printf("\n\t\t 商品信息如下:");
for(i=0;i<=total;i++)
{
printf("\n\t\t _________________________________");
printf("\n\t\t 商品编号:%d",sp[i].id);
printf("\n\t\t 商品名称:%s",sp[i].spname);
printf("\n\t\t 商品价格:%.2f",sp[i].price);
printf("\n\t\t 商品库存:%d",sp[i].kucun);
printf("\n\t\t _________________________________");
}
printf("\n\t\t 查询完成,按任意键继续其他操作....");
getchar();
}
}
///////////////查询大于或小于给定库存的商品信息 6
void chaxundaxiaokucun(struct shangpin shangp[],int count)
{
int i=0;
int choice=0;
int kucun=0;
printf("\n\t\t 查询大于或小于给定库存的商品信息(1.大于 2.小于)");
printf("\n\t\t 请选择:");
scanf("%d",&choice);
if(choice==1 || choice==2)
{
printf("\n\t\t 请输入给定库存:");
scanf("%d",&kucun);
}
else
{
printf("\n\t\t 输入有错!!已退出查询请求,任意键继续...");
getchar();
}
if(choice==1)
{
for(i=0;i<count;i++)
{
if(shangp[i].kucun>=kucun)
{
printf("\n\t\t_________________________________");
printf("\n\t\t商品编号:%d",shangp[i].id);
printf("\n\t\t商品名称:%s",shangp[i].spname);
printf("\n\t\t商品价格:%.2f",shangp[i].price);
printf("\n\t\t商品库存:%d",shangp[i].kucun);
printf("\n\t\t_________________________________");
}
}
}
else
{
for(i=0;i<count;i++)
{
if(shangp[i].kucun<kucun)
{
printf("\n\t\t_________________________________");
printf("\n\t\t商品编号:%d",shangp[i].id);
printf("\n\t\t商品名称:%s",shangp[i].spname);
printf("\n\t\t商品价格:%.2f",shangp[i].price);
printf("\n\t\t商品库存:%d",shangp[i].kucun);
printf("\n\t\t_________________________________");
}
}
}
printf("\n\t\t查询完成,按任意键继续其他操作....");
getchar();getchar();
}
//////////////////////////////// 保存所有商品信息
void savefile(struct shangpin shangp[],int count)
{
char filepath[30];
printf("\n\t\t 请输入要保存的文件名:");
scanf("%s",&filepath);getchar();
FILE *fp;
if((fp=fopen(filepath,"wb+"))==NULL)
{
printf("Cannot open file strike any key exit!");
getch();
}
fwrite(shangp,sizeof(struct shangpin),count,fp);
fclose(fp);
printf("\n\t\t 保存成功!任意键继续...");
getchar();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -