|
楼主 |
发表于 2021-1-4 19:41:37
|
显示全部楼层
#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
int bgnumber = 023; //客户号
int inumber = 0; //商品量的统计
int ibuy = 0; //订单的统计
void secondmain(); //管理维护子菜单
void jianpanload(); //输入商品
void scanproduct(); //浏览商品
void searchproduct(); //搜索商品
void dinggou(); //订购商品
void lookdinggou(); //查询订单
void addproduct(); //增加商品
void deleteproduct(); //删除商品
void saveproduct(); //保存商品
void savedinggou(); //保存订单
void wenbenload(); //从文本导入商品
struct product { char name[30]; //商品名
int number; //货号
char vender[30]; //厂家
char filed[100]; //产地
int stock; //存量
double unvalent}; //单价 ;
struct product a[100];
struct dinggou { int bgname; //货号
int bmany; //订购量
int btime; //日期时间
char bname[100]; //客户名
char baddress[100]; //客户地址
int bnumber}; //客户号;
struct dinggou b[100];
int main(void) {
int i;
wenbenload();
do
{ system("cls");
printf("\n\n\n\n\n\n");
printf("**************************欢迎使用商品订购系统v1.0******************************\n");
printf(" 作者: \n");
printf(" ┏━━━━━━━━━━━━━━━━━━━━━━┓ \n");
printf(" ┃ 1.浏览商品信息 ┃ \n");
printf(" ┃ 2.订购商品 ┃ \n");
printf(" ┃ 3.订单查询 ┃ \n");
printf(" ┃ 4.搜索商品 ┃ \n");
printf(" ┃ 5.管理菜单 ┃ \n");
printf(" ┃ 0.退出系统 ┃ \n");
printf(" ┗━━━━━━━━━━━━━━━━━━━━━━┛ \n");
printf("********************************************************************************\n");
printf("\n\n\t\t请输入你的操作(0~5): ");
scanf("%d",&i);
switch(i) {
case 1: system("cls"); scanproduct(); break;
case 2: system("cls"); dinggou(); break;
case 3: system("cls"); lookdinggou(); break;
case 4: searchproduct(); break;
case 5: secondmain(); break;
case 0: //退出系统的界面
system("cls");
printf("\n\n\n\n\n\n\n\n");
printf("\n\n\t\t\t欢迎使用本系统\n\n\n\n\n\t\t\t欢迎再次使用\n");
exit(0); //exit用于在程序运行的过程中随时结束程序
}
}while(1);
return 0;
}
//浏览商品
void scanproduct()
{
int i;
system("cls");
printf("\t\t\t\t\t商品信息列表\n");
for (i = 0; i < inumber; i++)
{
printf("名称 : %s\n",a[i].name);
printf("货号 : %d\n",a[i].number);
printf("厂家 : %s\n",a[i].vender);
printf("产地 : %s\n",a[i].filed);
printf("存量 : %d\n",a[i].stock);
printf("单价 : %.2lf\n\n\n",a[i].unvalent);
}
printf("\n\n\n\n\n\n\t\t\t");
printf("返回主菜单\n");
printf("\t\t\t");
system("pause");
return;
} //商品的订购
void dinggou()
{
char ch;
int i, j, t, c = 1;
int n = 1;
int m = 0;
do
{
switch(n)
{
case 1: system("cls");
printf("\t\t\t\t商品信息列表\n"); //显示商品的名称、货号信息,以便于订购
printf("名称\t 货号\t 库存\n");
for (i = 0; i < inumber; i++)
{
printf("%s\t %d\t %d\n\n\n",a[i].name,a[i].number,a[i].stock);
}
printf("\n\n\n");
printf("\t\t\t\t商品订单\n");
printf("\n\t\t\t请输入你的第%d个订单信息:\n",m + 1);
printf("\n\t\t\t货号:"); fflush(stdin);
scanf("%d",&b[ibuy].bgname); //检测是否含有此商品
j = 1;
for (i = 0; i < inumber; i++)
{
if(a[i].number == b[ibuy].bgname)
{
j = 0;
t = i;
}
} //若有商品继续购买项目
if(j == 0)
{ printf("\n\t\t\t订购量:");
fflush(stdin);
scanf("%d",&b[ibuy].bmany);
if (a[t].stock >= b[ibuy].bmany)
{ a[t].stock = a[t].stock - b[ibuy].bmany; //顾客购买后商品的库存计算
printf("\n\t\t\t日期时间:");
fflush(stdin);
scanf("%d",&b[ibuy].btime);
printf("\n\t\t\t客户名:");
fflush(stdin);
gets(b[ibuy].bname);
printf("\n\t\t\t客户地址:");
fflush(stdin);
gets(b[ibuy].baddress);
printf("\n\t\t\t客户号:");
b[ibuy].bnumber = bgnumber;
printf("%d\n",b[ibuy].bnumber);
bgnumber++;
ibuy++;
m++;
printf("\n\n\n\t\t\t\t");
system("pause");
}
else
{
printf("\n\n\t\t\t订购数目超出库存\n");
printf("\t\t\t");
system("pause");
}
} //若没有商品的提示及操作
else
{
printf("\n\n\t\t\t查无此货\n");
printf("\t\t\t");
system("pause");
}
case 2:
printf("是否继续输入订购?(Y/N)");
fflush(stdin);
scanf("%c",&ch);
if(ch == 'N' || ch == 'n')
{
c = 0;
break;
}
else if(ch == 'Y' || ch == 'y')
{
c = 0;
n = 1;
break;
}
else if(ch != 'n' || ch != 'N' || ch != 'Y' || ch != 'y')
{
n = 0;
c = 1;
break;
}
case 0:
if(c == 1)
{
n = 2;
}
}
}while(ch != 'n' && ch != 'N');
system("cls");
return ;
} //订单的查询
void lookdinggou()
{
int i;
system("cls");
printf("\t\t\t\t\t订单列表\n");
for (i = 0; i < ibuy; i++)
{
printf("货号 : %d\n",b[i].bgname);
printf("订购量 : %d\n",b[i].bmany);
printf("日期时间 : %d\n",b[i].btime);
printf("客户名 : %s\n",b[i].bname);
printf("客户地址 : %s\n",b[i].baddress);
printf("客户号 : %d\n\n\n",b[i].bnumber);
}
printf("\n\n\n\n\n\n\t\t\t");
printf("返回主菜单\n");
printf("\t\t\t");
system("pause");
return;
} //增加商品
void addproduct()
{ char ch;
int i=1;
int n = 1;
do
{
switch(n)
{
case 1:
system("cls");
printf("\t\t\t\t商品信息的增加\n");
printf("\t\t\t\t\t注:要重新输入已有及增加的商品\n");
printf("\n\t\t\t请输入你的第%d件商品的信息:\n",i);
printf("\n\t\t\t名称:");
fflush(stdin);
scanf("%s",a[inumber].name);
printf("\n\t\t\t货号:");
fflush(stdin);
scanf("%d",&a[inumber].number);
printf("\n\t\t\t厂家:");
fflush(stdin);
scanf("%s",a[inumber].vender);
printf("\n\t\t\t产地:");
fflush(stdin);
scanf("%s",a[inumber].filed);
printf("\n\t\t\t存量:");
fflush(stdin);
scanf("%d",&a[inumber].stock);
printf("\n\t\t\t单价:");
fflush(stdin);
scanf("%lf",&a[inumber].unvalent);
i++;
inumber++;
case 2:
printf("是否继续输入记录?(Y/N)");
fflush(stdin);
scanf("%c",&ch);
if(ch == 'N' || ch ==' Y'|| ch == 'n'|| ch == 'y')
{
break;
}
if(ch ==' Y'|| ch == 'y')
{
n = 1;
break;
}
case 0:
printf("是否继续输入记录?(Y/N)");
fflush(stdin);
scanf("%c",&ch);
n = 2;
}
}while(ch != 'n' && ch != 'N');
return;
} //删除商品
void deleteproduct()
{
int i;
int j;
char ch;
int n = 1;
do
{
switch(n)
{
case 1:
system("cls");
printf("\t\t\t\t商品列表\n"); //显示商品的名称、货号信息,以便于下部的删除
for (i = 0; i < inumber; i++)
{
printf("名称 : %s\n",a[i].name);
printf("ID : %d\n",i);
printf("库存 : %d\n\n\n",a[i].stock);
} //商品的搜索
printf("\n\n\n\t\t\t\t请输入你要删除商品的ID:");
scanf("%d",&j);
i = j;
while(i < inumber - 1)
{
strcpy(a[i].name, a[i + 1].name);
a[i].number = a[i + 1].number;
strcpy(a[i].filed, a[i + 1].filed);
a[i].stock = a[i + 1].stock;
a[i].unvalent = a[i + 1].unvalent;
strcpy(a[i].vender, a[i + 1].vender);
i++;
}
inumber--;
case 2:
printf("是否继续删除商品?(Y/N)");
fflush(stdin);
scanf("%c",&ch);
if(ch == 'N' || ch ==' Y'|| ch == 'n'|| ch == 'y')
{
break;
}
if(ch ==' Y'|| ch == 'y')
{
n = 1;
break;
}
case 0:
printf("是否继续输入记录?(Y/N)");
fflush(stdin);
scanf("%c",&ch);
n = 2;
}
}while(ch != 'n' && ch != 'N');
printf("\n\n\n\n\n\n\t\t\t");
printf("返回附加功能菜单\n");
printf("\t\t\t");
system("pause");
return;
} //商品信息的保存
void saveproduct()
{
FILE *fpgoods;
int i;
fpgoods = fopen("goodsinfo.out","w");
assert(fpgoods != NULL);
fprintf(fpgoods,"\t\t\t\t\t\t商品信息列表\n"); //商品信息的录入
for (i = 0; i < inumber; i++)
{
fprintf(fpgoods,"名称: %s\n",a[i].name);
fprintf(fpgoods,"货号: %d\n",a[i].number);
fprintf(fpgoods,"厂家: %s\n",a[i].vender);
fprintf(fpgoods,"产地: %s\n",a[i].filed);
fprintf(fpgoods,"存量: %d\n",a[i].stock);
fprintf(fpgoods,"单价: %.2lf\n\n\n",a[i].unvalent);
}
fclose(fpgoods);
system("cls");
printf("\n\n\n\n\n\n\t\t\t\t商品信息保存成功!!!\n");
printf("\t\t\t\t");
system("pause");
return;
} //订单的保存信息
void savedinggou()
{
FILE *fpgoods;
int i;
fpgoods = fopen("bookrecordinfo.out","w");
assert(fpgoods != NULL);
fprintf(fpgoods,"\t\t\t\t\t\t订单列表\n");
//商品信息的录入
for (i = 0; i < ibuy; i++)
{
fprintf(fpgoods,"货号 :%d\n",b[i].bgname);
fprintf(fpgoods,"订购量 :%d\n",b[i].bmany);
fprintf(fpgoods,"日期时间 :%d\n",b[i].btime);
fprintf(fpgoods,"客户名 :%s\n",b[i].bname);
fprintf(fpgoods,"客户地址 :%s\n",b[i].baddress);
fprintf(fpgoods,"客户号 :%d\n\n\n",b[i].bnumber);
}
fclose(fpgoods); //保存后信息的反馈
system("cls");
printf("\n\n\n\n\n\n\t\t\t\t信息保存成功!!!\n");
printf("\t\t\t\t"); system("pause");
return;
} //管理维护子菜单
void secondmain()
{
int i;
do
{
system("cls");
printf("\n\n\n\n\n\n\n");
printf("******************************管理维护子菜单************************************\n\n");
printf(" ┏━━━━━━━━━━━━━━━━━━━┓\n");
printf(" ┃ 1.输入全部商品 ┃\n");
printf(" ┃ 2.增加商品 ┃\n");
printf(" ┃ 3.删除商品 ┃\n");
printf(" ┃ 4.储存商品 ┃\n");
printf(" ┃ 5.储存订单 ┃\n");
printf(" ┃ 0.返回上一级 ┃\n");
printf(" ┗━━━━━━━━━━━━━━━━━━━┛\n\n\n");
printf("********************************************************************************\n\n\n\n\n");
printf("\n\n\t\t请输入你所要选择的功能(0~5): ");
scanf("%d",&i);
switch(i)
{
case 1:
system("cls");
jianpanload ();
break;
case 2:
system("cls");
addproduct();
break;
case 3:
system("cls");
deleteproduct();
break;
case 4:
system("cls");
saveproduct();
break;
case 5:
system("cls");
savedinggou();
break;
case 0:
system("cls");
return ;
}
}while(1);
printf("\t\t\t\t");
system("pause");
system("cls");
return;
} //从键盘输入商品
void jianpanload()
{
char ch;
int n = 1;
inumber = 0;
do
{
switch(n)
{
case 1:
//商品的录入
system("cls");
printf("\t\t\t\t请重新输入全部商品信息\n");
printf("\n\t\t\t请输入第%d件商品的信息:\n",inumber + 1);
printf("\n\t\t\t名称:");
fflush(stdin);
gets(a[inumber].name);
printf("\n\t\t\t货号:");
fflush(stdin);
scanf("%d",&a[inumber].number);
printf("\n\t\t\t厂家:");
fflush(stdin);
gets(a[inumber].vender);
printf("\n\t\t\t产地:");
fflush(stdin);
gets(a[inumber].filed);
printf("\n\t\t\t存量:");
fflush(stdin);
scanf("%d",&a[inumber].stock);
printf("\n\t\t\t单价:");
fflush(stdin);
scanf("%lf",&a[inumber].unvalent);
inumber++;
fflush(stdin);
case 2:
printf("是否继续输入记录?(Y/N)");
fflush(stdin);
scanf("%c",&ch);
if(ch == 'N' || ch ==' Y'|| ch == 'n'|| ch == 'y')
{
break;
}
if(ch ==' Y'|| ch == 'y')
{
n = 1;
break;
}
case 0:
printf("是否继续输入记录?(Y/N)");
fflush(stdin);
scanf("%c",&ch);
n = 2;
}
}while(ch != 'n' && ch != 'N');
return;
} //导入商品信息
void wenbenload()
{ FILE *fp;
char ch[30];
double dou;
int in;
int i = 0;
inumber = 0;
fp = fopen("goodsinfo.out","r");
assert(fp); //从文件中导入商品信息
fscanf(fp,"%s",&ch);
while(fscanf(fp,"%s",&ch) != EOF)
{
fscanf(fp, "%s", &ch);
strcpy(a[inumber].name, ch);
fscanf(fp,"%s",&ch);
fscanf(fp,"%d",&in);
a[inumber].number = in;
fscanf(fp,"%s",&ch);
fscanf(fp,"%s",&ch);
strcpy(a[inumber].vender, ch);
fscanf(fp,"%s",&ch);
fscanf(fp,"%s",&ch);
strcpy(a[inumber].filed, ch);
fscanf(fp,"%s",&ch);
fscanf(fp,"%d",&in);
a[inumber].stock = in;
fscanf(fp,"%s",&ch);
fscanf(fp,"%lf",&dou);
a[inumber].unvalent = dou; inumber++; } fclose (fp);
return;
} //搜索商品
void searchproduct()
{
int i;
int j;
char ch;
int n = 1;
do
{
switch(n)
{
case 1:
system("cls");
printf("\t\t\t\t商品列表\n");
//显示商品的名称、货号信息,以便于下部的删除
for (i = 0; i < inumber; i++)
{
printf("名称 : %s\n",a[i].name);
printf("ID : %d\n",i);
printf("库存 : %d\n\n\n",a[i].stock);
}
//商品的搜索
printf("\n\n\n\t\t\t\t请输入你要搜索商品的ID:");
scanf("%d",&j);
if(0<=j&&j<=inumber)
{
printf("名称 : %s\n",a[j].name);
printf("货号 : %d\n",a[j].number);
printf("厂家 : %s\n",a[j].vender);
printf("产地 : %s\n",a[j].filed);
printf("存量 : %d\n",a[j].stock);
printf("单价 : %.2lf\n\n\n",a[j].unvalent);
}
case 2:
printf("是否继续搜索商品?(Y/N)");
fflush(stdin);
scanf("%c",&ch);
if(ch == 'N'|| ch == 'n')
{
break;
}
if(ch ==' Y'|| ch == 'y')
{
n = 1;
break;
}
}
}while(ch != 'n' && ch != 'N');
printf("\n\n\n\n\n\n\t\t\t");
printf("返回主菜单!\n");
printf("\t\t\t");
system("pause");
return;
} |
|