资源描述
算法与数据结构课程设计仓库货品管理(常用版)
(可以直接使用,可编辑 完整版资料,欢迎下载)
*******************
实践教学
*******************
兰州理工大学
计算机与通信学院
2021年春季学期
算法与数据结构 课程设计
题 目: 仓库货品管理
专业班级:08级计算机科学与技术5班
姓 名: 马菁
学 号: 08240507
指导教师: 李 睿
成 绩:_________________
目 录
摘 要 3
前 言 4
正 文 5
1.采用类c语言定义相关的数据类型 5
2.各模块的伪码算法............................................................................................5
3.函数的调用关系图 12
4.调试分析 13
5.测试结果 13
6.源程序(带注释)..............................................................................................................16
总 结 28
参考文献 30
致 谢 31
附 件Ⅰ部分源程序代码 32
摘 要
本文介绍了小型仓库管理系统的设计与实现。通过对仓库基本功能的分析,该程序实现了对小型仓库管理的基本操作。设计要求主要是货品入库、出库、查找及显示库存量等最基本功能操作。在课程设计过程中,对问题的所采用的数据结构和算法分析,及程序设计语言采用VC,程序运行的平台是WindowsXP(visual C++6.0),逐步对基本要求进行分布实现,在设计中采用单链表和文件对录入的基本数据进行存储,最终对产品进行的基本操作如产品入库、出库及查找都基本以实现。该小型仓库管理系统的界面可视化程度较高,操作者和使用者使用较为便。
关键字: 仓库货品管理 ;单链表 ;数据结构和算法;
前 言
我们对教学计划有一个系统的认识,大学的每个专业都要制定教学计划。假设任何专业都有固定的学习年限,每学年含两学期,每学期的时间长度和学分上限值均相等。每个专业开设的课程都是确定的,而且课程在开设时间的安排必须满足先修关系。每门课程有哪些先修课程是确定的,可以有任意多门,也可以没有。每门课恰好占一个学期。试在这样的前提下设计一个教学计划编制程序。通过该题目的设计过程,可以加深理解数据的逻辑结构、存储结构,掌握线性表上基本运算的实现,进一步理解和熟练掌握课本中所学的各种数据结构,学会如何把学到的知识用于解决实际问题,培养学生的动手能力。通过本次课程设计的制作,能让我们对数据结构以及程序设计有更深的体会,流程图的建立能提高我们系统分析问题的能力,从而灵活的驾驭整个程序的运行,通过对图的顶点的存储,让我们加深对邻接表的应用,更重要的是拓扑排序的复习,大一时,我们曾在离散数学中学习了拓扑排序,此次课程设计不仅能让我们学习数据结构的知识,同时也能让我们系统复习一下图论的知识。
正文
1. 采用类c语言定义相关的数据类型
menu_init ()
+新建仓库 newstore()
+打开仓库 openstore()
+添加货物 addproduct()
+修改货物 editproduct()
+删除货物 delproduct()
+库存管理 menu_store()
-货物出库 instore()
-货物进库 outstore()
+货物查询 menu_check()
+按编号查询 bynumber()
+按名称查询 byname()
+储存数据 savedata()
+所有货物 listall()
+退出系统 exit()
1.2数据设计
商品结构体设计:
struct Product
{
int num; char name[20]; float rice; int amount; struct *next;
};
2各模块的伪码算法:
2.1菜单类:
menu_init();
说明:初始化界面
menu_store();
说明:库存管理界面
menu_check();
说明:货物查询界面
menu exit();
说明:退出界面
2.2货物管理类:
addproduct( struct Product *head );
说明: struct Product *head 为要添加节点的链表
功能:添加货物
流程图:
editproduct( struct Product *head );
说明: struct Product *head 为要修改节点的链表
功能:修改货物
流程图:
delproduct( struct Product *head );
说明: struct Product *head 为要修改节点的链表
功能:删除货物
流程图:
instore( struct Product *head );
说明: struct Product *head 为要修改节点的链表
功能:修改货物
outstore( struct Product *head );
说明: struct Product *head 为要修改节点的链表
功能:修改货物
outinstore( struct Product *head, int ouin );
说明: struct Product *head 为要修改节点的链表
功能:出库进库综合操作类
2.3货物查询类:
bynumber( struct Product *head, int num );
说明: struct Product *head 为要修改节点的链表, num 为商品编号
功能:按编号查询商品
byname( struct Product *head, char *name );
说明: struct Product *head 为要修改节点的链表, name 为商品名称
功能:按名称查询商品
listall( struct Product *head );
说明: struct Product *head 为要显示链表
功能:显示所有商品
流程图:
2.4仓库管理类:
openstore( );
说明: 打开仓库数据文件到链表
功能:打开仓库文件
NS流程图:
struct Product *h = NULL;
filename
01.2 1.4 1.6 1.7 1.8 1.9 1.10 2.1 2.4 3.1 3.2 3.5 4.1 4.2 4.3 5.1 5.2 5.3 5.4 6.2 6.3
输入文件名filename
fp = fopen (filename,”rb”)
T
F
while( !feof(fp) )
fread( pd, Length, 1, fp )
F
return h;
return h;
q = pd;
pd = pd ->next;
break;
q->next; return h;
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 <stdio.h>
#include <stdlib.h>
/*#include <conio.h>*/
#include <malloc.h>
#include <string.h>
#define Length sizeof( struct Product )
/*定义货品结构体*/
struct Product
{
int num;
char name[20];
float rice;
int amount;
struct Product *next;
};
void cls( void )
{
int i;
for( i=0; i<1; i++)
printf("\n");
}
/*
打开仓库,从把文件数据读入链表
返回链表
*/
struct Product *openstore()
{
char filename[255];
struct Product *h, *pd, *q;
FILE *fp;
h = NULL;
printf("请输入要打开的仓库数据文件(如:store):\n");
scanf("%s", &filename);
if( filename[0] == '0' ) return h;
if( (fp=fopen(filename, "rb") ) == NULL )
{
printf("打开文件出错\n");
// getch();
return h;
}
printf("正在打开文件\n");
pd = ( struct Product *)malloc( Length );
if( pd == NULL)
{
printf("内存溢出\n");
// getch();
return(h);
}
h = pd;
while( !feof(fp) )
{
if( fread( pd, Length, 1, fp)!=1 ) break;
pd->next = (struct Product *)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);
}
int savedata( struct Product *head )
{
char filename[255];
struct Product *pd;
FILE *fp;
pd = head;
printf("请输入要保存的仓库数据文件名(如:store,0取消):\n");
scanf("%s", &filename);
if( filename[0] == '0' ) return 1;
if( (fp=fopen(filename, "wb") ) == NULL )
{
printf("储存文件出错\n");
// getch();
return 1;
}
printf("正在储存数据...\n");
while( pd!=NULL )
{
fwrite( pd, Length, 1, fp);
pd = pd->next;
}
fclose( fp );
printf("仓库数据保存成功\n");
// getch();
return 0;
}
/*
//创建链表,新建一个仓库,并输入数据
//返回链表
*/
struct Product *newstore()
{
struct Product *h = NULL, *pd;
for(;;)
{
pd = (struct Product *)malloc( Length );
if (!pd)
{
printf("内存溢出!\n");
// getch();
return NULL;
}
printf("请输入货品编号(0退出):\n");
scanf("%d", &pd->num);
if( pd->num == 0 ) break;
printf("请输入货品名称:\n");
scanf("%s", &pd->name);
printf("请输入货品价格:\n");
scanf("%f", &pd->rice);
printf("请输入货品库存量:\n");
scanf("%d", &pd->amount );
printf("\n");
pd->next = h;
h = pd;
}
return(h);
}
/*
//添加货品,向链表末尾添加货品
//参数:*head链表指针
//返回添加货品的链表
*/
struct Product *addproduct( struct Product *head )
{
struct Product *h, *pd;
if( !head )
{
printf("请先创建或打开仓库\n");return head;
}
else
{
h = head;
}
for(;;)
{
pd = (struct Product *)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->rice);
printf("请输入货品库存量:\n");
scanf("%d", &pd->amount );
printf("\n");
while( h->next!=NULL )
{
h = h->next;
}
h->next = pd;
pd->next = NULL;
}
return(h);
}
/*
//按编号查找货品
//参数:*head链表指针,*num货品编号
//返回:链表结点
*/
struct Product *bynumber( struct Product *head, int num )
{
float total;
int n = num;
struct Product *pd;
pd = head;
while( pd!=NULL&&pd->num!=n)
{
pd = pd->next;
}
if( pd == NULL)
{
printf("没有该编号货品。\n");
// getch();
}
else
{
printf("\t********************按编号查询货品************************\n");
printf("\t| 编号 | 名称 | 价格 | 库存 | 价值量 |\n");
printf("\t|------|-------------|---------|--------|---------|\n");
printf("\t|%6d|%-13s|%9.3f|%8d|", pd->num, pd->name, pd->rice, pd->amount);
total = pd->rice * pd->amount;
printf("%9.3f|\n", total);
printf("\t*************************************************************\n");
// getch();
}
return(pd);
}
/*
//按名称查找货品
//参数:*head链表指针,*name货品名称
//返回:链表结点*/
struct Product *byname( struct Product *head, char name[20] )
{
float total;
struct Product *pd;
pd = head;
while( pd!=NULL&&strcmp(pd->name, name)!=0)
{
pd = pd->next;
}
if( pd == NULL)
{
printf("没有该名称货品。\n");
// getch();
}
else
{
printf("\t*********************按名称查询货品*****************************\n");
printf("\t| 编号 | 名称 | 价格 | 库存 | 价值量 |\n");
printf("\t|------|------------------|---------|--------|---------|\n");
printf("\t|%6d|%-18s|%9.3f|%8d|", pd->num, pd->name, pd->rice, pd->amount);
total = pd->rice * pd->amount;
printf("%9.3f|\n", total);
printf("\t****************************************************************\n");
// getch();
}
return(pd);
}
void *checkbynumber( struct Product *head )
{
struct Product *h = head;
int num;
printf("请输入查询编号(0退出):\n");
scanf("%d", &num);
return bynumber( h, num);
}
void *checkbyname( struct Product *head )
{
struct Product *h = head;
char name[20];
printf("请输入货品名称(0退出):\n");
scanf("%s", &name);
return byname( h, name);
}
/*
//修改货品
//参数:*head链表指针
//返回:链表结点
*/
struct Product *editproduct( struct Product *head )
{
int num;
struct Product *h, *pd;
h = head;
for(;;)
{
pd = (struct Product *)malloc( Length );
if (!pd)
{
printf("内存溢出!\n");
// getch();
break;
}
printf("请输入要修改的货品编号:(0退出)\n");
scanf("%d", &num);
if( num == 0 ) break;
pd = bynumber( h, num);
if( pd == NULL) break;
printf("请输入货品新名称:\n");
scanf("%s", &pd->name);
printf("请输入货品新价格:\n");
scanf("%f", &pd->rice);
printf("\n");
}
return(h);
}
struct Product *delproduct( struct Product *head )
{
int num;
char confirm;
struct Product *h, *q, *pd;
pd = q = h = head;
for(;;)
{
printf("请输入要删除的货品编号:(0退出)\n");
scanf("%d", &num);
if( num == 0 ) break;
while( pd!=NULL&&pd->num!=num)
{
q = pd;
pd = pd->next;
}
if( pd == NULL)
{
printf("没有该编号货品。\n");
}
else
{
bynumber( h, num);
// getch();
if(pd==h) /*如果p==h,说明被删结点是头结点*/
h=pd->next; /*修改头指针指向下一条记录*/
else
q->next=pd->next;
printf("删除成功\n");
}
}
return(h);
}
/*
//货品进库出库
//参数:*head链表指针, *outin为进库出库类型,0表示出库
//返回:链表结点
*/
struct Product *outinstore( struct Product *head, int outin )
{
int num, outnum;
struct Product *h, *pd;
h = head;
for(;;)
{
pd = (struct Product *)malloc( Length );
if (!pd)
{
printf("内存溢出!\n");
// getch();
break;
}
printf("请输入要修改的货品编号:(0退出)\n");
scanf("%d", &num);
if( num == 0 ) break;
pd = bynumber( h, num);
if(!pd) break;
if( outin == 0)
{
printf("请输入货品出库数量:\n");
scanf("%d", &outnum);
pd->amount = pd->amount - outnum;
}
else
{
printf("请输入货品进库数量:\n");
scanf("%d", &outnum);
pd->amount = pd->amount + outnum;
}
printf("\n");
}
return(h);
}
/*
//货品出库
*/
struct Product *outstore(struct Product *head)
{
struct Product *h = head;
return outinstore(h, 0);
}
/*
//货品进库
*/
struct Product *instore(struct Product *head)
{
struct Product *h = head;
return outinstore(h, 1);
}
void listall( struct Product *head)
{
float total=0, all=0;
struct Product *pd;
pd = head;
if( pd == NULL )
{
cls();
printf("错误:当前未打开任何仓库\n");
// getch();
return;
}
cls();
printf("\t***********************仓库内所有货品*************************\n");
printf("\t\t| 编号 | 名称 | 价格 | 库存 | 价值量 |\n");
printf("\t\t|------|-------------|---------|--------|---------|\n");
do
{
printf("\t\t|%6d|%-13s|%9.3f|%8d|", pd->num, pd->name, pd->rice, pd->amount);
total = pd->rice * pd->amount;
all+= total;
printf("%9.3f|\n", total);
pd = pd->next;
} while(pd!=NULL);
printf("\t**************************************************************\n");
printf("\t仓库货品总价值量为:%12.3f元\n", all);
printf("\t**************************************************************\n");
// getch();
}
void menu_store( struct Product *head )
{
int select;
for(;;)
{
printf("\t*******************************************************\n");
printf("\t\t算法与数据结构课程设计-仓库货品管理\n");
printf("\t*******************************************************\n");
printf("\t\t\t\t1.货品出库\n");
printf("\t\t\t\t2.货品进库\n");
printf("\t\t\t\t0.返 回\n");
printf("\t*******************************************************\n");
printf("请选择操作:");
scanf("%d", &select);
switch(select)
{
case 0: return;
case 1: head = outstore(head); break;
case 2: head = instore(head);
}
}
}
void menu_check( struct Product *head )
{
int select;
for(;;)
{
printf("\t*******************************************************\n");
printf("\t\t算法与数据结构课程设计-仓库货品管理\n");
printf("\t*******************************************************\n");
printf("\t\t\t\t1.按编号查询\n");
printf("\t\t\t\t2.按名称查询\n");
printf("\t\t\t\t0.返 回\n");
printf("\t*******************************************************\n");
printf("请选择操作:");
scanf("%d", &select);
switch(select)
{
case 0: return;
case 1: checkbynumber( head ); break;
case 2
展开阅读全文