用栈队列链表等实现的商品管理系统Word下载.docx
《用栈队列链表等实现的商品管理系统Word下载.docx》由会员分享,可在线阅读,更多相关《用栈队列链表等实现的商品管理系统Word下载.docx(25页珍藏版)》请在冰豆网上搜索。
Pushabuttontogetalistdisplayedofalltheitemsandtheirquantitiesintheinventory.
3.
Pushabuttontotakethenext(top)itemfrominventoryandputitinashippingqueue.
4.
Pushabuttontogetalistdisplayedofalltheitemsthatarecurrentlyshipping.
5.
Pushabuttontoindicatethatashippeditemhasbeendeliveredandshouldbetakenoutoftheshippingqueue.
ShippeditemsareputinandtakenoutFIFO.
6.
Pushabuttontodisplayallthethingsthathavebeendelivered.
Youaretocreateclassesforthedifferentdatastructuresandnodes.
Youalsoneedadriverprogramthattakesuserinputandmanipulatesanodeobjectandprintsoutput.
ThedrivershouldbewrittenasaC++applicationwithbuttonsandtextinputandoutput.
Onewaytodotheapplicationistohavetwotextfieldsforinput,atextareaforoutput,andbuttonsthatsay“addtoinventory,”“displayinventory,”etc.
Thinkaboutyourdesignanddrawitoutbeforeyouwritethecode.
Also,drawyourdatastructuresbeforeyouwriteanycode.
Drawouttheoperationsoftakingthingsfromonedatastructureandputtingthemintoanother.
Thinkaboutwhatgoesinyourapplicationandyourclassbeforeyouwriteanycode.
三、实验过程或算法(源程序)
本组由王福临(20115394)、陈云艳(20115351)和许文丽(20115352)组成。
许文丽负责课程设计的界面设计,以及最终的实验报告填写等总结部分,所进行的工作占总工作量的30%;
陈云艳负责课程设计的几个基本类的具体功能的实现和出错处理部分,所进行的工作占总工作量的30%;
王福临负责课程设计的界面设计内部的与功能相关的进货,出货以及卖货的综合函数的实现部分,所进行的工作占总工作量的40%。
1:
我们选用的是窗体应用程序来做这一个项目.
2:
许文丽同学设计的界面如下:
整个实现一共有六个按钮,分别管理货物的入库,库存货品的展示,货物的出库,出库货品的展示,货物的出售以及出售货物的展示。
程序的主要进程如下:
(1):
用户点击按钮,把货物存入仓库;
(2):
点击按钮,展示所有仓库中的货物;
(3):
点击按钮,将货物的一部分从仓库中取出来;
(4)展示所有的取出的货物;
(5)将提出的货物一件件的卖出;
(6)展示(记录)所有卖出的货物。
3:
类的具体功能的实现
这些类的基本功能:
为各个按钮的实现做基础,首先,我们需要用到类模板,那么就需要一个基类来作为我们的实例化对象;
其次,对仓库中货物的操作其实本质上是对栈和队列中的数据元素的插入,删除的操作,所以首先要实现几个基本类的实现。
node.h<
节点类>
#pragmaonce
#include<
string>
usingnamespacestd;
classnode
{private:
stringh;
ints;
stringd;
public:
node(void);
voidset(inta,stringb,stringc);
nodeoperator+(node&
);
booloperator==(node&
intshu();
node(node&
N){
h=N.h;
s=N.s;
d=N.d;
}
stringhuo();
stringdan();
~node(void);
};
Node.cpp
#include"
StdAfx.h"
node.h"
node:
:
node(void)
{h="
"
;
s=-1;
d="
}
voidnode:
set(inta,stringb,stringc)
{s=a;
h=b;
d=c;
stringnode:
huo()
{returnh;
intnode:
shu()
{returns;
dan()
{returnd;
nodenode:
operator+(node&
N)
{this->
s=this->
s+N.s;
return*this;
boolnode:
operator==(node&
{if(this->
h==N.h)
return1;
elsereturn0;
~node(void)
{}
Aquue.h<
队列类>
#defineDefaultsize200
template<
classT>
classAquue
intsize;
intfront;
intrear;
T*listArray;
Aquue(void)
{size=Defaultsize+1;
rear=0;
front=1;
listArray=newT[size];
~Aquue(){delete[]listArray;
voidclear(){front=rear;
boolenqueue(constT&
it)
{if((rear+2)%size==front)returnfalse;
rear=(rear+1)%size;
listArray[rear]=it;
returntrue;
booldequeue(T&
{if(length()==0)returnfalse;
it=listArray[front];
front=(front+1)%size;
returntrue;
}
boolfrontValue(T&
it)const
{if(length()==0)returnfalse;
virtualintlength()const
{return((rear+size)-front+1)%size;
};
Astack.h<
栈类>
#defineDefaultListSize200
template<
classAstack
inttop;
Astack(void)
{size=DefaultListSize;
top=0;
listArray=newT[size];
Astack(Astack&
sta)
{size=sta.size;
top=sta.top;
for(inti=0;
i<
top;
i++)
listArray[i]=sta.listArray[i];
voidclear()
{top=0;
boolpush(T&
item)
{if(top==size-1)
returnfalse;
else
{listArray[top]=item;
top++;
boolpop(T&
{if(top==0)
returnfalse;
{top--;
item=listArray[top];
booltopvalue(T&
item)const
{if(top==0)returnfalse;
{item=listArray[top];
returntrue;
intlength()
{returntop;
4:
窗体应用程序中的初始化:
它主要是帮助我们将涉及到的其他类的文件包含到此处,然后定义一些要用到的全局变量,
iostream>
#include"
Aquue.h"
Astack.h"
Form2.h"
报馈?
错洙?
h"
出?
啦?
.h"
namespaceProject1{
usingnamespaceSystem;
usingnamespaceSystem:
ComponentModel;
Collections;
Windows:
Forms;
Data;
Drawing;
Runtime:
InteropServices;
publicrefclassForm1:
publicSystem:
Forms:
Form
{
public:
Form1(void)
{
InitializeComponent();
a=newAquue<
node>
();
n=newAstack<
r=newAquue<
}
protected:
~Form1()
if(a)deletea;
if(n)deleten;
if(components)
{
deletecomponents;
}
private:
System:
Button^button1;
TextBox^textBox1;
TextBox^textBox2;
Button^button2;
Label^label1;
Label^label2;
TextBox^textBox4;
Label^label3;
RichTextBox^richTextBox1;
Label^label4;
Button^button3;
TextBox^textBox3;
TextBox^textBox5;
TextBox^textBox6;
Label^label5;
Label^label6;
Label^label7;
RichTextBox^richTextBox2;
Button^button4;
Label^label8;
Button^button5;
TextBox^textBox7;
TextBox^textBox8;
TextBox^textBox9;
Label^label9;
Label^label10;
Label^label11;
Button^button6;
RichTextBox^richTextBox3;
Label^label12;
Aquue<
*a;
Astack<
*n;
Aquue<
*r;
5:
界面上的各个按钮的功能的实现部分:
入库:
用户输入需要存放入库的货品名,数量及单位,然后点击“入库”按钮,这样货物就被一件一件的存放进仓库了,而内部是用一个栈来接收这些货物的,很好的模拟了商家进货的过程,及先进的放在仓库里面,后来的放在仓库外面。
这里设计的时候做了一点小小的改进,就是说当输入者不小心或者是不知道而在数量栏输入错误的信息的时候,它会报错,这个其实就是我们的“Form2"
的作用了。
如下。
(当然这个其实是针对不熟悉这个程序的用户而言的)。
主要的实现代码如下:
private:
Voidbutton1_Click(System:
Object^sender,System:
EventArgs^e){
constchar*ch1=(constchar*)(Marshal:
StringToHGlobalAnsi(textBox1->
Text)).ToPointer();
strings1=ch1;
Marshal:
FreeHGlobal(IntPtr((void*)ch1));
intflag=0;
constchar*ch2=(constchar*)(Marshal:
StringToHGlobalAnsi(textBox2->
for(inti=0;
ch2[i]!
='
\0'
{
if(ch2[i]>
'
9'
||ch2[i]<
0'
)
flag=1;
}
intbbb;
if(flag==1)
Form2^f2=gcnewForm2();
f2->
set1("
pleasegivetherightmessage"
Show();
return;
else
bbb=atoi(ch2);
FreeHGlobal(IntPtr((void*)ch2));
constchar*ch3=(constchar*)(Marshal:
StringToHGlobalAnsi(textBox4->
strings3=ch3;
FreeHGlobal(IntPtr((void*)ch3));
nodeno;
no.set(bbb,s1,s3);
n->
push(no);
textBox1->
Text=L"
textBox2->
textBox4->
(2)库存显示:
由于进货入库是一个一对一的操作,如果用户不记得自己到底进了那些货,多少货,那么只需要点击“仓库货物展示”按钮就可以看到仓库中所有的有序排列的货物。
如下所示:
其实就是将上一入库中所接受的货物从栈中pop出来,但值得注意的是不能对栈本身操作,而是要将其复制,这样才不会使得原来栈中元素全无,再者就是不会导致每点击一次库存展示它的顺序就颠倒一次,这样显然不符合我们用栈的初衷,所以才需要用到拷贝构造函数对其复制品进行操作。
Voidbutton2_Click(System:
nodeit;
Astack<
*d;
d=newAstack<
(*n);
stringst="
while(d->
pop(it))
intaa,bb;
stringname="
stringsss="
stringdanwei="
name=it.huo();
aa=it.shu();
danwei=it.dan();
while(aa)
bb=aa%10;
aa=aa/10;
sss=char(bb+48)+sss;
st=st+name+"
"
+sss+"
+danwei+"
\n"
String^ss=gcnewString(st.c_str());
richTextBox1->
Text=ss;
deletess;
deleted;
(3)出库:
a.现在要提货了,即本质上是从栈中拿货,这样就是对栈的一些操作了,注意我们这里并没有将不同时间进来的相同的货物数量加在一起,为了保持栈的本质不变,所以提货的时候也要保持原来货物的顺序不改变,只是将货物的数量减少而已,调试结果如下所示:
(提货前)
(提货后)
B.另外,还必须考虑的一个问题是,万一我事先不知道或者不是进货本人来提货的时候,可能会出现所提的货不在仓库之中,因此我们需要为其提供一个报错框,来提示用户仓库中无此货,如下所示:
C.那么,如果库存商品没有我们想要的那么多呢,这是有需要进行报错处理,如下;
Voidbutton3_Click(System:
intam;
constchar*ch=(constchar