commit
8780ccafd6
@ -0,0 +1,300 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
#define SIZE 100
|
||||
struct product//数据结构
|
||||
{
|
||||
long number; //商品编号
|
||||
char name[20]; //商品名称
|
||||
float inprice; //商品进价
|
||||
float outprice; //商品售价
|
||||
int count; //商品数量
|
||||
} ;
|
||||
int main(){
|
||||
FILE *fp;
|
||||
void Remined();//打印清单函数声明
|
||||
void menu();//菜单函数声明
|
||||
void In();//商品进库管理函数声明
|
||||
void Out();//商品出库管理函数声明
|
||||
void Add();//创建新商品信息函数声明
|
||||
void Del();//清楚商品信息函数声明
|
||||
void Sale();//销售统计函数声明
|
||||
void Exit();//退出函数声明
|
||||
fp=fopen("商品信息","a+");//创建商品信息文件
|
||||
fclose(fp);
|
||||
fp=fopen("清单","w+");//创建清单文件
|
||||
fclose(fp);
|
||||
menu();
|
||||
}
|
||||
|
||||
//增加新商品函数
|
||||
void Add(){
|
||||
FILE *fp;
|
||||
char m;
|
||||
struct product inf;
|
||||
void menu();
|
||||
//录入各个信息
|
||||
printf("请输入商品编号\n");//编号
|
||||
scanf("%ld",&inf.number);
|
||||
printf("请输入商品数量\n");//数量
|
||||
scanf("%d",&inf.count);
|
||||
printf("请输入商品进价\n");
|
||||
scanf("%f",&inf.inprice);
|
||||
printf("请输入商品售价\n");
|
||||
scanf("%f",&inf.outprice);
|
||||
printf("请输入商品名称\n");
|
||||
scanf("%s",&inf.name);
|
||||
fp=fopen("商品信息","a+");
|
||||
if(fp==NULL)
|
||||
printf("");
|
||||
fwrite(&inf,sizeof(struct product),1,fp);
|
||||
fclose(fp);
|
||||
//询问是否继续输入
|
||||
printf("是否继续输入? 是 输入'Y';返回主菜单 输入'N'\n");
|
||||
getchar();
|
||||
m=getchar();
|
||||
if(m=='Y'||m=='y')
|
||||
Add();
|
||||
if(m=='N'||m=='n')
|
||||
menu();
|
||||
}
|
||||
//进货模块
|
||||
void In(){
|
||||
FILE *fp;
|
||||
void menu();
|
||||
int i,b;
|
||||
char m;
|
||||
long number;
|
||||
int count;
|
||||
struct product inf[SIZE];
|
||||
struct product inf1;
|
||||
//输入商品的各种信息
|
||||
fp=fopen("商品信息","r");
|
||||
if((fp=fopen("商品信息","r"))==NULL)
|
||||
printf("打开商品信息文件出错\n");
|
||||
printf("请输入商品编号\n");//编号
|
||||
scanf("%ld",&number);
|
||||
printf("请输入商品数量\n");//数量
|
||||
scanf("%d",&count);
|
||||
//将所有信息从文件中读出,进行修改
|
||||
i=0;
|
||||
while(fread(&inf1,sizeof(struct product),1,fp)!=(int)NULL){
|
||||
if(inf1.number!=number){
|
||||
inf[i].number=inf1.number;
|
||||
strcpy(inf[i].name,inf1.name);
|
||||
inf[i].inprice=inf1.inprice;
|
||||
inf[i].outprice=inf1.outprice;
|
||||
inf[i].count=inf1.count;
|
||||
i++;
|
||||
}
|
||||
else{
|
||||
inf[i].number=inf1.number;
|
||||
inf[i].inprice=inf1.inprice;
|
||||
inf[i].outprice=inf1.outprice;
|
||||
inf[i].count=count+inf1.count;
|
||||
strcpy(inf[i].name,inf1.name);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
if((fp=fopen("商品信息","w+"))==NULL)
|
||||
printf("打开商品信息文件出错\n");
|
||||
for(b=0;b<i;b++){
|
||||
if(fwrite(&inf[b],sizeof(struct product),1,fp)==!1)
|
||||
printf("写入商品信息文件出错\n");
|
||||
} fclose(fp);
|
||||
//询问是否继续输入
|
||||
printf("是否继续输入? 是 输入'Y';返回主菜单 输入'N'\n");
|
||||
getchar();
|
||||
m=getchar();
|
||||
if(m=='Y'||m=='y')
|
||||
In();
|
||||
if(m=='N'||m=='n')
|
||||
menu();
|
||||
}
|
||||
//出货模块
|
||||
void Out(){
|
||||
FILE *fp;
|
||||
void menu();
|
||||
char m;
|
||||
float money=0;
|
||||
long number;
|
||||
int count,i,b;
|
||||
struct product inf[SIZE],inf1;
|
||||
struct product list;
|
||||
//输入商品的各种信息
|
||||
if((fp=fopen("商品信息","rb"))==NULL)
|
||||
printf("打开商品信息文件出错\n");
|
||||
printf("请输入商品编号\n");//编号
|
||||
scanf("%ld",&number);
|
||||
printf("请输入商品数量\n");//数量
|
||||
scanf("%d",&count);
|
||||
i=0;
|
||||
while(fread(&inf1,sizeof(struct product),1,fp)!=(int)NULL){
|
||||
if(inf1.number!=number){
|
||||
inf[i].number=inf1.number;
|
||||
strcpy(inf[i].name,inf1.name);
|
||||
inf[i].inprice=inf1.inprice;
|
||||
inf[i].outprice=inf1.outprice;
|
||||
inf[i].count=inf1.count;
|
||||
i++;
|
||||
}
|
||||
else{
|
||||
inf[i].number=number;
|
||||
inf[i].inprice=inf1.inprice;
|
||||
inf[i].outprice=inf1.outprice;
|
||||
inf[i].count=(inf1.count-count);
|
||||
strcpy(inf[i].name,inf1.name);
|
||||
list.number=number;
|
||||
list.count=count;
|
||||
list.inprice=inf1.inprice;
|
||||
list.outprice=inf1.outprice;
|
||||
strcpy(list.name,inf1.name);
|
||||
money=(list.count)*(list.outprice);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
if((fp=fopen("商品信息","w+"))==NULL)
|
||||
printf("打开商品信息文件出错\n");
|
||||
for(b=0;b<i;b++){
|
||||
if(fwrite(&inf[b],sizeof(struct product),1,fp)==(int)NULL)
|
||||
printf("写入商品信息文件出错\n");
|
||||
} fclose(fp);
|
||||
fp=fopen("清单","a+");
|
||||
fwrite(&list,sizeof(struct product),1,fp);
|
||||
fclose(fp);
|
||||
printf("是否打印本次清单?是 输入'Y';返回主菜单 输入'N'\n");
|
||||
getchar();
|
||||
m=getchar();
|
||||
if(m=='y'||m=='Y')
|
||||
printf("商品编号 商品名称 进价 售价 金额\n");
|
||||
printf("%3l%s%3.lf%3.lf\n",list.number,list.name,list.inprice,list.outprice,money);
|
||||
printf("是否继续输入?是 输入'Y'或'y';否 输入'N'或'n'\n");
|
||||
getchar();
|
||||
m=getchar();
|
||||
if(m=='y'||m=='Y')
|
||||
Out();
|
||||
if(m=='N'||m=='n')
|
||||
menu();
|
||||
}
|
||||
|
||||
//清除模块
|
||||
void Del(){
|
||||
int i,b;
|
||||
void menu();
|
||||
long number;
|
||||
struct product inf[SIZE],infd;
|
||||
char m;
|
||||
FILE *fp;
|
||||
printf("请输入商品编号\n"),
|
||||
scanf("%ld",&number);
|
||||
fp=fopen("商品信息","r");
|
||||
if(fp=NULL)
|
||||
printf("打开文件出错\n");
|
||||
//将文件内容读出后重新写入
|
||||
i=0;
|
||||
while(fread(&infd,sizeof(struct product),1,fp)!=(int)NULL)
|
||||
{
|
||||
if(infd.number!=number){
|
||||
inf[i].number=infd.number;
|
||||
inf[i].count=infd.count;
|
||||
inf[i].inprice=infd.inprice;
|
||||
inf[i].outprice=infd.outprice;
|
||||
strcpy(inf[i].name,infd.name);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
if(fopen("商品信息","w+")==NULL)
|
||||
printf("打开商品信息文件出错\n");
|
||||
for(b=0;b<i;b++)
|
||||
if(fwrite(&inf[b],sizeof(struct product),1,fp)==1)
|
||||
printf("写入商品信息文件出错\n");
|
||||
fclose(fp);
|
||||
//询问是否继续输入
|
||||
printf("是否继续输入?是 输入'Y'或'y';否 输入'N'或'n'\n");
|
||||
getchar();
|
||||
m=getchar();
|
||||
if(m=='Y'||m=='y')
|
||||
Del();
|
||||
if(m=='N'||m=='n')
|
||||
menu();
|
||||
}
|
||||
//退出模块
|
||||
void Exit(){
|
||||
char m;
|
||||
void menu();
|
||||
printf("是否确认? 是 输入'Y'或'y';否 输入'N'或'n'\n");
|
||||
getchar();
|
||||
m=getchar();
|
||||
if(m=='Y'||m=='y')
|
||||
exit(1);
|
||||
if(m=='N'||m=='n')
|
||||
menu();
|
||||
}
|
||||
//清单模块
|
||||
void Sale()
|
||||
{
|
||||
char m;
|
||||
void menu();
|
||||
struct product list;
|
||||
FILE *fp;
|
||||
printf("确认打印?是 输入y; 不是输入n\n");
|
||||
getchar();
|
||||
m=getchar();
|
||||
if(m=='Y'||m=='y'){
|
||||
fp=fopen("清单","r");
|
||||
printf("商品名称 商品编号 商品售价 总金额 销售数量\n");
|
||||
while(fread(&list,sizeof(struct product),1,fp)!=(int)NULL)
|
||||
printf("%s %5ld %3.lf %3.lf %d\n",list.name,list.number,list.outprice,(list.count*list.outprice),list.count);
|
||||
}
|
||||
printf("按任意键返回菜单\n");
|
||||
getchar();
|
||||
getchar();
|
||||
menu();
|
||||
if(m=='n'||m=='N')
|
||||
menu();
|
||||
}
|
||||
//显示库存函数
|
||||
void Remined(){
|
||||
struct product list1;
|
||||
FILE *fp;
|
||||
void menu();
|
||||
fp=fopen("商品信息","r");
|
||||
printf("商品编号 商品名称 商品进价 商品售价 库存量\n");
|
||||
while(fread(&list1,sizeof(struct product),1,fp)!=(int)NULL)
|
||||
printf("%ld %s %f %f %d\n",list1.number,list1.name,list1.inprice,list1.outprice,list1.count);
|
||||
printf("按任意键返回菜单\n");
|
||||
getchar();
|
||||
getchar();
|
||||
menu();
|
||||
}
|
||||
void menu()//菜单模块
|
||||
{
|
||||
int choice;
|
||||
printf("#######################################################################\n");
|
||||
printf("# #\n");
|
||||
printf("#------------------欢 迎 来 到 商 店 销 售 管 理 系 统----------------#\n");
|
||||
printf("# #\n");
|
||||
printf("#######################################################################\n");
|
||||
printf("请输入你要使用的功能编号\n");
|
||||
printf("0-------------退出\n");
|
||||
printf("1-------------商品进库管理\n");
|
||||
printf("2-------------商品出库管理\n");
|
||||
printf("3-------------创建新商品信息\n");
|
||||
printf("4-------------清除商品信息\n");
|
||||
printf("5-------------销售统计\n");
|
||||
printf("6-------------显示库存量\n");
|
||||
scanf("%d",&choice);
|
||||
switch(choice){
|
||||
case 0:Exit();
|
||||
case 1:In();break;
|
||||
case 2:Out();break;
|
||||
case 3:Add();break;
|
||||
case 4:Del();break;
|
||||
case 5:Sale();break;
|
||||
case 6:Remined();break;
|
||||
default:main();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue