算法与数据结构课程设计 产品进销存管理系统.docx

上传人:b****6 文档编号:6127460 上传时间:2023-01-04 格式:DOCX 页数:18 大小:169.95KB
下载 相关 举报
算法与数据结构课程设计 产品进销存管理系统.docx_第1页
第1页 / 共18页
算法与数据结构课程设计 产品进销存管理系统.docx_第2页
第2页 / 共18页
算法与数据结构课程设计 产品进销存管理系统.docx_第3页
第3页 / 共18页
算法与数据结构课程设计 产品进销存管理系统.docx_第4页
第4页 / 共18页
算法与数据结构课程设计 产品进销存管理系统.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

算法与数据结构课程设计 产品进销存管理系统.docx

《算法与数据结构课程设计 产品进销存管理系统.docx》由会员分享,可在线阅读,更多相关《算法与数据结构课程设计 产品进销存管理系统.docx(18页珍藏版)》请在冰豆网上搜索。

算法与数据结构课程设计 产品进销存管理系统.docx

算法与数据结构课程设计产品进销存管理系统

实习报告

题目:

编制一个产品进销存管理系统的程序

一、需求分析

1.针对食品这一行业,对其进行库房的产品进销存管理,选择线性顺序表来存储产品类,选择线性链表来存储属于此产品类的产品,并将产品链挂接到相应的产品类上。

其中存储产品时还应将属于此产品的一些信息如产品的进货总量,进货日期,销出数量,销售时间等进行相应存储。

2.能够对此库房产品进销存管理系统进行产品类的添加、产品的添加、产品数量的添加。

3.能够用一定的查询方法查询库房每种产品的总量、进货日期、销出数量、销售时间等

4.本演示程序以用户和计算机的对话方式执行,即在计算机终端上显示“提示信息”之后,由用户在键盘上输入演示程序中规定的操作命令;相应的操作结果显示在其后。

二、概要设计

1.设定顺序表挂接链表的抽象数据类型定义:

ADTsqmountlink{

数据对象:

D={ai|ai∈kindlist,i=1,2,…,n,n≥0}

数据关系:

R={|ai-1,ai∈D,i=2,3,…,n}

基本操作:

InitMountList(&L)

操作结果:

构造一个空的顺序表挂接链表L。

DestroyMountList(&L)

初始条件:

顺序表挂接链表L已存在。

操作结果:

销毁顺序表挂接链表L。

CreatMountList(&L)

初始条件:

顺序表挂接链表L不存在。

操作结果:

创建一个顺序表挂接链表L,并将L返回。

KindInsert(&L,n)

初始条件:

顺序表挂接链表L已存在。

操作结果:

向顺序表挂接链表L中添加n个产品类。

ProductInsert(&L,i,n)

初始条件:

顺序表挂接链表L已存在且要将产品插入的产品

类i已存在。

操作结果:

向顺序表挂接链表L中的产品类i中添加n种产品。

ProQuantity_add(&L,i,e,n)

初始条件:

顺序表挂接链表L已存在且需添加数量的产品

及产品所属的类也已存在。

操作结果:

添加顺序表挂接链表L的产品类i中的产品e的总量。

Visit(&L,i,e)

初始条件:

顺序表挂接链表L已存在且待查询产品所属产品类i也已存在。

操作结果:

在顺序表挂接链表L中查询产品e的各项信息(

其进货总量、进货日期、销

出数量、销售时间等)。

DisplayList(&L)

初始条件:

顺序表挂接链表L已存在。

操作结果:

显示顺序表挂接链表L的内容。

}

2.本程序包含两个模块:

1)主程序模块:

voidmain()

{

初始化一个空的顺序表挂接链表L;

创建初始的产品类、产品顺序表挂接链表L;

列出要执行的各项操作;

Loop:

输入各项操作命令;

switch(命令)

{

接受命令;

处理命令;

}

}

2)顺序表挂接链表单元模块——实现顺序表挂接链表的抽象数据类型;

各模块之间的调用关系如下:

主程序模块

顺序表挂接链表单元模块

三、详细设计

1.程序设计

#include

#include

#include

#defineok1

#defineerror0

#defineoverflow0

#defineSQMOUNTLINK_INIT_SIZE100

#defineSQMOUNTLINKINCREMENT10

typedefstructdate

{

intyear;

intmonth;

intday;

}date;//日期

typedefstructproductlnode

{

charpname[30];//产品名称

inttotalquantity;//产品总量

dategoodsdate;//进货日期

intsalesquantity;//销出数量

datesalestime;//销售时间

structproductlnode*nextproduct;

}productlnode,*plinklist;

typedefstructkindlnode

{

productlnode*firstproduct;

charpkindname[30];

}kindlnode;

typedefstruct{

kindlnode*kindelem;

intlength;

intlistsize;

}sqmountlink;

intInitMountList(sqmountlink&L)

{//初始化一个空的顺序表挂接链表L

inti;

L.kindelem=(kindlnode*)malloc(SQMOUNTLINK_INIT_SIZE*sizeof(kindlnode));

if(!

L.kindelem)exit(overflow);

L.length=0;

L.listsize=SQMOUNTLINK_INIT_SIZE;

for(i=0;i

{

(L.kindelem[i]).firstproduct=NULL;

}

returnok;

}//InitMountList

intCreatMountList(sqmountlink&L)

{//创建初始的产品类、产品顺序表挂接链表L

plinklistp,q;

inti,j,n,k;

printf("此线性表L中含有的产品类个数:

\n");

scanf("%d",&n);

for(i=0;i

{

printf("输入第%d个产品类名称:

\n",(i+1));

scanf("%s",&(L.kindelem[i].pkindname));

printf("输入此产品类含有的产品个数:

\n");

scanf("%d",&k);

if(k>=1)

{

p=(plinklist)malloc(sizeof(productlnode));

printf("输入此产品类所含产品的产品名称、总量、进货日期、销出数量、销售时间:

\n");

scanf("%s%d%d,%d,%d%d%d,%d,%d",&(p->pname),&(p->totalquantity),&((p->goodsdate).year),&((p->goodsdate).month),&((p->goodsdate).day),

&(p->salesquantity),&((p->salestime).year),&((p->salestime).month),&((p->salestime).day));

L.kindelem[i].firstproduct=p;

p->nextproduct=NULL;

}

for(j=1;j

{

q=(plinklist)malloc(sizeof(productlnode));

printf("输入此产品类所含产品的产品名称、总量、进货日期、销出数量、销售时间:

\n");

scanf("%s%d%d,%d,%d%d%d,%d,%d",&(q->pname),&(q->totalquantity),&((q->goodsdate).year),&((q->goodsdate).month),&((q->goodsdate).day),

&(q->salesquantity),&((q->salestime).year),&((q->salestime).month),&((q->salestime).day));//调试输入年月日时,年月日要用逗号分隔开。

q->nextproduct=p->nextproduct;

p->nextproduct=q;

p=q;

}

L.length++;

}

returnok;

}//CreatMountList

intKindInsert(sqmountlink&L,intn)

{//向顺序表挂接链表L中添加n类产品

inti;

kindlnode*newbase;

if(L.length+n>=L.listsize)

{

newbase=(kindlnode*)realloc(L.kindelem,(L.listsize+n)*sizeof(kindlnode));

if(!

newbase)exit(overflow);

L.kindelem=newbase;

L.listsize+=n;

}

printf("需添加的产品类名称:

\n");

for(i=0;i

{

scanf("%s",&L.kindelem[L.length].pkindname);

L.kindelem[L.length].firstproduct=NULL;

L.length++;

}

returnok;

}//KindInsert

intProductInsert(sqmountlink&L,charpkindname2[],intn)

{//向顺序表挂接链表L的某产品类中添加n个产品

plinklistp,q;

intk,j;

for(k=0;k

{

if(strcmp((L.kindelem[k]).pkindname,pkindname2)!

=0)

continue;

else

break;

}

if(L.kindelem[k].firstproduct==NULL)

{

q=(plinklist)malloc(sizeof(productlnode));

printf("输入此产品类所含产品的产品名称、总量、进货日期、销出数量、销售时间:

\n");

scanf("%s%d%d,%d,%d%d%d,%d,%d",&(q->pname),&(q->totalquantity),&((q->goodsdate).year),&((q->goodsdate).month),&((q->goodsdate).day),

&(q->salesquantity),&((q->salestime).year),&((q->salestime).month),&((q->salestime).day));

q->nextproduct=NULL;

(L.kindelem[k]).firstproduct=q;

for(j=1;j

{

p=(plinklist)malloc(sizeof(productlnode));

printf("输入此产品类所含产品的产品名称、总量、进货日期、销出数量、销售时间:

\n");

scanf("%s%d%d,%d,%d%d%d,%d,%d",&(p->pname),&(p->totalquantity),&((p->goodsdate).year),&((p->goodsdate).month),&((p->goodsdate).day),

&(p->salesquantity),&((p->salestime).year),&((p->salestime).month),&((p->salestime).day));

p->nextproduct=q->nextproduct;

q->nextproduct=p;

q=p;

}

}

else

{

for(q=L.kindelem[k].firstproduct;;q=q->nextproduct)

{

if(!

(q->nextproduct))

break;

}

printf("需添加产品的名称、总量、进货日期、销出数量、销售时间:

\n");

for(j=0;j

{

p=(plinklist)malloc(sizeof(productlnode));

scanf("%s%d%d,%d,%d%d%d,%d,%d",&(p->pname),&(p->totalquantity),&((p->goodsdate).year),&((p->goodsdate).month),&((p->goodsdate).day),

&(p->salesquantity),&((p->salestime).year),&((p->salestime).month),&((p->salestime).day));

p->nextproduct=q->nextproduct;

q->nextproduct=p;

q=p;

}

}

returnok;

}//ProductInsert

voidProQuantity_add(sqmountlink&L,charpkindname1[],charpname1[],intn)

{//添加顺序表挂接链表L的某产品类中的某产品的总量,且需添加的产品总量为n

inti,k;

plinklistp;

for(i=0;i

{

if(strcmp((L.kindelem[i]).pkindname,pkindname1)!

=0)

continue;

else

break;

}

if(i

{

for(p=L.kindelem[i].firstproduct;p!

=NULL;p=p->nextproduct)

{

k=strcmp(p->pname,pname1);

if(k==0)

{

p->totalquantity=p->totalquantity+n;

printf("查看添加后产品的各项输出:

%s%d%,d%d,%d%d%d,%d,%d\n",p->pname,p->totalquantity,(p->goodsdate).year,(p->goodsdate).month,(p->goodsdate).day,

p->salesquantity,(p->salestime).year,(p->salestime).month,(p->salestime).day);

}

}

}

}//ProQuantity_add

voidVisit(sqmountlink&L,charpkindname3[],charpname3[])

{//在顺序表挂接链表L中,查询属于某产品类的某产品的各项信息

inti,k;

plinklistp;

for(i=0;i

{

if(strcmp((L.kindelem[i]).pkindname,pkindname3)!

=0)

continue;

else

break;

}

if(i

{

for(p=L.kindelem[i].firstproduct;p!

=NULL;p=p->nextproduct)

{

k=strcmp(p->pname,pname3);

if(k==0)

break;

}

if(k!

=0)

printf("此产品不存在:

\n");

else

{

printf("输出待查询产品的各项信息:

\n");

printf("%s%s%d%d,%d,%d%d%d,%d,%d\n",(L.kindelem[i]).pkindname,p->pname,p->totalquantity,(p->goodsdate).year,(p->goodsdate).month,(p->goodsdate).day,

p->salesquantity,(p->salestime).year,(p->salestime).month,(p->salestime).day);

}

}

}//Visit

voidDisplayList(sqmountlink&L)

{//显示各产品所属产品类,产品名称、产品总量,进货日期,销出数量,销售时间

inti;

plinklistp;

printf("产品类产品产品总量进货日期销出数量销售时间\n");

for(i=0;i

{

if(!

(L.kindelem[i].firstproduct))

printf("%s\n",(L.kindelem[i]).pkindname);

for(p=L.kindelem[i].firstproduct;p;p=p->nextproduct)

printf("%s%s%d%d,%d,%d%d%d,%d,%d\n",(L.kindelem[i]).pkindname,p->pname,p->totalquantity,(p->goodsdate).year,(p->goodsdate).month,(p->goodsdate).day,

p->salesquantity,(p->salestime).year,(p->salestime).month,(p->salestime).day);

}

}//DisplayList

voidDestroyMountList(sqmountlink&L)

{//销毁已存在的顺序表挂接链表L

inti;

kindlnode*p;

plinklistq;

for(i=L.length;i>=0;i--)

{

p=&(L.kindelem[i]);

if((*p).firstproduct==NULL)

free(p);

else

{

while((*p).firstproduct){

for(q=(*p).firstproduct;q->nextproduct;q=q->nextproduct);

free(q);

}

free(p);

}

}

}//DestroyMountList

voidmenu_operation()

{//操作菜单

printf("----输入所要执行操作:

-------\n");

printf("----产品类的添加:

1------\n");

printf("----产品的添加:

2------\n");

printf("----产品数量的添加:

3-----\n");

printf("----查询每种产品所属产品类,产品总量,进货日期,销出数量,销售时间:

4-----------\n");

printf("----释放L所占内存空间,退出程序:

0-----\n");

}//menu_operation

/*----------------------------主程序----------------------------*/

voidmain(void)

{

intorder;

inti,n;

chara[30];

charb[30];

sqmountlinkL;

InitMountList(L);

printf("------创建初始的产品类、产品顺序表挂接链表L------\n");

CreatMountList(L);

DisplayList(L);

printf("------初始的产品类、产品顺序表挂接链表L创建完成------\n");

menu_operation();

loop:

printf("输入命令:

");

scanf("%d",&order);

switch(order)

{

case1:

printf("需添加产品类的个数:

");

scanf("%d",&i);

KindInsert(L,i);

printf("输出修改后的产品库存管理表:

\n");

DisplayList(L);

gotoloop;

case2:

printf("需添加产品所属产品类的名称:

");

scanf("%s",&a);

printf("需向此产品类添加产品的个数:

");

scanf("%d",&i);

ProductInsert(L,a,i);

printf("输出修改后的产品库存管理表:

\n");

DisplayList(L);

gotoloop;

case3:

printf("输入需添加数量的产品所属产品类的名称:

");

scanf("%s",&a);

printf("输入需添加数量的产品的名称:

");

scanf("%s",&b);

printf("输入需添加产品的数量:

");

scanf("%d",&n);

ProQuantity_add(L,a,b,n);

printf("输出修改后的产品库存管理表:

\n");

DisplayList(L);

gotoloop;

case4:

printf("输入待查询产品所属产品类的名称:

");

scanf("%s",&a);

printf("输入待查询产品的名称:

");

scanf("%s",&b);

Visit(L,a,b);

gotoloop;

case0:

DestroyMountList(L);

exit(0);

}

}

2.函数的调用关系图

四、设计和调试分析

1.因要存取产品类和产品,而产品又从属于某一个产品类,所以本程序在存储结构设计方面采取了顺序表挂接链表的形式,其中顺序表存储产品类,链表存储产品。

2.因考虑到产品类与产品类之间,一类中的产品与另一产品类及另一产品类的产品并无联系,所以本程序并未采用图的邻接表的形式存储,而是采用了类似图的邻接表的存储结构存储。

3.本程序中产品类的添加、属于同一类产品的添加都采用末尾插入。

4.本程序的设计还存在一些缺点;例如对某些不合逻辑的输入,还缺少一些判错处理(比如逻辑上销售时间肯定在进货时间之后,此程序未给出这方面相应的比较判断处理),有些操作函数的设计不完善(如:

货物可能分几次进入,而显示时间的存储单元只有一个,无法同时显示在不同时间进货的日期。

查询某产品的各项信息时,必须事先知道产品属于哪一类等)。

5.起初程序设计中采用了固定长度的数组,在动态分配存储空间时将所分配空间的起始地址赋给了所定义的数组名,调试时出错。

因固定长度的数组名为一常量地址,不可再对其赋值。

程序中年月日的输入是用逗号分隔的,调试时用空格进行分隔,出错。

五、用户手册

1、本程序的运行环境为DOS操作系统,执行文件为Text1.exe

2、进入演示程序后即显示文本方式的用户界

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 自然科学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1