超市商品管理系统(含附源代码)
- 格式:doc
- 大小:99.50 KB
- 文档页数:18
实验题目:超市管理系统一、实验目的1.熟悉 c 语言的编译连接和运行过程。
2.掌握 c 语言的数据类型,熟悉整型、实型、字符型变量的定义方式及如何给它们赋值。
3.掌握if 语句及switch 语句的运用方法及嵌套应用方法。
4.掌握实现循环结构的三种语句while 、do-while. 、for 的使用。
5.掌握函数的定义方法和调用方法。
6.能够采用模块化思想调试程序。
二.实验内容1.编写程序并进行调试运行。
2.输入商品资料,并保存于文件。
每件商品包含信息如:商品号、商品名、商品类别、商品总量、商品上限和下限、商品价格、进货日期、生产日期、保质期等。
3.对已存入的商品信息进行更新操作,包括添加一件商品信息、删除某件商品信息和修改商品信息。
4.通过按商品名、商品种类、商品进货量的方式查询商品信息。
5.输入某商品号后对其利润进行统计、对进货价格相同的商品进行统计。
6 对商品的库存量和利润进行排序。
7.最后输出商品信息,供需要时打印。
二、需求分析1.该程序可用于对商品的基本信息的存储、更新、查询、输出、统计、排序等操作,以实现管理者对商品的管理和消费者对商品的了解。
2.其中更新功能包括:添加信息、删除信息、修改信息、可根据需要添加一个或多件商品信息,也可对个别商品信息进行适当的删除或修改。
以便随时更新商品信息。
3.程序中设计的查询功能可根据需要从若干数据中查询某件商品信息,并且可根据三种不同的方法查询:按商品名查询、按商品种类查询和按商品进货量查询。
以满足不同的需要。
四、概要设计1、方案设计对系统进行分析,给出结构图分析:系统要求实现许多的功能,因此遵循结构化程序设计思想来进行本系统的设计—自顶向下、逐步细化,将系统设计任务分解出许多子功能模块进行设计结构图如下:超市管理管理系统查询模块排序模块退出系统退出系统查询模块排序模块统计模块*更新模块*输出信息¥录入信息按商品名查询利润排行库存量排行退出系统第二类商品第一类商品退出系统2 •功能模块说明:对各个模块进行功能的描述(1).输入模块:录入需要管理的商品信息并将信息保存于文件中,以方便日后进行打印、读取、更新等操作。
软件工程课程设计题目:超市前台POS销售系统及后台管理系统专业:班级:学号:姓名:指导老师:目录:一、问题定义 (3)1.系统开发目的 (3)2.背景说明 (3)3.项目确立 (3)4.应用范围 (3)5.名词定义 (3)二、可行性研究 (4)1.管理可行性分析 (4)2.经济可行性分析 (4)3.技术可行性分析 (4)4. 系统初步ER图 (5)5.可行性研究结论 (5)三、需求分析 (5)1. 用户需求分析 (5)2. 系统功能分析 (6)3. 系统结构 (7)4. 流程图 (7)5. 系统ER图 (9)四、设计 (1)1.系统模型: (1)2.模块子系统结构: (3)五、测试 (5)1. 测试过程分析: (5)2 .测试方案: (6)4. 测试结果 (9)5. 评估和建议 (9)六、实现 (10)七、维护 (10)八、总结 (10)一、问题定义1.系统开发目的1.大大提高超市的运作效率;2.通过全面的信息采集和处理,辅助提高超市的决策水平;3.使用本系统,可以迅速提升超市的管理水平,为降低经营成本,提高效益,增强超市扩张力,提供有效的技术保障。
2.背景说明21世纪,超市的竞争也进入到了一个全新的领域,竞争已不再是规模的竞争,而是技术的竞争、管理的竞争、人才的竞争。
技术的提升和管理的升级是超市业的竞争核心。
零售领域目前呈多元发展趋势,多种业态:超市、仓储店、便利店、特许加盟店、专卖店、货仓等相互并存。
如何在激烈的竞争中扩大销售额、降低经营成本、扩大经营规模,成为超市营业者努力追求的目标。
3.项目确立针对超市的特点,为了帮助超市解决现在面临的问题,提高小型超市的竞争力,我们将开发以下系统:前台POS销售系统、后台管理系统,其中这两个子系统又包含其它一些子功能。
4.应用范围本系统适应于各种超市。
5.名词定义①商品条形码:每种商品具有唯一的条形码,对于某些价格一样的商品,可以使用自定义条形码。
②交易清单:包括交易的流水账号、每类商品的商品名、数量、该类商品的总金额、交易的时间、负责本次收银的员工号。
商品订购系统设计完整代码以下是一个商品订购系统的设计完整代码示例:```pythonimport jsonclass Product:def __init__(self, id, name, price):self.id = id = nameself.price = priceclass Order:def __init__(self, id, products):self.id = idself.products = productsdef calculate_total(self):total = 0for product in self.products:total += product.pricereturn totalclass OrderSystem:def __init__(self):self.products = []self.orders = []def add_product(self, product):self.products.append(product)def create_order(self, product_ids): order_products = []for id in product_ids:for product in self.products:if product.id == id:order_products.append(product)breakorder_id = len(self.orders) + 1order = Order(order_id, order_products) self.orders.append(order)return order_iddef get_order_total(self, order_id):for order in self.orders:if order.id == order_id:return order.calculate_totalreturn Nonedef save_to_file(self, filename): data ="products": [],"orders": []}for product in self.products:data["products"].append"id": product.id,"name": ,"price": product.price})for order in self.orders:order_product_ids = []for product in order.products:order_product_ids.append(product.id) data["orders"].append"id": order.id,"product_ids": order_product_ids})with open(filename, 'w') as file:json.dump(data, file)def load_from_file(self, filename):with open(filename, 'r') as file:data = json.load(file)for product_data in data["products"]:product = Product(product_data["id"], product_data["name"], product_data["price"])self.add_product(product)for order_data in data["orders"]:order_products = []for product_id in order_data["product_ids"]:for product in self.products:if product.id == product_id:order_products.append(product)order = Order(order_data["id"], order_products)self.orders.append(order)#创建商品订购系统示例order_system = OrderSystem#添加商品product_1 = Product(1, "苹果", 3)product_2 = Product(2, "香蕉", 2)product_3 = Product(3, "橙子", 4)order_system.add_product(product_1)order_system.add_product(product_2)order_system.add_product(product_3)#创建订单order_id = order_system.create_order([1, 3])#获取订单总价order_total = order_system.get_order_total(order_id) if order_total is not None:print(f"订单{order_id}总价为:{order_total}")else:print("订单不存在")#保存数据到文件order_system.save_to_file("order_data.json")#从文件加载数据order_system.load_from_file("order_data.json")```这个代码示例演示了一个简单的商品订购系统。
(店铺管理)超市进销存系统壹、进销存系统概述(壹)进销存管理信息系统简介进销存管理是商业企业运营管理中的核心环节,也是壹个企业能否取得效益的关键。
如果能做到合理生产、及时销售、库存量最小,减少积压,那么企业就能取得最佳的效益。
由此可见,进销存管理决策的正确和否直接影响了企业的经济效益。
在手工管理的情况下,销售人员很难对客户做出正确的供货承诺,同时企业的采购部也缺少壹份准确的采购计划,目前的库存及市场需求很难反应到采购中去,部门之间的通讯也经常不通畅,这在激烈竞争的市场中是非常不利的。
企业的进销存管理信息系统就是在这种情况下应运而生的。
它利用计算机技术,使得企业采购,库存和销售能够有利结合起来,供销衔接,提高企业的效率和效益。
(二)X公司简介及项目开发背景大连大兴商贸X公司是壹家以销售计算机及周边配件为主的中小型高科技贸易X公司,凭着其良好的销售业绩及雄厚的技术实力,X公司成为了多家国际知名品牌计算机的二级代理商。
该X公司货源主要来自其产业链上游的全国总代理或地区总代理,其客户主要是大连本地或本地周边的商业用户。
因此该X公司的货物吞吐量较大,而X公司目前进销存环节的操作均以人工作业为主,X公司的销售人员不清楚库存的数量,而采购员则又不能及时了解目前产品的销量,所有货品的出库、配送及入库均采用人工开单,办事效率低下,随着X公司业务的日益增长,整个物流环节的办事效率正逐渐成为X公司发展的瓶径。
因此,为了满足日益增长的业务需求,X公司决定开发壹套进销存管理信息系统,以提高办事效率,理顺物流环节。
X公司的组织机构图如图壹所示:图1X公司组织结构图(三)开发设计思想1.尽可能利用X公司现有的软硬件环境,及先进的管理系统开发方案,从而达到充分利用X公司现有资源,提高系统开发水平和应用效果的目的。
2.系统应符合采购、销售、库存的规定,满足X公司日常工作需要,且达到操作工程中的直观、方便、实用、安全等要求。
3.系统采用先进的俩层体系结构,客户端负责提供表达逻辑、显示用户界面信息,基本操作;服务器端负责实现数据服务。
python代码完成超市管理系统的设计与实现超市管理系统是一个相对复杂的系统,涵盖了商品管理、库存管理、销售管理、员工管理等多个模块。
以下是一个简化的超市管理系统的Python代码示例,主要实现了商品管理和销售管理两个功能。
pythonclass Product:def __init__(self, id, name, price, quantity):self.id = id = nameself.price = priceself.quantity = quantityclass Supermarket:def __init__(self):self.products = []def add_product(self, product):self.products.append(product)def sell_product(self, product_id, quantity):for product in self.products:if product.id == product_id:if product.quantity >= quantity:product.quantity -= quantityreturn quantity * product.priceelse:return "库存不足"return "商品不存在"# 示例supermarket = Supermarket()# 添加商品product1 = Product(1, "苹果", 5, 100)product2 = Product(2, "香蕉", 3, 50)supermarket.add_product(product1)supermarket.add_product(product2)# 销售商品print(supermarket.sell_product(1, 10)) # 输出 50print(supermarket.sell_product(2, 30)) # 输出 "库存不足"在这个示例中,我们定义了两个类:Product和Supermarket。
程序设计——超市管理系统学院:专业:班级:姓名:学号:指导老师:超市管理系统课程设计1)需求分析:设计题目:超市管理系统设计要求:有一个小型超市,出售N(N>=10)种商品,设计并实现一个系统系统功能需求分析:1.保存及输出:超市中的各种商品信息保存在指定文件中,可以把它们输出显示。
2.计算并排序:计算每类商品的总价值(sum,单精度)及平均价(aver,单精度,输出一位小数),将每类商品按平均价从大到小的顺序排序打印出来。
3.统计:统计输出库存量低于100的货号及类别。
统计输出有两种以上(含两种)商品库存量低于100的商品类别。
2)概要设计:系统总体设计框架:系统功能模块图:3)详细设计:主要功能模块的算法设计思路:本程序主要分为八个模块:主模块、信息输出修改模块、新建信息模块、排序模块、计算模块、统计模块1、统计模块2、打印模块。
1)主模块:通过调用各分模块实现功能;2)信息输出修改模块:输出显示文件中商品信息内容,添加商品信息,删除商品信息,修改商品信息;3)新建商品信息模块:建立一个新结构体,为链表存信息用,并且将信息保存在指定的文件中;4)排序模块:把文件中顺序零乱的商品信息按单价的大小从高到低进行排序,放到链表里存储;5)计算模块:将所有商品的价格与库存量进行累加求和;6)打印模块:将商品信息按每类平均价格排序(从高到低)按顺序打印出来;7)统计模块1:统计库存量低于100的货名及类别;8)统计模块2:统计商品库存量有2种以上(含2种)低于100的商品类别工作流程图:4)主要源程序代码:#include "stdio.h" /*输入,输出头文件*/ #include "stdlib.h" /*申请空间头文件*/#include "string.h" /*对字符串加工头文件*/ #include "conio.h" /*清屏头文件*/FILE *fp;int n=0; /*定义文件指针类型*/int i,j,a[4],m; /*定义整数类型*/float aver[4],sum[4],g[4],h; /*定义浮点类型*/char c[5]="elec"; /*定义字符数组类型*/ char d[5]="comm"; /*定义字符数组类型*/char e[5]="food"; /*定义字符数组类型*/char f[5]="offi"; /*定义字符数组类型*/struct good /*定义结构体*/{int num; /*商品编号*/char name[20]; /*商品名称*/char kind[40]; /*商品类型*/float price; /*商品价格*/char unit[10]; /*商品单位*/int quantity; /*商品数量*/struct good *next; /*定义结构体指针类型*/}*head,*p1,*p2;struct good *createlist() /*创建链表函数*/{struct good *head1,*p1,*p2; /*定义结构体指针类型*/if((fp=fopen("goods message.txt","w"))==NULL) /*判断能否打开文件*/ {printf("can not open the file");exit(0); /*结束程序*/}head1=(struct good *)malloc(sizeof(struct good)); /*申请头结点空间*/p1=head1;p2=head1;printf("*********************************************\n");printf("请输入信息:编号,名称,类型,价格,单位,数目\n");printf(" (以输入“-1”表示结束输入)\n");printf("*********************************************\n");printf("____________________\n");scanf("%d %s %s %f %s %d",&p1->num,p1->name,p1->kind,&p1->price,p1->unit,&p 1->quantity); /*输入商品信息*/printf("____________________\n");p1->next=NULL;fprintf(fp,"%d %s %s %f %s %d",p1->num,p1->name,p1->kind,p1->price,p1->unit,p1->quantity); /*将商品信息写入文件*/while(1){p1=(struct good *)malloc(sizeof(struct good)); /*申请新空间*/printf("*********************************************\n");printf("请输入信息:编号,名称,类型,价格,单位,数目\n");printf(" (以输入“-1”表示结束输入)\n");printf("*********************************************\n");printf("____________________\n");scanf("%d",&p1->num);if(p1->num==-1) /*申请空间结束条件*/{printf("____________________\n\n");fprintf(fp,"%d",-1);fclose(fp);return head1; /*返回头指针*/}scanf("%s %s %f %s %d",p1->name,p1->kind,&p1->price,p1->unit,&p1->quantity); /*输入商品信息*/printf("________________\n");fprintf(fp,"%d %s %s %f %s %d",p1->num,p1->name,p1->kind,p1->price,p1->unit,p1->quantity); /*将商品信息写入文件*/p1->next=NULL;p2->next=p1;p2=p1;}}struct good *paixu(struct good*head2) /*链表排序函数*/struct good *p6,*p7,*r,*s; /*定义结构体指针类型*/for(i=0;i<=3;i++) /*赋初值值*/{a[i]=0;sum[i]=0;aver[i]=0;}p6=(struct good *)malloc(sizeof(struct good)); /*申请新空间*/ p6->next=head2;head2=p6;while(p6->next!=NULL) /*判断循环结束条件*/{p7=p6->next;r=p6;while(p7->next!=NULL) /*判断循环结束条件*/{if((p7->next->price)>(r->next->price)) /*判断是否调换*/r=p7;p7=p7->next;}if(p6!=r) /*判断循环结束条件*/s=r->next; /*指针调换*/r->next=s->next;s->next=p6->next;p6->next=s;}p6=p6->next;}p6=head2;head2=head2->next;free(p6); /*释放第一个无效空间*/return head2;}void jisuan(){p1=head;do{if(strcmp(p1->kind,c)==0) /*判断是否为电器类型*/{sum[0]=sum[0]+(p1->price)*(p1->quantity); /*求电器总价*/ a[0]=a[0]+p1->quantity; /*求电器总件数*/}if(strcmp(p1->kind,d)==0) /*判断是否为日用品类型*/{sum[1]=sum[1]+(p1->price)*(p1->quantity); /*求日用品总价*/ a[1]=a[1]+p1->quantity; /*求日用品总件数*/}if(strcmp(p1->kind,e)==0) /*判断是否为办公用品类型*/{sum[2]=sum[2]+(p1->price)*(p1->quantity); /*求办公用品总价*/ a[2]=a[2]+p1->quantity; /*求办公用品总件数*/}if(strcmp(p1->kind,f)==0) /*判断是否为食品类型*/{sum[3]=sum[3]+(p1->price)*(p1->quantity); /*求食品总价*/a[3]=a[3]+p1->quantity; /*求食品总件数*/}p1=p1->next;}while (p1!=NULL); /*遍历链表结束条件*/for(i=0;i<4;i++)aver[i]=sum[i]/a[i]; /*求每类商品平均价*/printf("****************************************************\n"); printf("商品类型\t 平均价\t 总库存量\n");printf("****************************************************\n");printf("____________________________________________________\n"); printf("电器总价值:%0.1f\t平均价:%0.1f\t总库存量:%d\n",sum[0],aver[0],a[0]); printf("____________________________________________________\n"); printf("日用品总价值:%0.1f\t平均价:%0.1f\t总库存量:%d\n",sum[1],aver[1],a[1]); printf("____________________________________________________\n"); printf("食品总价值:%0.1f\t平均价:%0.1f\t总库存量:%d\n",sum[2],aver[2],a[2]); printf("____________________________________________________\n"); printf("办公用品总价值:%0.1f\t平均价:%0.1f\t总库存量:%d\n",sum[3],aver[3],a[3]);printf("____________________________________________________\n");}void shuchu() /*输出商品信息函数*/{do{struct good *p3,*p4,*p5; /*定义结构体指针类型*/int n=0,p=0,q=0,r=0;printf("所有商品信息:\n");printf("编号,名称,类型,价格,单位,数目\n");printf("**********************************\n");if((fp=fopen("goods message.txt","rb+"))==NULL) /*判断能否打开文件*/{printf("can not open the file");exit(0); /*结束程序*/}head=(struct good *)malloc(sizeof(struct good)); /*申请头结点空间*/p3=head;fscanf(fp,"%d %s %s %f %s %d",&p3->num,p3->name,p3->kind,&p3->price,p3->unit,&p3->quantity);/*从文件中写到链表*/while(1){p4=(struct good *)malloc(sizeof(struct good)); /*申请头结点空间*/fscanf(fp,"%d ",&p4->num);if(p4->num!=-1) /*判断循环结束条件*/{fscanf(fp,"%s %s %f %s %d",p4->name,p4->kind,&p4->price,p4->unit,&p4->quantity); /*从文件中写到链表*/ p4->next=NULL;p3->next=p4;p3=p4;}else{p3->next=NULL;break;}}fclose(fp); /*关闭文件*/p3=head;while(p3!=NULL){printf(" %d %s %s %0.1f %s %d\n\n",p3->num,p3->name,p3->kin d,p3->price,p3->unit,p3->quantity);printf("__________________________________\n");p3=p3->next;}printf("**********************************\n");printf("//////////////////////////////////\n");while(n!=4){p3=head;printf("**********************************\n");printf("1 添加商品信息\n");printf("2 删除某商品信息\n");printf("3 修改某商品信息\n");printf("4 返回(当你完成了对某一商品的添加、删除或者修改后请按4返回)\n");printf("**********************************\n");scanf("%d",&n);if(n==1) /*添加商品信息*/{printf("请输入商品编号名称类型价格单位数目\n");printf("**********************************\n");p4=(struct good *)malloc(sizeof(struct good)); /*申请空间*/scanf("%d %s %s %f %s %d",&p4->num,p4->name,p4->kind,&p4->price,p4->unit,&p 4->quantity); /*输入商品信息*/p4->next=NULL;while(p3->next!=NULL) /*判断循环结束条件*/{p3=p3->next;}p3->next=p4;p3=head;if((fp=fopen("goods message.txt","w"))==NULL) /*判断能否打开文件*/{printf("can not open the file");exit(0); /*结束程序*/}while(p3!=NULL){fprintf(fp,"%d %s %s %f %s %d",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity) ;/*将商品信息写入文件*/p3=p3->next;}fprintf(fp,"%d",-1);fclose(fp); /*关闭文件*/printf("**********************************\n");printf("__________________________________\n");printf("------------请按4返回-------------\n");printf("__________________________________\n");printf("**********************************\n");}if(n==2) /*删除商品*/{printf("**********************************\n");printf("请输入需要删除的商品编号\n");printf("**********************************\n");scanf("%d",&p);printf("**********\n");printf("1 确认删除\n2 取消删除\n");printf("**********\n");scanf("%d",&r);if(r==1){if((head->num)==p){head=head->next;free(p3); /*释放空间*/}else{p4=head;p3=p4->next;while(p3!=NULL) /*判断循环结束条件*/ {if((p3->num)==p){p5=p3->next;free(p3); /*释放空间*/p4->next=p5;break;}p3=p3->next;p4=p4->next;}}if((fp=fopen("goods message.txt","w"))==NULL) /*判断能否打开文件*/{printf("can not open the file");exit(0); /*结束程序*/}p3=head;while(p3!=NULL) /*判断循环结束条件*/{fprintf(fp,"%d %s %s %f %s %d",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity); /*将商品信息写入文件*/p3=p3->next;}fprintf(fp,"%d",-1);fclose(fp); /*关闭文件*/}if(r==2)continue; /*继续循环*/printf("**********************************\n");printf("__________________________________\n");printf("------------请按4返回-------------\n");printf("__________________________________\n");printf("**********************************\n");}if(n==3) /*修改某商品信息*/{printf("请输入需要修改的商品编号\n");scanf("%d",&q);while(p3!=NULL) /*判断循环结束条件*/{if((p3->num)==q) /*判断是否为所需要修改的商品*/{printf("请输入商品单价与库存量(如果单价不变请输入原来的单价)\n");scanf("%f %d",&p3->price,&p3->quantity); /*输入商品价格与库存量*/}p3=p3->next;}if((fp=fopen("goods message.txt","w"))==NULL) /*判断能否打开文件*/{printf("can not open the file");exit(0); /*结束程序*/}p3=head;while(p3!=NULL) /*判断循环结束条件*/{fprintf(fp,"%d %s %s %f %s %d",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity); /*将商品信息写入文件*/p3=p3->next;}fprintf(fp,"%d",-1);fclose(fp); /*关闭文件*/printf("**********************************\n");printf("__________________________________\n");printf("------------请按4返回-------------\n");printf("__________________________________\n");printf("**********************************\n");}if(n==4) /*退出*/break;}printf("**********\n");printf("1 继续修改\n---------\n2 返回\n");printf("**********\n");scanf("%d",&p);if(p==1)continue; /*继续循环*/if(p==2)break; /*跳出循环*/}while(n!=2);fclose(fp); /*关闭文件*/}void printf0(struct good *p) /*遍历链表并打印电器类商品函数*/{struct good *p3; /*定义结构体指针类型*/p3=p;while (p3!=NULL) /*判断遍历链表循环结束条件*/{if(strcmp(p3->kind,c)==0) /*判断商品类型是否为电器类型*/{printf("%d\t%s\t%s\t%0.1f\t%s\t%d\n",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity); /*输出电器类商品信息*/ printf("________________________________________________\n");}p3=p3->next;}return;}void printf1(struct good *p) /*遍历链表并打印日用品类商品函数*/{struct good *p3; /*定义结构体指针类型*/p3=p;while (p3!=NULL) /*判断遍历链表循环结束条件*/{if(strcmp(p3->kind,d)==0) /*判断商品类型是否为日用品类型*/{printf("%d\t%s\t%s\t%0.1f\t%s\t%d\n",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity); /*输出日用品类商品信息*/ printf("________________________________________________\n");}p3=p3->next;}return;}void printf2(struct good *p) /*遍历链表并打印办公用品类商品函数*/{struct good *p3; /*定义结构体指针类型*/p3=p;while (p3!=NULL) /*判断遍历链表循环结束条件*/{if(strcmp(p3->kind,e)==0) /*判断商品类型是否为办公用品类型*/{printf("%d\t%s\t%s\t%0.1f\t%s\t%d\n",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity); /*输出办公用品类商品信息*/ printf("________________________________________________\n");}p3=p3->next;}return;}void printf3(struct good *p) /*遍历链表并打印食品类商品函数*/{struct good *p3; /*定义结构体指针类型*/p3=p;while (p3!=NULL) /*判断遍历链表循环结束条件*/{if(strcmp(p3->kind,f)==0) /*判断商品类型是否为食品类型*/{printf("%d\t%s\t%s\t%0.1f\t%s\t%d\n",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity); /*输出食品类商品信息*/ printf("________________________________________________\n");}p3=p3->next;}return;}void shunxudayin(){for(i=0;i<4;i++)g[i]=aver[i]; /*将平均价赋给新数组*/for(j=0;j<3;j++) /*将新数组用冒泡排序法排序*/for(i=j+1;i<4;i++){if(g[j]<g[i]){h=g[j];g[j]=g[i];g[i]=h;}}printf("\n****************************\n");printf("商品平均价格排序表(从高到低)\n");printf("****************************\n");printf("________________________________________________\n");printf("编号\t名称\t类别\t单价\t单位\t数量\n");printf("________________________________________________\n"); for(j=0;j<4;j++)for(i=0;i<4;i++){if (aver[i]==g[j]) /*判断每类商品平均价格的先后顺序*/switch(i){case 0:printf0(head); /*调用遍历链表并打印电器类商品函数*/break;case 1:printf1(head); /*调用遍历链表并打印日用品类商品函数*/break;case 2:printf2(head);/*调用遍历链表并打印办公用品类商品函数*/break;case 3:printf3(head); /*调用遍历链表并打印食品类商品函数*/break;}}void tongji1(){p1=head;printf("\n************************\n");printf("库存量低于100的货名及类别\n");printf("************************\n");printf("________________________\n");printf("商品名称\t商品类型\n");printf("________________________\n");while(p1!=NULL) /*判断遍历链表循环结束条件*/{if(p1->quantity<100) /*判断库存量是否小于100*/{printf("%s\t%s\n",p1->name,p1->kind); /*输出商品名称及类别*/ printf("________________________\n");}p1=p1->next;}}void tongji2()printf("\n**********************************************\n");printf("商品库存量有2种以上(含2种)低于100的商品类别:\n");printf("**********************************************\n");printf("________\n");if((a[0]<100)&&(a[0]>=2)) /*判断电器类库存量是否为2种以上(含2种)低于100*/{printf("电器\n");printf("________\n");}if((a[1]<100)&&(a[1]>=2)) /*判断日用品类库存量是否为2种以上(含2种)低于100*/{printf("日用品\n");printf("________\n");}if((a[2]<100)&&(a[2]>=2)) /*判断食品类库存量是否为2种以上(含2种)低于100*/{printf("食品\n");printf("________\n");if((a[3]<100)&&(a[3]>=2)) /*判断办公用品类库存量是否为2种以上(含2种)低于100*/{printf("办公用品\n");printf("________\n");}}int main(int argc, char* argv[]){struct good *p1,*p2; /*定义结构体指针类型*/while(1){printf("***********************************************\n");printf("1 ----------输出查看或者修改已存信息-----------\n");printf("-----------------------------------------------\n");printf("2 -----重新输入新信息(并且删除原有信息)------\n");printf("-----------------------------------------------\n");printf("3 统计商品信息(如果您还没有查看过信息请先按1)\n");printf("-----------------------------------------------\n");printf("4 -------------------退出---------------------\n");printf("***********************************************\n");scanf("%d",&m);if(m==1)shuchu(); /*调用输出信息函数*/if(m==2){system("cls");head=createlist(); /*调用建立链表函数*/}if(m==3){printf("统计结果如下\n");head=paixu(head); /*调用链表排序函数*/ jisuan(); /*调用计算函数*/ shunxudayin(); /*调用顺序打印函数*/ tongji1(); /*调用统计1函数*/tongji2(); /*调用统计2函数*/}if(m==4){p1=head;while(p1!=NULL) /*判断遍历链表结束条件*/ {p2=p1->next;free(p1); /*释放空间*/p1=p2;}break;}}return 0; /*结束程序*/ }5)调试分析过程描述:测试数据:01 milk drink 2.5 box 502 apple fruit 3 kilo 2测试输出结果:存在问题的思考:源代码出错,漏了一些分号导致程序频频出错,在进行编写时注意小地方别出错!否则会影响大局!6)总结:学习体会与收获:通过这个超市管理系统程序设计实验,我从理论知识跨越到实践上,感到收效良多,从崇拜计算机到学会控制计算机,在心理上不再觉得计算机是万能的,人的大脑才是万能的,算法才是万能的数学才是万能的,在这次实验中,实现一个完整的程序大大加深了我对C语言课程的兴趣!对C语言课程设计的认识以及自己的建议:C语言课程设计就是通过编译实现需要的功能的一种程序的设计,建议自己以后在这方面多下功夫,真正实现自己编译以个完整的C程序,实现自己的梦想和未来!。
C#简单超市收银系统源码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _16超市收银系统{class ProductFather{public double Price{get;set;}public string Name{get;set;}public string ID{get;set;}public ProductFather(string id, double price, string Name){this.ID = id;this.Price = price; = Name;}}}using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _16超市收银系统{class SamSung:ProductFather{public SamSung(string id, double price, string Name): base(id, price, Name){}}}using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _16超市收银系统{class Acer:ProductFather{public Acer(string id, double price, string Name): base(id, price, Name){}}}using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _16超市收银系统{class Banana : ProductFather{public Banana(string id, double price, string Name): base(id, price, Name){}}}using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _16超市收银系统{class JiangYou:ProductFather{public JiangYou(string id, double price, string Name) : base(id, price, Name){}}}using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _16超市收银系统{class SupperMarket{//创建仓库对象CangKu ck = new CangKu();/// <summary>/// 创建超市对象的时候,给仓库的货架上导入货物/// </summary>public SupperMarket(){ck.JinPros("Acer", 1000);ck.JinPros("SamSung", 1000);ck.JinPros("JiangYou", 1000);ck.JinPros("Banana", 1000);}/// <summary>/// 跟用户交互的过程/// </summary>public void AskBuying(){Console.WriteLine("欢迎观临,请问您需要些什么?");Console.WriteLine("我们有Acer、SamSung、Jiangyou、Banana");string strType = Console.ReadLine();Console.WriteLine("您需要多少?");int count = Convert.ToInt32(Console.ReadLine());//去仓库取货物ProductFather[] pros = ck.QuPros(strType, count);//下面该计算价钱了double realMoney = GetMoney(pros);Console.WriteLine("您总共应付{0}元", realMoney);Console.WriteLine("请选择您的打折方式1--不打折2--打九折3--打85 折4--买300送50 5--买500送100");string input = Console.ReadLine();//通过简单工厂的设计模式根据用户的舒服获得一个打折对象CalFather cal = GetCal(input);double totalMoney = cal.GetTotalMoney(realMoney);Console.WriteLine("打完折后,您应付{0}元", totalMoney);Console.WriteLine("以下是您的购物信息");foreach (var item in pros){Console.WriteLine("货物名称:"++","+"\t"+"货物单价:"+item.Price+","+"\t"+"货物编号:"+item.ID);}}/// <summary>/// 根据用户的选择打折方式返回一个打折对象/// </summary>/// <param name="input">用户的选择</param>/// <returns>返回的父类对象但是里面装的是子类对象</returns>public CalFather GetCal(string input){CalFather cal = null;switch (input){case "1": cal = new CalNormal();break;case "2": cal = new CalRate(0.9);break;case "3": cal = new CalRate(0.85);break;case "4": cal = new CalMN(300, 50);break;case "5": cal = new CalMN(500, 100);break;}return cal;}/// <summary>/// 根据用户买的货物计算总价钱/// </summary>/// <param name="pros"></param>/// <returns></returns>public double GetMoney(ProductFather[] pros){double realMoney = 0;//realMoney = pros[0].Price * pros.Length;for (int i = 0; i < pros.Length; i++){realMoney += pros[i].Price;// realMoney = pros[i] * pros.Length;}return realMoney;}public void ShowPros(){ck.ShowPros();}}}using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _16超市收银系统{/// <summary>/// 不打折该多少钱就多少钱/// </summary>class CalNormal:CalFather{public override double GetTotalMoney(double realMoney){return realMoney;}}}using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _16超市收银系统{/// <summary>/// 按折扣率打折/// </summary>class CalRate:CalFather{/// <summary>/// 折扣率/// </summary>public double Rate{get;set;}public CalRate(double rate){this.Rate = rate;}public override double GetTotalMoney(double realMoney){return realMoney * this.Rate;}}}using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _16超市收银系统{/// <summary>/// 买M元送N元/// </summary>class CalMN:CalFather{//买500送100public double M{get;set;}public double N{get;set;}public CalMN(double m, double n){this.M = m;this.N = n;}public override double GetTotalMoney(double realMoney){//600 -100//1000-200//1200if (realMoney >= this.M){return realMoney - (int)(realMoney / this.M) * this.N;}else{return realMoney;}}}}using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _16超市收银系统{class CangKu{List<List<ProductFather>> list = new List<List<ProductFather>>();/// <summary>///向用户展示货物/// </summary>public void ShowPros(){foreach (var item in list){Console.WriteLine("我们超市有:" + item[0].Name + "," + "\t" + "有" +item.Count + "个," + "\t" + "每个" + item[0].Price + "元");}}//list[0]存储Acer电脑//list[1]存储三星手机//list[2]存储酱油//list[3]存储香蕉/// <summary>/// 在创建仓库对象的时候像仓库中添加货架/// </summary>public CangKu(){list.Add(new List<ProductFather>());list.Add(new List<ProductFather>());list.Add(new List<ProductFather>());list.Add(new List<ProductFather>());}/// <summary>/// 进货/// </summary>/// <param name="strType">货物的类型</param>/// <param name="count">货物的数量</param>public void JinPros(string strType, int count){for (int i = 0; i < count; i++){switch (strType){case "Acer": list[0].Add(new Acer(Guid.NewGuid().ToString(), 1000, "宏基笔记本"));break;case "SamSung": list[1].Add(new SamSung(Guid.NewGuid().ToString(), 2000, "棒之手机"));break;case "JiangYou": list[2].Add(new JiangYou(Guid.NewGuid().ToString(), 10, "老抽酱油"));break;case "Banana": list[3].Add(new Banana(Guid.NewGuid().ToString(), 50, "大香蕉"));break;}}}/// <summary>/// 从仓库中提取货物/// </summary>/// <param name="strType"></param>/// <param name="count"></param>/// <returns></returns>public ProductFather[] QuPros(string strType, int count){ProductFather[] pros = new ProductFather[count];for (int i = 0; i < pros.Length; i++){switch (strType){case "Acer":pros[i] = list[0][0];list[0].RemoveAt(0);break;case "SamSung": pros[i] = list[1][0];list[1].RemoveAt(0);break;case "JiangYou": pros[i] = list[2][0];list[2].RemoveAt(0);break;case "Banana": pros[i] = list[3][0];list[3].RemoveAt(0);break;}}return pros;}}}using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _16超市收银系统{class SupperMarket{//创建仓库对象CangKu ck = new CangKu();/// <summary>/// 创建超市对象的时候,给仓库的货架上导入货物/// </summary>public SupperMarket(){ck.JinPros("Acer", 1000);ck.JinPros("SamSung", 1000);ck.JinPros("JiangYou", 1000);ck.JinPros("Banana", 1000);}/// <summary>/// 跟用户交互的过程/// </summary>public void AskBuying(){Console.WriteLine("欢迎观临,请问您需要些什么?");Console.WriteLine("我们有Acer、SamSung、Jiangyou、Banana");string strType = Console.ReadLine();Console.WriteLine("您需要多少?");int count = Convert.ToInt32(Console.ReadLine());//去仓库取货物ProductFather[] pros = ck.QuPros(strType, count);//下面该计算价钱了double realMoney = GetMoney(pros);Console.WriteLine("您总共应付{0}元", realMoney);Console.WriteLine("请选择您的打折方式1--不打折2--打九折3--打85 折4--买300送50 5--买500送100");string input = Console.ReadLine();//通过简单工厂的设计模式根据用户的舒服获得一个打折对象CalFather cal = GetCal(input);double totalMoney = cal.GetTotalMoney(realMoney);Console.WriteLine("打完折后,您应付{0}元", totalMoney);Console.WriteLine("以下是您的购物信息");foreach (var item in pros){Console.WriteLine("货物名称:"++","+"\t"+"货物单价:"+item.Price+","+"\t"+"货物编号:"+item.ID);}}/// <summary>/// 根据用户的选择打折方式返回一个打折对象/// </summary>/// <param name="input">用户的选择</param>/// <returns>返回的父类对象但是里面装的是子类对象</returns>public CalFather GetCal(string input){CalFather cal = null;switch (input){case "1": cal = new CalNormal();break;case "2": cal = new CalRate(0.9);break;case "3": cal = new CalRate(0.85);break;case "4": cal = new CalMN(300, 50);break;case "5": cal = new CalMN(500, 100);break;}return cal;}/// <summary>/// 根据用户买的货物计算总价钱/// </summary>/// <param name="pros"></param>/// <returns></returns>public double GetMoney(ProductFather[] pros){double realMoney = 0;//realMoney = pros[0].Price * pros.Length;for (int i = 0; i < pros.Length; i++){realMoney += pros[i].Price;// realMoney = pros[i] * pros.Length;}return realMoney;}public void ShowPros(){ck.ShowPros();}}}using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _16超市收银系统{class Program{static void Main(string[] args){//创建超市对象SupperMarket sm = new SupperMarket();//展示货物sm.ShowPros();//跟用户交互sm.AskBuying();Console.ReadKey();}}}。
黔南民族师范学院软件设计课程设计报告题目:超市商品管理系统系部名称:计科系专业名称:信息管理与信息系统班级:B12计信班学号:1208045139学生姓名:胡崇祯指导教师:黄茹时间:2013年11月9日至2013年12月8日一、课程设计目的1. 通过本课程设计,强化上机动手能力,使学生在理论和实践的基础上进一步巩固《C语言程序设计》课程学习的内容,掌握工程软件设计的基本方法。
2. 学会将知识应用于实际的方法,提高分析和解决问题的能力,增加综合能力。
3. 为后续各门计算机课程的学习打下坚实基础。
4. 为毕业设计和以后工作打下必要基础。
二、课程设计内容1.编写程序并进行调试运行。
2. 输入商品信息,并保存于文件。
每个商品信息包含信息如:库存量、进价、售价、保质期、生产商等。
3. 对已存入的商品信息进行更新操作,包括添加一个商品信息、删除某个商品信息和修改某个商品信息。
4.通过输入商品名、商品号、商品类型的方式查询商品信息。
5. 最后输出商品信息,供需要时打印。
三、需求分析1. 该程序可用于对商品基本信息的存储、更新、查询、排序、输出等操作,以实现对商品信息的管理。
2. 其中更新功能包括:添加信息、删除信息、修改信息、可根据需要添加一个或多个商品信息,也可对个别商品信息进行适当的删除或修改。
以便随时更新商品信息。
3. 程序中设计的查询功能可根据需要从若干数据中查询某个商品信息,并且可根据三种不同的方法查询:按商品号查询、按商品类型和按商品查询,以满足不同的需要。
四、概要设计1、方案设计对系统进行分析,给出结构图分析:系统要求实现许多的功能,因此遵循结构化程序设计思想来进行本系统的设计—自顶向下、逐步细化,将系统设计任务分解出许多子功能模块进行设计结构图如下:2、模块功能说明(对各个模块进行功能的描述)(1).输入模块:录入需要管理的商品信息并将信息保存于文件中,以方便日后进行打印、读取、更新等操作。
(2).添加模块:可添加一个或多个商品信息,并将所添加商品信息保存,方便查找。
(3).删除模块:可对售完的商品信息做删除处理。
(4).修改模块:可根据需要对多个商品信息进行修改,也可随时对个别项进行修改。
(5).查询模块:可对已建立的商品信息进行查询,并且可根据需要选择按商品名查询或按商品号查询。
(6).保存模块:用于对信息进行保存。
(7).输出模块:将所有商品信息或想要查询的商品信息显示于屏幕,用于打印商品信息或查找某些商品信息。
(8).退出系统:选择该项,自动退出该系统。
输入模块: 输出模块:排行模块:六、调试情况,设计技巧及体会1、对自己设计进行评价,指出合理和不足之处,提出改进的方案。
此次实践课编写的是一个应用程序,相对于以前我们见到的程序,它要大得多,开始时,数据的输出格式不太规范,而且各模块也出现了一些小问题,在老师和同学的帮助下,通过自己一次又一次的进行调试和修改,最后运行的结果基本上达到了预期的目的。
由于时间问题和考虑得不够周全,可能在某些功能上不是很完善,不过已有的功能已能基本满足一般用户的需求,如果能通过不断的实验和使用过程中所积累的问题进行改进。
如:数量,价格的输入值为负值时,程序也能继续执行,这就给运用上带来一些不便或可能出现一些莫名其妙的错误。
不过总的来说,对于自己首次能够自主完成一个这样大的程序来说,还是比较满意。
2、在设计过程中的感受。
本次C 语言的实习课让我对C 语言的学习又有了更深入的了解,也让我更深刻地领悟到了“实践出真理”这个道理,在上机实践过程中学到的知识远远超过了在课堂上十几周学到的,学校组织的这次实习让我们这些实践知识较缺乏的大学生增添了许多实践经验,为我们将来走上工作岗位其了不小的铺垫作用。
本次实习中遇到了很多以前没有遇到过的问题,也曾想过要放弃,但看到自己一般写过的大量程序,给了我继续的信心。
在老师和同学的帮助下,我顺利的完成了本次实习,让我体会到了经过不懈的努力,有过挫折有过坎坷,但最终实现目标后的成就感,也让我充分感受到友谊和团结的重要性。
七、参考文献《C语言程序设计》王曙燕曹锰八、附录:#include <stdio.h>#include <math.h>#include <string.h>#include<conio.h>#include<stdio.h>#include<string.h>#define MAX 20#define PRINT1 printf("---------------------------------------------------------\n")#define PRINT2 printf("商品号--商品名称--商品种类--销售价格--生产日期(年-月-日)--保质期\n")#define PRINT3printf("%4d%8s%8s%8d%8d-%2d-%2d%4d\n",goods[i].num,goods[i].name,goods[i] .kind,goods[i].out_price,goods[i].pro_time.year,goods[i].pro_time.month,goods[i].pro _time.day,goods[i].save_day)int sum;struct date{int year;int month;int day;};struct goods_type /*定义结构体*/{int num;char name[10];char kind[10];int amount;int in_price;int out_price;struct date pro_time;int save_day;int profit;}goods[MAX];Save_Message(int sum); /*函数声明*/void Inquire_message(void);void Inquire_goodskind(void);void Inquire_goodsname(void);int Read_Message(void);void Renew_Messahe(void);void Revise_Message(void);void Delete_Message(void);void Insert_Message();void Show_Message(void);int Input_Message(void);void Count_Message();long Count_Profit();long Count_Amount();void Sort_amount(void);void Sort_Message(void);void Sort_Message(void){int choice;do{clrscr();printf("\n\n\n *******商品信息排行********\n\n");printf(" 1:按库存量排行\n\n");printf(" 0:返回主菜单\n\n");printf(" 请选择(0-1): ");scanf("%d",&choice);switch(choice){case 1:Sort_amount();break;case 0:break;}}while(choice!=0);}void Sort_amount(void) /*库存量排序*/{struct goods_type *p,*q[MAX];int i,j,k;clrscr();printf(" 库存排行");PRINT1;printf("\n\n排名商品号商品名称商品类别库存量\n\n");p=goods;for(i=0;i<sum;i++)q[i]=p++;for(i=0;i<sum;i++){k=i;for(j=i+1;j<sum;j++)if(q[k]->amount<q[j]->amount)k=j;if(k!=i){p=q[i];q[i]=q[k];q[k]=p;}}for(i=0;i<sum;i++){printf(" %d ",i+1);printf(" %d ",q[i]->num);printf(" %s ",q[i]->name);printf(" %s ",q[i]->kind);printf(" %d \n ",q[i]->amount);}bioskey(0);}long Count_Amount() /*统计库存量*/{int i,j=0,choice,count_num,Amount;char inquire_name[10];clrscr();printf("\n 请输入想要统计的商品号: ");scanf("%d",&count_num);for(i=0;i<sum;i++)if(goods[i].num==count_num){Amount=goods[i].amount;printf("-------------------------");printf(" 商品号库存量");printf("\n%8d%8d",goods[i].num,Amount);}elsej++;if(j==sum)printf("该商品信息不存在!!!");bioskey(0);}long Count_Profit() /*统计利润模块*/{int i,choice,j=0,count_num,profit;clrscr();printf("\n 请输入想要统计的商品号: ");scanf("%d",&count_num);for(i=0;i<sum;i++)if(goods[i].num==count_num){profit=goods[i].out_price-goods[i].in_price;printf("\n 商品利润");printf("\n -------------------------------");printf("\n 商品号利润");printf("\n %8d%8d\n",&goods[i].num,&profit);}elsej++;if(j==sum)printf("\n 该商品不存在!!!");printf("\n 按任意键返回主菜单!!");bioskey(0);}void Count_Message(void) /*统计模块*/{int choice;do{clrscr();printf("**************统计商品信息*************\n\n\n");printf("******* 1:统计库存量************\n\n\n");printf("******* 2:统计利润************\n\n\n");printf("******* 0:返回主菜单************\n\n\n");printf("******* 请选择(0-2): ************\n\n\n");scanf("%d",&choice);switch(choice){case 1:Count_Amount();break;case 2:Count_Profit();break;case 0:break;}}while(choice!=0);}int Input_Message(void) /*输入模块*/{int i=0,s=MAX;char bd;clrscr();printf("开始输入商品信息.\n");printf("\n\n 商品信息:(最多%d) \n",s);printf(" ===============================\n");do{printf("\n 第%d 商品",i+1);printf("\n 商品号: ");scanf("%d",&goods[i].num);if(goods[i].num==0) break;printf("\n 商品名称: ");scanf ("%s",goods[i].name);printf("\n 商品种类: ");scanf ("%s",goods[i].kind);printf("\n 商品库存量: ");scanf ("%d",&goods[i].amount);printf("\n 进货价格: ");scanf ("%d",&goods[i].in_price);printf("\n 销售价格: ");scanf ("%d",&goods[i].out_price);printf("\n 生产日期(yyyy-mm-dd): ");scanf("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_time.month,&goods[i].pro_ti me.day);printf("\n 保质期: ");scanf ("%d",&goods[i].save_day);printf("继续输入信息,y or n ??");fflush(stdin);scanf("%c",&bd);if(bd=='y')i++;elsebreak;}while(i<MAX);printf("\n--%d 所有商品录入完毕!--\n\n\n",i+1);getch();printf(" 按任意键返回主菜单.");sum=i;printf("输入回车返回主菜单!!!");bioskey(0);}void Show_Message(void) /*显示输出模块*/{int i=0,j=0,count,page=7;clrscr();printf("\n\n --商品信息-- 在第%d 页\n\n",page);PRINT2;PRINT1;do{if(goods[i].num!=0){j++;if(j%page!=0){PRINT3;PRINT1;}else{PRINT3;PRINT1;if(goods[i+1].num!=0){printf("按任意键继续!");bioskey(0);clrscr();printf("\n\n --------商品信息--------在第%d 页\n\n",++page);PRINT2;PRINT1;}}}i++;}while(goods[i].num!=0);printf("按任意键返回主菜单!!!!!");bioskey(0);}void Insert_Message(void)/*添加商品信息模块*/{int i=sum,j,flag=0;char choice;clrscr();printf("\n\n 添加一种新商品\n\n ");printf("\n-------------------------------------------------\n");do{goods[i].num=++sum;printf("\n 新商品号:%d",goods[i].num);printf("\n 新商品名: ");scanf("%s",goods[i].name);printf("\n 新商品种类: ");scanf("%s",goods[i].kind);printf("\n 新商品数量: ");scanf("%d",&goods[i].amount);printf("\n 进价: ");scanf("%d",&goods[i].in_price);printf("\n 售价: ");scanf("%d",&goods[i].out_price);printf("\n 生产日期(yyyy-mm-dd): ");scanf("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_time.month,&goods[i].pr o_time.day);printf("\n 保质期: ");scanf("%d",&goods[i].save_day);i++;printf("\n\n 想继续添加商品吗?(Y/N)");fflush(stdin);choice=getch();if(choice=='y'||choice=='Y'){printf("继续");flag=1;}elseflag=0;}while(flag==1);printf("\n\n\n 按任意键返回主菜单.........");bioskey(0);}void Delete_Message(void)/*删除商品信息模块*/{int i,j,numberkey,flag=0;char choice;printf("开始删除......\n\n");do{clrscr();printf("请输入你要删除的商品号: \n");scanf("%d",&numberkey);for(i=0;i<sum;i++){if(goods[i].num==numberkey){for(j=i;j<sum;j++)goods[j]=goods[j+1];sum--;flag=1;printf("删除成功!!\n\n\n");break;}}if(flag==0){printf("不存在该商品信息!!!");bioskey(0);}printf("\n\n是否继续输入(y/n)?\n");getchar();scanf("%c",&choice);}while(choice=='y'||choice=='Y');printf("\n按任意键返回");bioskey(0);}void Revise_Message(void)/*修改商品信息模块*/{int i,j,flag,choice,revise_num;char ch;do{clrscr();printf("\n\n 开始修改...");printf("\n\n 请输入你想输入的商品号:\n");scanf("%d",&revise_num);for(i=0;i<sum;i++){if(goods[i].num==revise_num){printf("确定修改此商品信息吗?(y/n)");PRINT1;PRINT2;PRINT3;getchar();ch=getchar();if(ch='y'){printf("\n\n\n修改商品信息的哪一项?");printf("\n\n 1:商品名称");printf("\n\n 2:商品类型");printf("\n\n 3:销售价格");printf("\n\n 4:生产日期");printf("\n\n 5:保质期");printf("\n\n 请选择(0-5)\n");scanf("\n %d",&choice);switch(choice){case 1:printf("请输入修改后的商品名\n");scanf("%s",&goods[i].name);break;case 2:printf("请输入修改后的商品类型\n");scanf("%s",&goods[i].kind);break;case 3:printf("请输入修改后的商品销售价格\n");scanf("%d",&goods[i].out_price);break;case 4:printf("请输入修改后的商品生产日期\n"); scanf("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_time.month,&goods[i].pr o_time.day);break;case 5:printf("请输入修改后的商品保质期\n");scanf("%d",&goods[i].save_day);break;case 0:break;}printf("修改商品信息:\n");PRINT2;PRINT3;}elsebreak;}elsej++;if(j==sum)printf("不存在该商品信息..");}printf("\n\n 继续修改商品信息吗(y/n)?");getchar();ch=getchar();if(ch=='y'){printf("继续.\n");flag=1;}elseflag=0;}while(flag==1);printf("修改完成!!\n\n");getch();}void Renew_Message(void) /*更新商品信息模块*/{int choice;do{clrscr();printf("\n\n*********更新商品信息*********");printf("\n\n 1:添加商品信息.\n\n");printf("\n\n 2:删除商品信息.\n\n");printf("\n\n 3:修改商品信息.\n\n");printf("\n\n 0:返回上一级.\n\n");printf("\n\n 请选择(0-3): ");scanf("%d",&choice);switch(choice){case 1:Insert_Message();break;case 2:Delete_Message();break;case 3:Revise_Message();break;case 0:break;}}while(choice!=0);}int Read_Message(void) /*读取信息模块*/{FILE *fp;int i=0;if((fp=fopen("999.txt","rb"))==NULL){printf("\n\t 现在还没有保存全部信息,按回车键回到主菜单输入商品信息!!");printf("\n\t 按任意键返回!!!!\n");getch();return;}while(feof(fp)!=1){fread(&goods[i],sizeof(struct goods_type),1,fp);if(goods[i].num==0)break;elsei++;}fclose(fp);return(i);}void Inquire_goodsname(void)/*按商品名称查询*/{int i,j,choice;char namekey[10];j=0;printf("开始查询...");printf("请输入你要查询的商品号:\n");scanf("%s",namekey);for(i=0;i<sum;i++)if(strcmp(goods[i].name,namekey)==0&&goods[i].num!=0){printf(" ---商品信息----");PRINT1;PRINT2;PRINT3;}elsej++;if(j==sum)printf("该商品不存在!");printf("按任意键返回主菜单.");getch();}void Inquire_goodskind(void)/*按商品类型查询*/{int i,j,choice;char kindkey[10];j=0;printf("开始查询...");printf("请输入你要查询的商品种类:\n");scanf("%s",kindkey);for(i=0;i<sum;i++)if(strcmp(goods[i].kind,kindkey)==0&&goods[i].num!=0){printf(" ---商品信息----");PRINT1;PRINT2;PRINT3;}elsej++;if(j==sum)printf("该商品不存在!");printf("按任意键返回主菜单.");getch();}void Inquire_Message(void) /*查询模块*/{int choice;do{printf("\n *****查询商品信息***** \n");printf("\n *****1:按商品名称.***** \n");printf("\n *****2:按商品种类.***** \n");printf("\n *****0:返回上一级.***** \n");printf("\n 请选择(0-2): ***** \n");scanf("%d",&choice);switch(choice){case 1:Inquire_goodsname();break;case 2:Inquire_goodskind();break;case 0:break;}}while(choice!=0);}Save_Message(int sum) /*保存模块*/{FILE *fp;int i;if((fp=fopen("999.txt","wb"))==NULL){printf("\n\n不能打开文件!\n\n");exit();}for(i=0;i<=sum;i++)if(fwrite(&goods[i],sizeof(struct goods_type),1,fp)!=1)printf("写文件出错!");fclose(fp);}void main(void) /*主函数*/{int choice;clrscr();sum=Read_Message();bioskey(0);do{clrscr();printf("***************************************************\n");printf(" ************ 超市商品管理系统**************\n");printf(" ****** ******\n");printf(" ****** ******\n");printf(" ****** ******\n");printf(" ****** 欢迎登陆******\n");printf(" ****** ******\n");printf(" ************\n");printf(" ****** ******\n");printf("***************************************************\n");printf("***************************************************\n");getchar ();clrscr();printf(" ***************超市商品管理系统***********\n\n");printf(" ***** 1:输入商品信息*****\n\n");printf(" ***** 2:输出商品信息*****\n\n");printf(" ***** 3:更新商品信息*****\n\n");printf(" ***** 4:查询商品信息*****\n\n");printf(" ***** 5:统计商品信息*****\n\n");printf(" ***** 6:商品信息排序*****\n\n");printf(" ***** 0:退出系统*****\n\n");printf(" ***** 请选择(0-6): *****\n");scanf("%d",&choice);switch(choice){case 1:Input_Message();break;case 2:Show_Message();break;case 3:Renew_Message();break;case 4:Inquire_Message();break;case 5:Count_Message();break;case 6:Sort_Message();break;case 0:break;}}while(choice!=0);Save_Message(sum);printf("\n-信息已经保存!-(file name:999.txt)\n");【本文档内容可以自由复制内容或自由编辑修改内容期待你的好评和关注,我们将会做得更好】。