仓库管理系统.docx
《仓库管理系统.docx》由会员分享,可在线阅读,更多相关《仓库管理系统.docx(54页珍藏版)》请在冰豆网上搜索。
仓库管理系统
*******************
实践教学
*******************
兰州理工大学
计算机与通信学院
2011年秋季学期
面向对象课程设计
题目:
仓库管理系统
专业班级:
计算机科学与技术一班
姓名:
海发明
学号:
10240102
指导教师:
年福忠
成绩:
_______________
目录
摘要--------------------------------------------------------------------------------------1
序言--------------------------------------------------------------------------------------2
正文--------------------------------------------------------------------------------------3
1.采用类c++语言定义相关的数据类型-----------------------------------------------5
2.各模块的伪码算法.---------------------------------------------------------------------5
3.函数的调用关系图----------------------------------------------------------------------12
4.调试分析----------------------------------------------------------------------------------13
5.测试结果----------------------------------------------------------------------------------13
6.源程序(带注释)------------------------------------------------------------------------------------16
总结-------------------------------------------------------------------------------------28
参考文献-------------------------------------------------------------------------------------30
致谢-------------------------------------------------------------------------------------31
附件部分源程序代码-----------------------------------------------------------------33
摘要
本程序主要介绍了小型仓库货品管理的设计与基本功能的实现。
通过对仓库基本功能的分析,该程序实现了对小型仓库管理的基本操作。
设计要求主要是货品入库、出库、增加、删除、查找及显示库存量等最基本功能操作。
在课程设计过程中,对问题的所采用的数据结构和算法分析,及程序设计语言采用VC++,程序运行的平台WindowsXP(visualC++6.0),逐步对基本要求进行分布实现,在设计中采用单链表和文件对录入的基本数据进行存储,最终对产品进行的基本操作如产品入库、出库及查找都基本以实现。
关键字:
c++,结构体,软件,插入;
序言
现代科学技术的飞速发展,改变了世界,也改变了人类的生活,作为新世纪的大学生,应当站在时代发展的前列,掌握现代科学技术知识,调整自己的知识结构和能力结构,以适应社会发展的要求。
掌握计算机知识和应用,无疑是培养新型人才的一个重要环节。
对于我们计算机专业的学生来说,想要把所学知识用于实践,课程设计是一个很好的环节,课程设计不仅提高了我们的设计能力和操作能力,加深理解了数据的逻辑结构、存储结构,掌握线性表上基本运算的实现,进一步理解和熟练掌握课本中所学的各种数据结构,而且学会了如何把学到的知识用于解决实际问题。
通过本次课程设计的制作,能让我们对数据结构以及程序设计有更深的体会,流程图的建立能提高我们系统分析问题的能力,从而灵活的驾驭整个程序的运行,对于具体问题,找出具体的解决方案或是多种解决方案,增强我们的创新能力。
正文
1.采用类c++语言定义相关的数据类型
menu_init()
+新建仓库newstore()
+打开仓库openstore()
+添加货物addproduct()
+修改货物editproduct()
+删除货物delproduct()
+库存管理menu_store()
-货物出库instore()
-货物进库outstore()
+货物查询menu_check()
+按编号查询bynumber()
+按名称查询byname()
+储存数据savedata()
+所有货物listall()
+退出系统exit()
1.2数据设计
商品结构体设计:
structProduct
{
intnum;charname[20];floatprice;intamount;charfac[50];charbuss[50];struct*next;
};
2各模块的伪码算法:
2.1菜单类:
menu_init();
说明:
初始化界面
menu_store();
说明:
库存管理界面
menu_check();
说明:
货物查询界面
menuexit();
说明:
退出界面
2.2货物管理类:
addproduct(structProduct*head);
说明:
structProduct*head为要添加节点的链表
功能:
添加货物
流程图:
editproduct(structProduct*head);
说明:
structProduct*head为要修改节点的链表
功能:
修改货物
流程图:
delproduct(structProduct*head);
说明:
structProduct*head为要修改节点的链表
功能:
删除货物
流程图:
instore(structProduct*head);
说明:
structProduct*head为要修改节点的链表
功能:
修改货物
outstore(structProduct*head);
说明:
structProduct*head为要修改节点的链表
功能:
修改货物
outinstore(structProduct*head,intouin);
说明:
structProduct*head为要修改节点的链表
功能:
出库进库综合操作类
2.3货物查询类:
bynumber(structProduct*head,intnum);
说明:
structProduct*head为要修改节点的链表,num为商品编号
功能:
按编号查询商品
byname(structProduct*head,char*name);
说明:
structProduct*head为要修改节点的链表,name为商品名称
功能:
按名称查询商品
listall(structProduct*head);
说明:
structProduct*head为要显示链表
功能:
显示所有商品
流程图:
2.4仓库管理类:
openstore();
说明:
打开仓库数据文件到链表
功能:
打开仓库文件
NS流程图:
structProduct*h=NULL;
filename
01.21.41.61.71.81.91.102.12.43.13.23.54.14.24.35.15.25.35.46.26.3
输入文件名filename
fp=fopen(filename,”rb”)
T
F
while(!
feof(fp))
fread(pd,Length,1,fp)
F
returnh;
returnh;
q=pd;
pd=pd->next;
break;
q->next;returnh;
savedata();
说明:
写仓库链表数据到文件
功能:
储存货品数据
2.5辅助类:
cls();
说明:
换行
功能:
换行
3.函数的调用关系图:
四、五、调试分析与结果:
1程序运行时初始界面
2新建仓库
用键盘输入1,程序调用新建仓库功能函数,要求用户输入货物编号,货物名称,货物价格等。
3打开仓库文件
用键盘输入2,程序调用打开仓库文件功能函数,要求用户输入仓库数据文件名,数据文件存在,显示打开成功。
4添加货物
用键盘输入3,程序调用添加货物功能函数,要求用户输入货物编号,货物名称,货物价格等。
5修改货物
用键盘输入4,程序调用修改货物功能函数,要求用户输入货物编号,货物存在,显示货物详细信息,按任意键后,要求用户输入新货物名称,货物价格等。
6删除货物
用键盘输入5,程序调用删除货物功能函数,要求用户输入货物编号,货物存在,显示货物详细信息,按任意键后,删除货物。
7库存管理:
用键盘输入6,程序调用库存管理功能函数,显示库存管理子页面,选择2,货物出库,要求用户输入货物编号,货物存在,显示货物详细信息,要求用户输入进库数量。
8货物查询
用键盘输入7,程序调用货物查询功能函数,显示货物查询子页面,选择1,按编号查询,要求用户输入货物编号,货物存在,显示货物详细信息。
货若物不存在,显示“没有该编号货物”。
9储存数据
用键盘输入8,程序调用储存数据功能函数,要求用户输入文件名,将数据储存在指定文件中。
10所有货物
用键盘输入9,程序调用所有货物功能函数,显示仓库内所有货物。
11退出系统
用键盘输入0,程序调用货退出系统功能函数,显示提示保存信息。
6.源程序(带注释):
#include
#include
#include
#include
#defineLengthsizeof(structProduct)
structProduct//定义货品结构体
{
intnum;//编号
charname[20];//名称
floatprice;//价格
intamount;//库存数量
charfac[50];//生产厂家
charbuss[50];//提供商家
structProduct*next;
};
voidcls(void)
{
inti;
for(i=0;i<1;i++)
printf("\n");
}
//打开仓库,从把文件数据读入链表返回链表
structProduct*openstore()
{
charfilename[255];
structProduct*h,*pd,*q;
FILE*fp;
h=NULL;
printf("请输入要打开的仓库数据文件(如:
D:
//store.txt):
\n");
scanf("%s",&filename);
if(filename[0]=='0')returnh;
if((fp=fopen(filename,"rb"))==NULL)
{
printf("打开文件出错\n");
//getch();
returnh;
}
printf("正在打开文件\n");
pd=(structProduct*)malloc(Length);
if(pd==NULL)
{
printf("内存溢出\n");
//getch();
return(h);
}
h=pd;
while(!
feof(fp))
{
if(fscanf(fp,"%d\t%s\t%f\t%d\t%s\t%s\n",&pd->num,&pd->name,&pd->price,&pd->amount,&pd->fac,&pd->buss)==NULL)
break;
pd->next=(structProduct*)malloc(Length);
if(pd->next==NULL)
{
printf("内存溢出\n");
//getch();
return(h);
}
q=pd;
pd=pd->next;
}
q->next=NULL;
fclose(fp);
printf("成功打开仓库数据文件\n");
//getch();
return(h);
}
intsavedata(structProduct*head)
{
charfilename[255];
structProduct*pd;
FILE*fp;
pd=head;
printf("请输入要保存的仓库数据文件名(如:
D:
//store.txt,0取消):
\n");
scanf("%s",&filename);
if(filename[0]=='0')
return1;
if((fp=fopen(filename,"wb"))==NULL)
{
printf("储存文件出错\n");
//getch();
return1;
}
printf("正在储存数据...\n");
while(pd!
=NULL)
{
fprintf(fp,"%d\t%s\t%f\t%d\t%s\t%s\n",pd->num,pd->name,pd->price,pd->amount,pd->fac,pd->buss);
pd=pd->next;
}
fclose(fp);
printf("仓库数据保存成功\n");
//getch();
return0;
}
//创建链表,新建一个仓库,并输入数据
//返回链表
structProduct*newstore()
{
structProduct*h=NULL,*pd;
for(;;)
{
pd=(structProduct*)malloc(Length);
if(!
pd)
{
printf("内存溢出!
\n");
//getch();
returnNULL;
}
printf("请输入货品编号(0退出):
\n");
scanf("%d",&pd->num);
if(pd->num==0)
break;
printf("请输入货品名称:
\n");
scanf("%s",&pd->name);
printf("请输入货品价格:
\n");
scanf("%f",&pd->price);
printf("请输入货品库存量:
\n");
scanf("%d",&pd->amount);
printf("请输入货品的生产厂家:
\n");
scanf("%s",&pd->fac);
printf("请输入货品的提供商家:
\n");
scanf("%s",&pd->buss);
printf("\n");
pd->next=h;
h=pd;
}
return(h);
}
//添加货品,向链表末尾添加货品
//参数:
*head链表指针
//返回添加货品的链表
structProduct*addproduct(structProduct*head)
{
structProduct*h,*pd;
if(!
head)
{
printf("请先创建或打开仓库\n");
returnhead;
}
else
{
h=head;
}
for(;;)
{
pd=(structProduct*)malloc(Length);
if(!
pd)
{
printf("内存溢出!
\n");
//getch();
break;
}
printf("请输入货品编号(0退出):
\n");
scanf("%d",&pd->num);
if(pd->num==0)
break;
printf("请输入货品名称:
\n");
scanf("%s",&pd->name);
printf("请输入货品价格:
\n");
scanf("%f",&pd->price);
printf("请输入货品库存量:
\n");
scanf("%d",&pd->amount);
printf("请输入货品的生产厂家:
\n");
scanf("%s",&pd->fac);
printf("请输入货品的提供商家:
\n");
scanf("%s",&pd->buss);
printf("\n");
while(h->next!
=NULL)
{
h=h->next;
}
h->next=pd;
pd->next=NULL;
}
return(h);
}
//按编号查找货品
//参数:
*head链表指针,*num货品编号
//返回:
链表结点
structProduct*bynumber(structProduct*head,intnum)
{
floattotal;
intn=num;
structProduct*pd;
pd=head;
while(pd!
=NULL&&pd->num!
=n)
{
pd=pd->next;
}
if(pd==NULL)
{
printf("没有该编号货品。
\n");
//getch();
}
else
{
printf("********************按编号查询货品**************************************\n");
printf("|编号|名称|价格|库存|生产厂家|提供商家|价值量|\n");
printf("|------|-------------|---------|--------|----------|----------|----------|\n");
printf("|%6d|%-13s|%-9.3f|%-8d|%-10s|%-10s|",pd->num,pd->name,pd->price,pd->amount,pd->fac,pd->buss);
total=pd->price*pd->amount;
printf("%-10.3f|\n",total);
printf("************************************************************************\n");
//getch();
}
return(pd);
}
//按名称查找货品
//参数:
*head链表指针,*name货品名称
//返回:
链表结点
structProduct*byname(structProduct*head,charname[20])
{
floattotal;
structProduct*pd;
pd=head;
while(pd!
=NULL&&strcmp(pd->name,name)!
=0)//查找货品
{
pd=pd->next;
}
if(pd==NULL)
{
printf("没有该名称货品。
\n");
//getch();
}
else
{
printf("*********************按名称查询货品**************************************\n");
printf("|编号|名称|价格|库存|生产厂家|提供商家|价值量|\n");
printf("|------|-------------|---------|--------|----------|----------|---------|\n");
printf("|%6d|%-13s|%-9.3f|%-8d|%-10s|%-10s|",pd->num,pd->name,pd->price,pd->amount,pd->fac,pd->buss);
total=pd->price*pd->amount;
printf("%-10.3f|\n",total);
printf("************************************************************************\n");
//getch();
}
return(pd);
}
void*checkbynumber(structProduct*head)
{
structProduct*h=head;
intnum;
printf("请输入查询编号(0退出):
\n");
scanf("%d",&num);
returnbynumber(h,num);
}
void*checkbyname(structProduct*head)
{
structProduct*h=head;
charname[20];
printf("请输入货品名称(0退出):
\n");
scanf("%s",&name);
returnbyname(h,name);
}
//修改货品
//参数:
*head链表指针
//返回:
链表结点
structProduct*editproduct(structProduct*head)
{
intnum;
str