欢迎来到天天文库
浏览记录
ID:61784674
大小:21.96 KB
页数:13页
时间:2021-03-20
《算法设计和分析-最小花费购物问题.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、//----//Bussiness.h//#include#include#include#includeclassProduct{public:voidSetNO(intno){if(no<1
2、
3、no>999){std::cout<<"wrongNO.";}else{m_nNO=no;}}intGetNO(){returnm_nNO;}voidSetPrice(intprice){if(price<1
4、
5、price>999){s
6、td::cout<<"wrongprice";}else{m_nPrice=price;}}intGetPrice(){returnm_nPrice;}private:intm_nNO;//商品编码[1,999];intm_nPrice;//单独购买的单价[1,999];};classItem{public:voidSetNO(intno){if(no<1
7、
8、no>999){std::cout<<"wrongNO.";}else{m_nNO=no;}}intGetNO(){returnm_nNO;}voi
9、dSetCount(intcount){if(count<1
10、
11、count>5){std::cout<<"wrongcount";}else{m_nCount=count;}}intGetCount(){returnm_nCount;}voidSubCount(intnSub){m_nCount-=nSub;}private:intm_nNO;//商品编码[1,999];intm_nCount;//购买该商品的个数[1,5];};classDiscountType{public:intm_nSize;//
12、该折扣组合的商品种类数;int*m_pNOs;//对应的商品编号;int*m_pCount;//对应每种商品需要的个数;intm_nOffer;//该种优惠方案所需花销;//intm_nSave;//相对于原价节省的钱;intGetProductCount(intnProNO)//返回该方案下需要nProNO的个数;{intcount=0;//一个很大的数超过了单件采购的最高限度;for(inti=0;i13、i];}}returncount;}protected:private:};//一次采购的的项目列表;classPurchase{public:Item*m_pItems;//采购的项目列表;intm_nCount;//采购的项目数目;voidClone(Purchase&pur){pur.m_nCount=m_nCount;pur.m_pItems=newItem[m_nCount];for(inti=0;i14、dClear(){delete[]m_pItems;}};//一家商应该具有的各种商品和促销方案;classShop{public:intMinCost(Purchase&curPurchase);Product*m_pProducts;//商店里的所有商品;intm_nProTypeCount;//商店里所有商品种类的总和;DiscountType*m_pDicounts;//商店里的所有促销优惠方案;intm_nDicTypeCount;//促销方案的种类;intGetProductPrice(int15、nProNO);private:intBackspaceMinCost(Purchase&purch,intdiscTypeID);boolSatisfiedDemand(Purchase&purch,intdiscTypeID);voidUpdatePurchase(Purchase&purch,intdiscTypeID);};constintMAX_PIECE=5;constintMAX_PRODUCT_CODE=999;constintMAX_PURCH_NUM=5;classScheduelCo16、st{public:ScheduelCost();voidInit(Shop&theShop,Purchase&thePurchase);voidComp(inti);voidOut();private:voidMiniCost();intB;//购买物品的数目上限;intS;//优惠折扣的类型总数,小于99;intm_cost[MAX_PIECE+1][MAX_PIECE+1][MAX_PIECE+1][MAX_PIECE+
13、i];}}returncount;}protected:private:};//一次采购的的项目列表;classPurchase{public:Item*m_pItems;//采购的项目列表;intm_nCount;//采购的项目数目;voidClone(Purchase&pur){pur.m_nCount=m_nCount;pur.m_pItems=newItem[m_nCount];for(inti=0;i14、dClear(){delete[]m_pItems;}};//一家商应该具有的各种商品和促销方案;classShop{public:intMinCost(Purchase&curPurchase);Product*m_pProducts;//商店里的所有商品;intm_nProTypeCount;//商店里所有商品种类的总和;DiscountType*m_pDicounts;//商店里的所有促销优惠方案;intm_nDicTypeCount;//促销方案的种类;intGetProductPrice(int15、nProNO);private:intBackspaceMinCost(Purchase&purch,intdiscTypeID);boolSatisfiedDemand(Purchase&purch,intdiscTypeID);voidUpdatePurchase(Purchase&purch,intdiscTypeID);};constintMAX_PIECE=5;constintMAX_PRODUCT_CODE=999;constintMAX_PURCH_NUM=5;classScheduelCo16、st{public:ScheduelCost();voidInit(Shop&theShop,Purchase&thePurchase);voidComp(inti);voidOut();private:voidMiniCost();intB;//购买物品的数目上限;intS;//优惠折扣的类型总数,小于99;intm_cost[MAX_PIECE+1][MAX_PIECE+1][MAX_PIECE+1][MAX_PIECE+
14、dClear(){delete[]m_pItems;}};//一家商应该具有的各种商品和促销方案;classShop{public:intMinCost(Purchase&curPurchase);Product*m_pProducts;//商店里的所有商品;intm_nProTypeCount;//商店里所有商品种类的总和;DiscountType*m_pDicounts;//商店里的所有促销优惠方案;intm_nDicTypeCount;//促销方案的种类;intGetProductPrice(int
15、nProNO);private:intBackspaceMinCost(Purchase&purch,intdiscTypeID);boolSatisfiedDemand(Purchase&purch,intdiscTypeID);voidUpdatePurchase(Purchase&purch,intdiscTypeID);};constintMAX_PIECE=5;constintMAX_PRODUCT_CODE=999;constintMAX_PURCH_NUM=5;classScheduelCo
16、st{public:ScheduelCost();voidInit(Shop&theShop,Purchase&thePurchase);voidComp(inti);voidOut();private:voidMiniCost();intB;//购买物品的数目上限;intS;//优惠折扣的类型总数,小于99;intm_cost[MAX_PIECE+1][MAX_PIECE+1][MAX_PIECE+1][MAX_PIECE+
此文档下载收益归作者所有