仓库物资管理系统C语言(共19页).doc
精选优质文档-倾情为你奉上 仓库物资管理系统课程设计课程名称: 程序设计基础 姓名: 学号: 班级: 联系方式: 1、课程设计目的和要求目的:进一步加深、巩固学生所学专业课程C程序设计的基本理论知识,理论联系实际,培养学生综合分析问题和解决问题的能力。掌握运用C语言独立地编写、调试应用程序和进行其它相关设计的技能。要求:编写仓库管理系统,实现库存记录、出库记录、入库记录等三方面的功能。2、课程设计名称及内容n 2.1课程设计名称仓库物资管理系统n 2.2设计内容设计一个仓库物资管理系统,该系统要求对仓库物资信息进行管理和维护,实现仓库物资信息化。n 2.3任务和要求1. 创建库存记录文件,根据提示输入若干电器的信息,并将信息保存至一个文件中。2. 物资入库管理,创建一个入库记录文件,每次有物资入库,则按入库记录要求输入各项信息,并将该次的入库信息添加到文件中,同时修改相应的库存记录文件。3. 物资出库管理,创建一个出库记录文件,每次有物资出库,则按出库记录要求输入各项信息,并将该次的出库信息添加到文件中,同时修改相应的库存记录文件。注意:物资出库时要检查出库数量的合法性(即出库数量必须小于库存数量)。4. 按不同条件进行查询操作,输出满足条件的物资信息。(1) 输入电器名称,在库存记录文件中查找相应的物资信息并输出。(2) 输入品牌名称,在库存记录文件中查找该品牌的所有电器信息并输出。(3) 输入一个日期(年.月.日),输出该天的入库记录和出库记录。(4) 输入电器名称和型号,输出该电器的所有入库记录和出库记录。5. 按不同条件对物资信息进行统计工作。(1) 输入电器名称,在库存记录文件中统计该电器的现有库存总量。(2) 输入电器名称,在入库记录文件中统计该电器的入库次数。(3) 输入一个日期(年.月),在出库记录文件中统计该月的出库记录次数。(4) 设置一个库存数量警戒值,输出库存数量小于该警戒值的所有库存电器的信息。3.设计思想作为仓库物资管理系统,首先要有对物资信息的录入,库存记录应包括以下信息:电器名称、品牌名称(或生产厂家)、型号、库存数量、价值。主要以录入、查找、增加、修改、删除、显示等功能,贯穿整个程序。输入要查找的物资名称,系统会自动显示对应的物资信息。最后就是退出程序4程序详细设计程序共有 20个函数,分别为void CreatStock()void CreatInstock()void Creatoutstock()void SearchElename();void SearchBrand();void SearchDate();void SearchElenameAndBrand();void PrintStock(struct stock *p);void PrintInstock(struct instock *p);void PrintOutstock(struct outstock *p)void SearchMenu()void CountMenu()void Count4()void main()int read_stock()int read_instock()int read_outstock()int Count1()int Count2()int Count3()其中程序末尾定义了main函数,主函数void main(),主要通过调用各个成员函数,最终实现物资信息的创建、查找、统计等各项功能。5.课程设计心得与体会 在这次C语言课程设计中,我收获颇丰也发现了自己许多不足的地方,结合自己所学并通过查阅资料,在程序设计过程中加深了我对面向对象的程序设计方法的认识,在巩固了基本的程序设计方法的基础上进一步学习了C中类的定义、成员方法的使用以及函数的调用等。同时,在程序的设计过程中暴露出了许多问题,首先,程序设计之初思路混乱,面对程序要求的各项功能如:教师信息的创建、删除、修改、查找等无从下手,最终通过一个个的子函数分别完成不同的功能并通过主函数调用最终实现程序功能的完整性;第二,平时对于面向对象的程序设计方法仅仅局限于概念上的理解,真正实现起来被每个对象繁杂的属性搞的晕头转向;第三,自己对C语言的学习仅仅局限于课本知识,很少实践,以至于在编程过程中错误不断甚至出现低级的语法错误。这次课程设计使我的编程能力得到了很大的提高,加深了我对面向对象这一概念的理解,对以后其他面向对象程序语言的学习打好良好基础,同样也在编程方面积累了经验6.参考资料C程序设计7程序源代码#include "stdio.h"#include<stdlib.h>#include<string.h>#include<conio.h>#define STOCKNUM 3/原来库存中家电的种类#define INSTOCKNUM 3/每次输入的家电种类#define OUTSTOCKNUM 3/出库家电的种类struct date/时间结构int year;int month;int day;struct stock/库存结构char elename20;char brand20;char type20;int stocknum;int value;stocSTOCKNUM+INSTOCKNUM;struct instock/入库结构char elename20;char brand20;char type20;int instocknum;int price;struct date intime;char sendername20;inINSTOCKNUM;struct outstock/出库结构char elename20;char brand20;char type20;int outstocknum;struct date outtime;char delivername20;outOUTSTOCKNUM;/- void CreatStock()/创建库存记录文件int i;FILE *fp;if(fp=fopen("stock.txt","w")=NULL)printf("Can't open file!n");exit(0);for(i=0;i<STOCKNUM;i+)printf("请输入电器的信息!n"); printf("n电器名称 品牌名称 型号 库存数量 价值n");scanf("%s %s %s %d %d",stoci.elename,stoci.brand,stoci.type,&stoci.stocknum,&stoci.value); fwrite(&stoci,sizeof(struct stock),1,fp);fclose(fp);/-int read_stock()/读取库存文件到stocint i=0;FILE *fp;if(fp=fopen("stock.txt","r")=NULL)printf("Can't open file :stock.txt !n");return 0;if( fgetc(fp)<0 ) /读入的是文件结束符return 0;rewind(fp);/使位置指针重新移到文件开头while( !feof(fp) ) fread(&stoci,sizeof(struct stock),1,fp);i+;fclose(fp);return -i;/返回库存家电的种类/-int read_instock()/读取入库文件到inint i=0;FILE *fp;if(fp=fopen("instock.txt","r")=NULL)printf("Can't open file :instock.txt !n");return 0;if( fgetc(fp)<0 ) return 0;rewind(fp);while( !feof(fp) ) fread(&ini,sizeof(struct instock),1,fp);i+;fclose(fp);return -i;/返回入库家电的种类/-int read_outstock()/读取出库文件到outint i=0;FILE *fp;if(fp=fopen("outstock.txt","r")=NULL)printf("Can't open file :outstock.txt !n");return 0;if( fgetc(fp)<0 ) return 0;rewind(fp);while( !feof(fp) ) fread(&outi,sizeof(struct outstock),1,fp);i+;fclose(fp);return -i;/返回出库家电的种类/-void CreatInstock()/创建入库记录并改变库存记录int i,j,k;int an=STOCKNUM;int boolean=0;FILE *fp;if(fp=fopen("instock.txt","w")=NULL)printf("Can't open file!n");exit(0); for(i=0;i<INSTOCKNUM;i+) printf("电器名称 品牌名称 型号 入库数量 单价 入库时间(年 月 日) 送货人姓名n"); scanf("%s %s %s %d %d %d %d %d %s",ini.elename,ini.brand,ini.type,&ini.instocknum,&ini.price,&ini.intime.year,&ini.intime.month,&ini.intime.day,ini.sendername); printf("有物资入库!n");fwrite(&ini,sizeof(struct instock),1,fp); fclose(fp);read_instock();/读取instock.txt入in;read_stock();/读取stock.txt入stoc;for(k=0;k<INSTOCKNUM;k+)boolean=0;for(j=0;j<STOCKNUM;j+)if(strcmp(stocj.elename,ink.elename)=0 && strcmp(stocj.brand,ink.brand )=0 && strcmp(stocj.type ,ink.type )=0 )stocj.stocknum =stocj.stocknum +ink.instocknum ;boolean=1;if( boolean=0 )/原来库存中没有此类家电strcpy(stocan.elename ,ink.elename );strcpy(stocan.brand ,ink.brand );strcpy(stocan.type ,ink.type );stocan.stocknum =ink.instocknum ;stocan.value=ink.price ;an+;if(fp=fopen("stock.txt","w")=NULL)printf("Can't open file!n");exit(0);fwrite(stoc,sizeof(struct stock),an,fp); fclose(fp);/-void Creatoutstock()/创建出库记录并改变库存记录 int i=0,j=0,k=0,n=0;int sum_stock=0;FILE *fp;sum_stock=read_stock();/读取stock.txt入stocprintf("共有家电物资%d种n",sum_stock);for(n=0;n<OUTSTOCKNUM;n+)printf("电器名称 品牌名称 型号 出库数量 出库时间(年 月 日) 提货人姓名n"); scanf("%s %s %s %d %d %d %d %s",outn.elename,outn.brand,outn.type,&outn.outstocknum ,&outn.outtime .year ,&outn.outtime .month,&outn.outtime .day,outn.delivername); printf("有物资出库!n");if(fp=fopen("outstock.txt","w")=NULL)printf("Can't open file!n"); exit(0);for(j=0;j<OUTSTOCKNUM;j+)for(i=0;i<3;i+)if(strcmp(stoci.elename,outj.elename )=0)&&(strcmp(stoci.brand,outj.brand)=0)&&(strcmp(stoci.type,outj.type)=0) k=1;if(outj.outstocknum<=stoci.stocknum)fwrite(&outj,sizeof(struct outstock),1,fp);stoci.stocknum=stoci.stocknum-outj.outstocknum;printf("资源%s出库成功!n",outj.elename); else if(outj.outstocknum>stoci.stocknum) /else printf("n超出库存量!n按任意键继续!n"); getch(); if( k=0 ) printf("n库存中不存在该信息!n按任意键继续!n"); getch(); fclose(fp);if(fp=fopen("stock.txt","w")=NULL)printf("Can't open file :stock.txt !n");exit(0);fwrite(stoc,sizeof(struct stock),sum_stock,fp); fclose(fp);/-void SearchElename();void SearchBrand();void SearchDate();void SearchElenameAndBrand();void PrintStock(struct stock *p);void PrintInstock(struct instock *p);void PrintOutstock(struct outstock *p);/-void SearchMenu()/查询菜单int select; while(1) printf("n欢迎使用查询功能!n"); printf("*n"); printf(" 输入 1 按电器名称查询 n"); printf(" 输入 2 按品牌名称查询 n"); printf(" 输入 3 按日期查询 n"); printf(" 输入 4 按电器名称和型号查询n"); printf(" 输入 0 退出查询功能n"); printf("n请选择查询方式 :"); scanf("%d",&select); getchar(); switch(select) case 1:SearchElename();break; case 2:SearchBrand();break; case 3:SearchDate();break; case 4:SearchElenameAndBrand();break; case 0:return; default:printf("n错误!请重新选择!n"); /-void SearchElename()/按照电器名称查询 int i;int sum_stock=0;int boolean=0; char celename20,c='y'sum_stock=read_stock();/库存中家电的种类 while(c='y'|c='Y')boolean=0;printf("n请输入电器名称:");scanf("%s",celename);getchar();for(i=0;i<sum_stock;i+)if( strcmp(stoci.elename,celename)=0 )printf("n库存电器%d的信息n",i);PrintStock(&stoci);boolean=1;printf("n按任意键继续!n");getch();if( boolean=0 )printf("没有电器: %sn",celename);printf("n继续查询其他库存信息吗?)(y/n):");c=getchar();getchar();/-void SearchBrand()/按照品牌名称查询int i;int sum_stock=0;int boolean=0;char cbrand20,c='y'sum_stock=read_stock();/库存中家电的种类 while(c='y'|c='Y')boolean=0;printf("n请输入品牌名称:");scanf("%s",cbrand);for(i=0;i<sum_stock;i+)if( strcmp(stoci.brand,cbrand)=0 )printf("n库存电器%d的信息n",i);PrintStock(&stoci);boolean=1;printf("n按任意键继续!n");getch();if( boolean=0 ) printf("没有电器: %sn",cbrand);printf("n继续查询其他库存信息吗?)(y/n):");c=getchar();getchar(); /-void SearchDate()/按照日期查询int i,j;int sum_instock=0,sum_outstock=0;int booleanin=0,booleanout=0;struct date time;sum_instock=read_instock();sum_outstock=read_outstock();printf("n请输入日期: ");scanf("%d%d%d",&time.year,&time.month,&time.day);for(i=0;i<sum_instock;i+)if(ini.intime.year=time.year && ini.intime.month=time.month && ini.intime.day=time.day)PrintInstock(&ini);booleanin+; for(j=0;j<OUTSTOCKNUM;j+)if(outj.outtime.year=time.year && outj.outtime.month=time.month && outj.outtime.day=time.day)PrintOutstock(&outj);booleanout+;if( booleanin=0 && booleanout=0 ) printf("该天没有入、出库信息!n按任意键继续!n");getch();elseif( booleanin=0 && booleanout!=0 ) printf("该天没有入库信息!n按任意键继续!n");getch(); else if( booleanin!=0 && booleanout=0 ) printf("该天没有出库信息!n按任意键继续!n"); getch();/-void SearchElenameAndBrand()/按照电器名称和型号查询int i;int sum_instock=0,sum_outstock=0;int booleanin=0,booleanout=0;char cname20,ctype20;sum_instock=read_instock();/入库家电的种类sum_outstock=read_outstock();/出库家电的种类 printf("n请输入电器名称和型号:");scanf("%s %s",cname,ctype);for(i=0;i<sum_instock;i+)if(strcmp(ini.elename,cname)=0 && strcmp(ini.type,ctype)=0)PrintInstock(&ini);booleanin=1;for(i=0;i<sum_outstock;i+)if(strcmp(outi.elename,cname)=0 && strcmp(outi.type,ctype)=0)PrintOutstock(&outi);booleanout=1; if( booleanin=0 && booleanout=0 )printf("该电器没有入、出库信息!n按任意键继续!n"); getch(); /-void PrintStock(struct stock *p)/输出库存信息 printf("输出库存记录信息!n"); printf("电器名称 品牌名称 型号 库存数量 价值n"); printf("%s %s %s %5d %dn",p->elename,p->brand,p->type,p->stocknum,p->value);/-void PrintInstock(struct instock *p)/输出入库信息 printf("输出入库记录信息!n"); printf("电器名称 t品牌名称 型号 入库数量 单价 入库时间 送货人姓名n"); printf("%stt%st%st%dt %dt %d %d %d %sn",p->elename,p->brand,p->type,p->instocknum,p->price,p->intime.year,p->intime.month,p->intime.day,p->sendername);/-void PrintOutstock(struct outstock *p)/输出出库信息 printf("输出出库记录信息!n"); printf("电器名称 品牌名称 型号 出库数量 出库时间 提货人姓名n"); printf("%s %s %s %d %d %d %d %sn",p->elename,p->brand,p->type,p->outstocknum,p->outtime.year,p->outtime.month,p->outtime.day,p->delivername);/-int Count1();int Count2();int Count3();void Count4();/-void CountMenu()/统计int select;int n1,n2,n3;while(1) printf("n欢迎使用物资统计功能!n"); printf("*n"); printf(" 1 输入电器名称,在库存记录文件中统计现有库存总量n"); printf(" 2 输入电器名称,在入库记录文件中统计入库次数n"); printf(" 3 输入日期(年,月),在出库记录文件中统计该月出库次数n"); printf(" 4 设置库存数量警戒值,输出库存数量小于该警戒值的所有库存电器的信息n"); printf(" 0 退出统计功能n"); printf("n 请选择查询方式 :"); scanf("%d",&select); getchar(); switch(select) case 1:n1=Count1();break; case 2:n2=Count2();break; case 3:n3=Count3();break; case 4:Count4();break; case 0:return; default:printf("n按键错误,请重新选择!n"); /-int Count1()/输入电器名称,在库存记录文件中统计现有库存总量int i;int sum_stock=0;int boolean=0;char cname20;printf("n 请输入电器名称: ");scanf("%s",cname);sum_stock=read_stock(); for(i=0;i<sum_stock;i+)if(strcmp(stoci.elename,cname)=0 ) printf("该电器现有库存总量:%d n",stoci.stocknum ); boolean=1; if( boolean=0 ) printf("库存中没有该电器n");printf("按任意键继续!n");getch();return 1; /-int Count2()/输入电器名称,在入库记录文件中统计入库次数 int i=0,sum=0;int sum_instock=0;int boolean=0;char cname20;printf("n 请输入电器名称: "); scanf("%s",cname);sum_instock=read_instock(); for( i=0;i<sum_instock;i+)if(strcmp(ini.elename,cname)=0 ) sum+;boolean=1;if( boolean=0 ) printf("入库中没有该电器n"); else printf("该电器入库次数:%d n",sum); printf("按任意键继续!n");getch();return 1;/-int Count3()/输入日期(年,月),在出库记录文件中统计该月出库次数 int i=0,sum=0;int sum_outstock=0;int boolean=0;struct date time;sum_outstock=read_outstock(); printf("n 请输入一个日期(年、月): "); scanf("%d%d",&time.year,&time.month );getchar();for(i=0;i<sum_outstock;i+) if(outi.outtime.year=time.year && outi.outtime.month=time.month ) sum+; boolean=1