店铺管理模拟超市的收银系统Word格式文档下载.docx
- 文档编号:8260661
- 上传时间:2023-05-10
- 格式:DOCX
- 页数:10
- 大小:17.80KB
店铺管理模拟超市的收银系统Word格式文档下载.docx
《店铺管理模拟超市的收银系统Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《店铺管理模拟超市的收银系统Word格式文档下载.docx(10页珍藏版)》请在冰点文库上搜索。
,4.10);
pGoods=newCGoods(5,"
空调"
3000.00);
AddGoods(pGoods,100);
pGoods=newCGoods(6,"
大米"
1.00);
AddGoods(pGoods,10000);
pGoods=newCGoods(7,"
葡萄"
pGoods=newCGoods(8,"
面包"
6.00);
pGoods=newCGoods(9,"
火腿"
15.00);
returnpStore;
}
voidusage(){cout<
<
"
\n\n"
;
cout.width(35);
cout.fill('
*'
);
cout<
right<
USAGE"
left<
*"
endl;
cout<
*请您按照请示来购买商品,祝您消费愉快!
\n"
*输入\"
-1\"
完成购买,去收银台\n"
cout.fill('
'
voidmain()
{
//准备超市储藏室、购物篮、收银台CStore*pStore=PrepareStore();
//给超市配货CStore*pBasket=newCStore();
CCounterCounter(pBasket);
doubledCash=0.0;
------------------------欢迎光临\"
美特好\"
超市
------------------------\n\n"
*******************本超市共有以下商品,欢迎您的选购
*******************"
//打印商店的现有商品pStore->
Print();
usage();
//iIndex---用户欲购买商品的索引,iNum用户欲购买商品的数目
intiIndex=0,iNum=0;
do{
请输入商品索引号:
//非法输入if(!
(cin>
>
iIndex)){
\n\n你键入了非法的索引号,程序即将退出\n\n"
gotoCELEAN;
//购买完毕,退出if(iIndex==-1){break;
//获取iIndex所对应的商品PSTOREELEMENTpSE=pStore->
GetGoods(iIndex);
//没有此类商品if(pSE==NULL){
\n很抱歉,本商店没有索引号为\"
iIndex<
\"
的商品\n\n"
continue;
//购买数量
请输入要购买数量:
iNum)){
\n\n你键入了非法的购买数目,程序即将退出\n\n"
gotoCELEAN;
//商品查询
intiStoreNum=pStore->
QueryGoods(iIndex);
if(iStoreNum<
=0){
很抱歉,你要购买的\"
pSE->
pGoods->
GetName()<
商品已经售完,请下次再来购买!
else{if(iNum>
iStoreNum){
很抱歉,本商店目前仅有\"
iStoreNum<
件,暂时先购买这么多吧\n"
CGoods*pMyGoods=pSE->
Clone();
pBasket->
AddGoods(pMyGoods,iStoreNum);
//加入购物篮pSE->
iNum=0;
//卖光了
else{
恭喜你,成功购买:
商品:
件数:
iNum<
CGoods*pMyGoods=pSE->
AddGoods(pMyGoods,iNum);
iNum=iStoreNum-iNum;
//超市剩余
}while(true);
if(pBasket->
GetAllGoods()->
size()==0){cout<
\n\n嗨,什么都没买到,白来一趟;
(\n\n"
\n\n购买完毕,今天收获不小啊,购买了如下商品:
pBasket->
\n\n您好,您本次共计消费"
Counter.Bill()<
元\n"
请交钱:
cin>
dCash;
while(Counter.Count(dCash)<
0){
还差:
-Counter.Count(0)<
cin>
\n\n共收取您现金:
Counter.GetCash()<
应交纳金额:
应找零:
Counter.Count(0)<
元\n\n"
**********************欢迎您再次光临本店**********************\n"
CELEAN:
deletepStore;
deletepBasket;
return;
//counter.cpp:
implementationofthesupermarketclass.
//
//////////////////////////////////////////////////////////////////////#include"
#include<
assert.h>
//*商品类的成员函数定义
//************************************************************************CGoods:
:
CGoods(intiIndex,stringstrName,doubledUnitPrice)
//初始化商品m_iIndex=iIndex;
m_strName=strName;
m_dUnitPrice=dUnitPrice;
CGoods:
~CGoods()
//attributesandoperations
intCGoods:
GetIndex(void)const{returnm_iIndex;
stringCGoods:
GetName(void)const{returnm_strName;
doubleCGoods:
GetUnitPrice(void)const{returnm_dUnitPrice;
voidCGoods:
SetUnitPrice(doubledUnitPrice){m_dUnitPrice=dUnitPrice;
CGoods*CGoods:
Clone(){returnnewCGoods(m_iIndex,m_strName,m_dUnitPrice);
//*商品类的成员函数定义结束
//*储藏室类的成员函数定义
//************************************************************************CStore:
CStore()
CStore:
~CStore()
DeleteAllGoods();
//往储藏室种添加货物boolCStore:
AddGoods(CGoods*pGoods,intiNum){assert(pGoods!
=NULL);
intsize=m_vStore.size();
boolbIsExist=false;
for(inti=0;
i<
size;
i++){
PSTOREELEMENTpSE=m_vStore[i];
assert(pSE!
//假如已经有了同类商品在储藏室,那么增加此商品的数目
if(pSE->
pGoods!
=NULL&
&
GetIndex()==pGoods->
GetIndex()){bIsExist=true;
iNum+=iNum;
break;
//储藏室没有同类商品,直接增加此类商品if(!
bIsExist){PSTOREELEMENTp=newSTOREELEMENT;
p->
pGoods=pGoods;
p->
iNum=iNum;
m_vStore.push_back(p);
returntrue;
//清空整个储藏室voidCStore:
DeleteAllGoods(){intsize=m_vStore.size();
i++){PSTOREELEMENTpSE=m_vStore[i];
=NULL){deletepSE->
pGoods;
//删除商品pSE->
pGoods=NULL;
deletepSE;
//删除储藏室元素pSE=NULL;
//删除名为strName的货物,iNum为删除数量intCStore:
DeleteGoods(conststring&
strName,intiNum){
intsize=m_vStore.size();
GetName()==strName){if(iNum<
=-1||pSE->
=iNum){
deletepSE->
pSE->
return0;
iNum-=iNum;
returnpSE->
iNum;
//删除索引号为iIndex的货物,iNum为删除数量intCStore:
DeleteGoods(intiIndex,intiNum){intsize=m_vStore.size();
GetIndex()==iIndex){if(iNum<
//获取货物清单vector<
PSTOREELEMENT>
*CStore:
GetAllGoods(void){return&
m_vStore;
//获取某类货物PSTOREELEMENTCStore:
GetGoods(intiIndex){intsize=m_vStore.size();
GetIndex()==iIndex){returnpSE;
returnNULL;
GetGoods(conststring&
strName){intsize=m_vStore.size();
for(inti=0;
GetName()==strName){returnpSE;
//查询货物intCStore:
QueryGoods(conststring&
GetName()==strName){returnpSE->
QueryGoods(intiIndex){intsize=m_vStore.size();
GetIndex()==iIndex){returnpSE->
//打印水单voidCStore:
Print(){stringstrTitle[4];
strTitle[0]="
索引号"
strTitle[1]="
商品名"
strTitle[2]="
数量"
strTitle[3]="
单价"
4;
cout.width(16);
strTitle[i];
//获取商品种类intsize=m_vStore.size();
for(i=0;
i++){cout.width(16);
m_vStore[i]->
GetIndex();
cout.width(16);
GetName();
cout.precision
(2);
fixed<
GetUnitPrice()<
//*储藏室类的成员函数定义结束
//*收银台类的成员函数定义
//************************************************************************CCounter:
CCounter(CStore*pBasket)
m_pBasket=pBasket;
m_dCash=0.0;
CCounter:
~CCounter()
//获取帐单doubleCCounter:
Bill(void){
doubledTotalPrice=0.0;
vector<
*pvSE=m_pBasket->
GetAllGoods();
//获取商品种类intsize=pvSE->
size();
PSTOREELEMENTpSE=(*pvSE)[i];
dTotalPrice+=pSE->
GetUnitPrice()*pSE->
returndTotalPrice;
//收钱及找零doubleCCounter:
Count(doubledCash){m_dCash+=dCash;
doubledTotal=Bill();
returnm_dCash-dTotal;
//收取的现金数doubleCCounter:
GetCash(){returnm_dCash;
//*收银台类的成员函数定义结束
}四、运行结果五、试验体会
在这次的设计过程中,我采用的是VC++,不仅使我对课程有了进一步的强化,还使我的开发能力得到了提高。
在此感谢给予我帮助的老师和同学们。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 店铺 管理 模拟 超市 收银 系统