C++课程设计《商品销售管理系统》Word下载.docx
《C++课程设计《商品销售管理系统》Word下载.docx》由会员分享,可在线阅读,更多相关《C++课程设计《商品销售管理系统》Word下载.docx(28页珍藏版)》请在冰豆网上搜索。
Intgetcount()//获取库存量
Intgetsalecount()//获取已售量
Floatgetbuy()//获取进价
Floatgetsale()//获取售价
Char*getgys()//获取供应商
—2—
Voidsetid(intn)//输入id
Voidsetname(charna[])//产品名
Voidsetcount(intc)//库存量
Voidsetsalecount(ints)//已售量
Voidsetbuy(floati)//进价
Voidsetsale(floato)//售价
Voidsetgys(charg[])//供应商
};
2、classcommodity商品类设计:
classCommodity//商品类
Datat[50];
//数组
intn;
//商品数量
public:
voidnewFile()//添加商品信息
voidshowData(inti)//显示商品信息
voidshowData()//显示文字信息
voidsave()//写入数据至文件
intsearch()//商品查询
voidsale()//商品销售结算
voidshowSale()//销售清单
inlinevoidmenu()//主菜单
3、本程序结构
(1)主函数
Voidmain(){
menu();
Commoditycom;
intc;
switch(c){return}
Break;
}
(2)数据类——实现对数据的输入输出。
(3)商品类——系统各项功能的实现。
三、详细设计
(1)数据类
classData//数据类
//产品编号
//产品名称
//库存数量
//已售数量
//进价
floatoprice;
//售价
//供应商
intgetId()
{
returnid;
}
char*getName()
returnname;
intgetCount()
—3—
returncount;
intgetSaleCount()
returnsalecount;
floatgetBuy()
returniprice;
floatgetSale()
returnoprice;
char*getGys()
returngys;
//----------------------
voidsetId(intn)
id=n;
voidsetName(charna[])
strcpy(name,na);
voidsetCount(intc)
count=c;
voidsetSaleCount(ints)
salecount=s;
voidsetBuy(floati)
iprice=i;
voidsetSale(floato)
oprice=o;
—4—
//...................
voidsetGys(charg[])
strcpy(gys,g);
(2)商品类
classCommodity//商品类
private:
public:
voidnewFile()
intid;
charname[50];
//字符数组
intcount;
floatiprice;
floatoprice;
if(n<
0)
n=0;
inti;
Datatemp;
for(;
;
n++)
{
cout<
<
"
商品编号:
cin>
>
id;
if(id==-1)
break;
t[n].setId(id);
商品名:
name;
t[n].setName(name);
库存量:
count;
t[n].setCount(count);
进价:
—5—
iprice;
t[n].setBuy(iprice);
售价:
oprice;
t[n].setSale(oprice);
供应商:
gys;
t[n].setGys(gys);
t[n].setSaleCount(0);
//售出此产品0个
cout<
若商品添加完毕,请按-1退出添加!
endl;
for(i=0;
i<
n;
i++)
{
if(t[i].getId()>
t[n].getId())
{
temp=t[i];
t[i]=t[n];
t[n]=temp;
}
}
}
voidshowData(inti)
cout<
t[i].getId()
<
setw(10)<
t[i].getName()
t[i].getCount()
t[i].getSaleCount()
—6—
setw(8)<
t[i].getBuy()
t[i].getSale()
t[i].getGys()<
voidshowData()
商品编号"
商品名"
库存量"
已售量"
进价"
售价"
供应商"
for(inti=0;
if(t[i].getCount()>
0)
showData(i);
产品种类:
n<
ofstreamfout;
fout.open("
商品销售管理系统.txt"
);
if(!
fout)
cannotopenthefile!
return;
fout<
"
for(inti=0;
i++)
t[i].getId()<
setw(14)<
t[i].getName()<
t[i].getCount()<
t[i].getBuy()<
t[i].getSale()<
t[i].getSaleCount();
*************SaveSuccess!
*****************"
fout.close();
}
intsearch()
id:
cin>
intlow=0,mid,high=n-1;
while(low<
=high)
mid=(low+high)/2;
if(t[mid].getId()==id)
returnmid;
elseif(t[mid].getId()>
id)
high=mid-1;
Else
low=mid+1;
—7—
return-1;
voidsale()
产品编号"
inttemp;
temp=search();
if(temp==-1)
cannotfindthecommodity!
return;
if(t[temp].getCount()<
=0)
此产品已缺!
输入数量:
floatmoney;
输入收到金额(元):
money;
if(count<
=0&
&
count>
t[temp].getCount())//输入的是负数或超出该产品库存量
数量输入不正确"
elseif(money<
t[temp].getSale()*count)
—8—
购物金额不足,还需增加金额"
t[temp].getSale()*count-money<
元"
else
t[temp].setCount(t[temp].getCount()-count);
//当前库存减少count
t[temp].setSaleCount(t[temp].getSaleCount()+count);
//出售量增加count
***名称:
t[temp].getName()<
endl
<
***数量:
count<
***单价:
t[temp].getSale()<
***应收:
count*t[temp].getSale()<
***找零:
money-count*t[temp].getSale()<
*************"
voidshowSale()
if(t[i].getSaleCount()>
(3)主函数
inlinevoidmenu()
********欢迎使用商品销售管理系统**********"
**********主菜单**********"
(1)添加"
(2)保存"
(3)显示"
(4)菜单"
(5)销售单"
(0)退出系统"
*************2011--2012***********"
voidmain()
)
请选择:
c;
—9—
switch(c)
case1:
com.newFile();
break;
case2:
com.save();
case3:
com.showData();
case4:
menu();
case5:
com.sale();
case0:
****谢谢使用*****"
*********!
再见!
*********"
return;
break;
四、调试手册
(1)、errorC2143:
syntaxerror:
missing'
'
before'
}'
行246少了一个分号
(2)、errorC2562:
'
main'
:
void'
functionreturningavalue空类型不能有返回值
(3)、errorC2679:
binary'
nooperatordefinedwhichtakesaright-handoperandoftype'
(orthereisnoacceptableconversion)
t[i].getName后面少了()
五、用户手册
1、本程序的运行环境为windows操作系统,执行文件为Ks..exe;
2、进入演示程序后,即显示对话形式的提示操作过程:
如:
第一项:
(1)商品添加功能
在选择一栏输入:
1
即显示商品编号、商品名、库存量、进价、售价、供应商各项商
品信息,依次输入所需添加的数据。
添加商品完毕,按-1退出添加。
选择:
2即将商品信息保存。
3显示已保存的商品信息。
4重新回到主菜单。
5进行商品销售结算。
同时选择:
3显示商品库存和已销售的完整信息。
六、测试数据
进入演示程序后,即显示对话形式的提示操作过程:
—10—
输入相应提示的商品信息
2界面显示数据保存成功
3显示商品信息
—11—
4重新回到主菜单
5进行商品结算
七、附录
程序源代码:
#include<
iostream.h>
fstream.h>
string.h>
iomanip.h>
//为了声明标识符setw()函数
#defineMfname100
//售价
—12—
id=n;
count=c;
—13—
t[n].setSaleCount(0);
—14—
—15—
—15—
cout<
t[i