阅读下列说明和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
【说明】
某大型购物中心欲开发一套收银软件,要求其能够支持购物中心在不同时期推出的各种促销活动,如打折、返利(例如,满300返100)等等。现采用策略(Strategy)模式实现该要求,得到如图5-1所示的类图。
图5-1 策略模式类图
【C++代码】
#include
using namespace std;
enum TYPE{NORMAL, CASH_DISCOUNT, CASH_RETURN};
class CashSuper{
public:
(1);
};
class CashNormal : public CashSuper { //正常收费子类
public:
double acceptCash(double money) { retum money; }
};
class CashDiscount : public CashSuper {
private:
double moneyDiscount; // 折扣率
public:
CashDiscount(double discount) { moneyDiscount= discount; }
double acceptCash(double money) { retum money * moneyDiscount; }
};
class CashRetum : public CashSuper { // 满额返利
private:
double moneyCondition; // 满额数额
double moneyReturn; // 返利数额
public:
CashRetnm(double motieyCondition, double moneyReturn) {
this->moneyCondition=moneyCondition;
this->moneyReturn=moneyReturn;
}
double acceptCash(double money) {
double result = money;
if(money>=moneyCondition)
result=money-(int)(money/moneyCondition ) * moneyReturn;
return result ;
}
};
class CashContext {
private:
CashSuper *cs;
public:
CashContext(int type) {
switch(type) {
case NORMAL: //正常收费
(2) ;
break;
case CASH_RETURN: //满300返100
(3) ;
break;
case CASH_DISCOUNT: //打八折
(4) ;
break;
}
}
double GetResult(double money) {
(5) ;
}
};
//此处略去main()函数