最新C语言进销存管理系统-源程序.doc
Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateC语言进销存管理系统-源程序综合性程序设计报告C语言课程设计综合性程序设计报告之源程序设计题目:电脑公司进销存管理系统专业:冶金工程学号:8090507姓名:刘欢成 绩: _设计时间: 2010年 11月 03 日二开题说明1.问题概要该系统用于处理某电脑公司的设备买入,卖出,仓储等设备账目。在买入设备时,记录设备的数量型号(如computer,keyboard)和价钱,并在库房记录中添加设备,在卖出设备时从库房中减掉该设备,并根据卖出的数量型号和价钱得出每一笔买出的利润。每个一段时间盘点库房和账目计算出利润等数据。基本要求:有货物管理(设备的添加,删除,修改)有账目管理可以查询账目清单可以计算年度或月份或季度利润。2.问题分析: 先定义合适的结构体,存储物品信息。在程序中建立一个文件用于存储,凡进行了进货操作的物品在文件中都有记录,进货时由于尚不知售货时间与售价、利润,故此三项(实际为四项,时间分为年、月两项)暂先赋值为零,待进行售货操作时再输入各数值,其中利润由系统自动计算得出并保存。账目清单分为已售、仓储两部分,由此可看到所有购进、卖出的货物信息。月利润查询可查得所输入年月的各类所售货物数量与利润。三 功能模块菜单进货操作售货操作修改信息账目清单退出月利润查询四源程序#include <stdio.h>#include <stdlib.h>#include <conio.h>#include <dos.h>#include <string.h>#define LEN sizeof(struct object)#define FORMAT1 "t%-8d%-11s%-9.2f%-6d%-4dn"#define DATA1 (p1+i)->num,(p1+i)->name,(p1+i)->inprice,(p1+i)->inyear,(p1+i)->inmonth#define FORMAT2 "t%-8d%-11s%-9.2f%-9.2f%-7.2f%-6d%-4d%-6d%-4dn"#define DATA2 (p1+i)->num,(p1+i)->name,(p1+i)->inprice,(p1+i)->outprice,(p1+i)->profit,(p1+i)->inyear,(p1+i)->inmonth,(p1+i)->outyear,(p1+i)->outmonthvoid in();void show();void modify();void sell(); void menu();void monthearn(); struct objectint num,inyear,inmonth,outyear,outmonth;char name10;float inprice,outprice,profit; obj100; struct object *p1=obj;main() int n;menu(); while(n)switch(n)case 1: in();break;case 2:sell();break;case 3:modify();break;case 4:show();break;case 5:monthearn();break;default:break;getch();menu();scanf("%d",&n);void menu()/菜单system("cls");printf("nnnnnn");printf("tt*菜单*n");printf("tt 0.退出n"); printf("tt 1.进货操作n"); printf("tt 2.售货操作n"); printf("tt 3.修改信息n"); printf("tt 4.账目清单n"); printf("tt 5.月利润查询n"); printf("tt*n");void in() /进货操作int i,m=0;char ch2;FILE *p;if( (p=fopen("data","a+")=NULL)printf("打不开文件!n"); /打开文件return;while(!feof(p)if(fread(&objm,LEN,1,p)=1) m+; /将数据读入内存fclose(p);if(m=0)printf("无记录!n");printf("请确认是否进货?(y/n)");scanf("%s",ch);while(strcmp(ch,"y")=0|strcmp(ch,"y")=0) printf("请输入设备编号:");scanf("%d",&objm.num);for(i=0;i<m;i+)if(p1+i)->num=objm.num)printf("此号已存在,按任意键继续!");getch();fclose(p);return;printf("设备名称:");scanf("%s",objm.name);printf("进价:");scanf("%f",&objm.inprice);printf("进货年、月:");scanf("%d%d",&objm.inyear,&objm.inmonth);objm.outprice=0;objm.outyear=0;(p1+m)->outmonth=0;fopen("data","w"); /打开文件用以向磁盘导入数据for(i=0;i<=m;i+)fwrite(&obji,LEN,1,p);if(fwrite(&objm,LEN,1,p)!=1)printf("无法保存!");getch();else printf("%s 保存成功!n",objm.name);m+;printf("继续?(y/n)");scanf("%s",ch);fclose(p);printf("保存完毕!n");void sell() /售货操作FILE *p;int snum,i,j,m=0;char ch2;if(p=fopen("data","rb")=NULL)printf("无法打开文件!n");return; /打开文件while(!feof(p)if(fread(&objm,LEN,1,p)=1)m+; /读入fclose(p);if(m=0)printf("无记录!n");return;printf("请输入编号:");scanf("%d",&snum);for(i=0;i<m;i+)if(snum=(p1+i)->num)break;if(i<m) /判断1printf("查得此物品,确认出售?(y/n)");scanf("%s",ch);if(strcmp(ch,"y")=0|strcmp(ch,"Y")=0) /判断2printf("请输入售价:"); scanf("%f",&(p1+i)->outprice);(p1+i)->profit=(p1+i)->outprice-(p1+i)->inprice);printf("n请输入售出年、月:");scanf("%d%d",&(p1+i)->outyear,&(p1+i)->outmonth);if(p=fopen("data","wb+")=NULL)printf("打不开文件!n");return;for(j=0;j<m;j+)if(fwrite(&objj,LEN,1,p)!=1)printf("无法保存!n");getch(); printf("售货成功!"); fclose(p);return;else return; /判断2else printf("无此物品!");return; /判断1void modify() /修改信息FILE *p;int i,j,m=0,snum;if(p=fopen("data","rb")=NULL)printf("打不开文件!n");return;while(!feof(p)if(fread(&objm,LEN,1,p)=1)m+;if(m=0)printf("无记录!n");fclose(p);return;printf("请输入欲修改信息的货物编号:"); scanf("%d",&snum);for(i=0;i<m;i+)if(snum=(p1+i)->num)break;if(i<m) printf("找到此货物!n");printf("n名称:");scanf("%s",(p1+i)->name);printf("n进价:");scanf("%f",&(p1+i)->inprice);printf("n进货年、月:");scanf("%d%d",&(p1+i)->inyear,&(p1+i)->inmonth);if(p=fopen("data","wb+")=NULL)printf("打不开文件!n"); return;for(j=0;j<m;j+)if(fwrite(&objj,LEN,1,p)!=1)printf("无法保存!");getch();fclose(p);else printf("无此货物!");return;void show() /账目清单FILE *p;int i,m=0;if(p=fopen("data","rb")=NULL)printf("打不开!");while(!feof(p)if(fread(&objm,LEN,1,p)=1)m+; fclose(p);printf("已售nt编号 名称 进价 售价 利润 进货时间 出售时间tn");for(i=0;i<m;i+)if(p1+i)->profit!=0)printf(FORMAT2,DATA2);printf("仓储n");printf("t编号 名称 进价 进货时间tn");for(i=0;i<m;i+)if(p1+i)->profit=0)printf(FORMAT1,DATA1);void monthearn()/月利润FILE *p;int m=0,s=0,a=0,b=0,c=0,d=0,y,z;float sum1=0,sum2=0,sum3=0,sum4=0;if(p=fopen("data","rb")=NULL)printf("打不开文件!n");return; /打开文件while(!feof(p)if(fread(&objm,LEN,1,p)=1)m+;fclose(p); /将数据读入内存 printf("请输入欲查询的年份、月份:"); scanf("%d%d",&y,&z);for(s=0;s<m;s+)if(strcmp(objs.name,"zhuji")=0)&&(y=objs.outyear)&&(z=objs.outmonth)a+;sum1+=objs.profit;if(strcmp(objs.name,"xianshiqi")=0)&&(y=objs.outyear)&&(z=objs.outmonth)b+;sum2+=objs.profit; if(strcmp(objs.name,"jianpan")=0)&&(y=objs.outyear)&&(z=objs.outmonth)c+;sum3+=objs.profit; if(strcmp(objs.name,"shubiao")=0)&&(y=objs.outyear)&&(z=objs.outmonth)d+;sum4+=objs.profit;printf("本月共售出n");printf("t主机 %d台,总利润 %7.2f 元n",a,sum1); printf("t显示器 %d台,总利润 %7.2f 元n",b,sum2); printf("t键盘 %d台,总利润 %7.2f 元n",c,sum3); printf("t鼠标 %d台,总利润 %7.2f 元n",d,sum4);-