From 4828e673260ee36d82bef54594e71dfe99da4677 Mon Sep 17 00:00:00 2001 From: "18408000311@stu.hut.edu.cn" <18408000311@stu.hut.edu.cn> Date: Thu, 10 Jan 2019 08:36:50 +0800 Subject: [PATCH] first commit --- hahaha.c | 301 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 301 insertions(+) create mode 100644 hahaha.c diff --git a/hahaha.c b/hahaha.c new file mode 100644 index 0000000..542ebcd --- /dev/null +++ b/hahaha.c @@ -0,0 +1,301 @@ +#include +#include +#include +#define SIZE 100 +struct product//数据结构 +{ + long number; //商品编号 + char name[20]; //商品名称 + float inprice; //商品进价 + float outprice; //商品售价 + int count; //商品数量 + } ; + int main(){ + system("color 8A"); + 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