|
|
|
@ -0,0 +1,193 @@
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
#include<string.h>
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
char id[10]; //序号
|
|
|
|
|
char name[20]; //名字
|
|
|
|
|
char xinghao[10];//型号
|
|
|
|
|
int price; //价格
|
|
|
|
|
char from[20]; //产地
|
|
|
|
|
int cun; //存货
|
|
|
|
|
int yiding; //已定数
|
|
|
|
|
}shop;
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
char place[20]; //客户地址
|
|
|
|
|
char call[15]; //客户电话
|
|
|
|
|
char thing[20]; //购买的物品
|
|
|
|
|
}info;
|
|
|
|
|
|
|
|
|
|
void buy();
|
|
|
|
|
void present_all();
|
|
|
|
|
void present_kehu();
|
|
|
|
|
int main(){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("------商店管理系统------\n");
|
|
|
|
|
printf("1.购买商品\n2.查询客户信息\n");
|
|
|
|
|
printf("输入你需要的功能所代表的序号\n");
|
|
|
|
|
int pok; scanf("%d",&pok);
|
|
|
|
|
|
|
|
|
|
switch(pok)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
system("cls");
|
|
|
|
|
buy(); break;
|
|
|
|
|
case 2:
|
|
|
|
|
present_kehu(); break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
void buy()
|
|
|
|
|
{
|
|
|
|
|
FILE *p,*q,*z;
|
|
|
|
|
char name[20];
|
|
|
|
|
int num;
|
|
|
|
|
info kehu;
|
|
|
|
|
|
|
|
|
|
if((p=fopen("商品信息.txt","r"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("open erro 25"); exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if((q=fopen("商品数量.txt","r"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("open erro 35"); exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if((z=fopen("客户信息.txt","a"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("erro45"); exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fscanf(q,"%d",&num);
|
|
|
|
|
|
|
|
|
|
printf("------商店购买系统-------\n");
|
|
|
|
|
printf("本店已有商品如下\n");
|
|
|
|
|
present_all();
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
printf("请输入你要购买的商品名称或编号\n");
|
|
|
|
|
scanf("%s",name);
|
|
|
|
|
system("cls");
|
|
|
|
|
shop x[50];
|
|
|
|
|
for(int i=0;i<num;i++)
|
|
|
|
|
{
|
|
|
|
|
fscanf(p,"%s%s%s%d%s%d%d",&x[i].id,&x[i].name,&x[i].xinghao,&x[i].price,&x[i].from,&x[i].cun,&x[i].yiding);
|
|
|
|
|
}
|
|
|
|
|
//输入数据//
|
|
|
|
|
for(int i=0;i<num;i++)
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(name,x[i].id)==0||strcmp(name,x[i].name)==0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if(x[i].cun==0)
|
|
|
|
|
{
|
|
|
|
|
printf("对不起,您要买的商品已经没有库存了\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("您购买的商品的信息为:\n");
|
|
|
|
|
printf("编号:%s\n名字:%s\n型号:%s\n价格:%d\n产地:%s\n存货:%d\n已订:%d\n",x[i].id,x[i].name,x[i].xinghao,x[i].price,x[i].from,x[i].cun,x[i].yiding);
|
|
|
|
|
printf("你是否要订购此商品?确定输入1,否输入2\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int kk;
|
|
|
|
|
scanf("%d",&kk);
|
|
|
|
|
switch(kk)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
|
|
printf("请输入你的地址信息\n");
|
|
|
|
|
scanf("%s",kehu.place);
|
|
|
|
|
printf("请输入你的电话信息\n");
|
|
|
|
|
scanf("%s",kehu.call);
|
|
|
|
|
fprintf(z,"\n%s %s %s",kehu.place,kehu.call,x[i].name);
|
|
|
|
|
printf("订购成功\n");
|
|
|
|
|
x[i].cun--;//存-1
|
|
|
|
|
x[i].yiding++;//已定+1
|
|
|
|
|
fclose(p);
|
|
|
|
|
|
|
|
|
|
if((p=fopen("商品信息.txt","w"))==NULL) // 重置//
|
|
|
|
|
{
|
|
|
|
|
printf("open erro 25"); exit(0);
|
|
|
|
|
}
|
|
|
|
|
for(int k=0;k<num;k++)
|
|
|
|
|
{
|
|
|
|
|
fprintf(p,"%s %s %s %d %s %d %d\n",x[k].id,x[k].name,x[k].xinghao,x[k].price,x[k].from,x[k].cun,x[k].yiding);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("你是否还要购买其他的产品?\n1.是\n2.不是\n");
|
|
|
|
|
int kkk;scanf("%d",&kkk);
|
|
|
|
|
|
|
|
|
|
switch(kkk)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
fclose(p);
|
|
|
|
|
fclose(q);
|
|
|
|
|
fclose(z);
|
|
|
|
|
buy();
|
|
|
|
|
break;
|
|
|
|
|
default:printf("欢迎您下次继续加购\n");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:system("cls");printf("欢迎您下次继续光临\n");break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if(i==num-1) printf("没有查到此商品\n");
|
|
|
|
|
}
|
|
|
|
|
fclose(p);
|
|
|
|
|
fclose(q);
|
|
|
|
|
fclose(z);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
void present_all()//展示商品信息//
|
|
|
|
|
{
|
|
|
|
|
FILE *p,*q;
|
|
|
|
|
int num;
|
|
|
|
|
if((p=fopen("商品信息.txt","r"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("open erro 25"); exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if((q=fopen("商品数量.txt","r"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("open erro 35"); exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fscanf(q,"%d",&num);
|
|
|
|
|
shop x[50];
|
|
|
|
|
for(int i=0;i<num;i++)
|
|
|
|
|
{
|
|
|
|
|
fscanf(p,"%s%s%s%d%s%d%d",&x[i].id,&x[i].name,&x[i].xinghao,&x[i].price,&x[i].from,&x[i].cun,&x[i].yiding);
|
|
|
|
|
printf("编号:%2s 名字:%6s 型号:%3s 价格:%3d 产地:%s 存货:%d 已定:%d\n",x[i].id,x[i].name,x[i].xinghao,x[i].price,x[i].from,x[i].cun,x[i].yiding);
|
|
|
|
|
}
|
|
|
|
|
fclose(p);
|
|
|
|
|
fclose(q);
|
|
|
|
|
}
|
|
|
|
|
void present_kehu() //展示客户信息//
|
|
|
|
|
{
|
|
|
|
|
FILE *p;
|
|
|
|
|
system("cls");
|
|
|
|
|
printf("-------全部客户信息-------\n");
|
|
|
|
|
if((p=fopen("客户信息.txt","r"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("erro 169"); exit(0);
|
|
|
|
|
}
|
|
|
|
|
info x;
|
|
|
|
|
while((fscanf(p,"%s%s%s",&x.place,&x.call,&x.thing))!=EOF)
|
|
|
|
|
printf("地址:%s 电话:%s 商品:%s\n",x.place,x.call,x.thing);
|
|
|
|
|
|
|
|
|
|
fclose(p);
|
|
|
|
|
}
|
|
|
|
|
|