第2章デパートの販促(2)——戦略モデル


/*shop.h */

#ifndef _SHOP_

#define _SHOP_

#include<iostream>

#include<string>



// 

class Cashsuper

{

public:

	virtual double acceptcash(double money);

};



// 

class cashnormal:public Cashsuper

{

public:

	virtual double acceptcash(double money);

};



// 

class cashrebate:public Cashsuper

{

public:

	cashrebate():moneyrebate(0.1){}

	virtual double acceptcash(double money);

	void calcute_rebate(std::string moneystring);

private:

	double moneyrebate;// 

};



// 

class cashreturn:public Cashsuper

{

public:

	void MoneyReturn(std::string moneycondition_str,std::string moneyreturn_str);

	virtual double acceptcash(double money);

private:

	double moneycondition;// ( 300)

	double moneyreturn;// ( 100)

};



// , 

class cashcontxt

{

public:

	cashcontxt(Cashsuper* cs){

		this->cas=cs;

	}

	double getresult(double money);

private:

	Cashsuper* cas;

};



#endif


  
/*shop,cpp */

#include<iostream>

#include"shop.h"

using namespace std;



// ( )

double Cashsuper::acceptcash(double money)

{

	return money;

}



// ( )

double cashnormal::acceptcash(double money)

{

	return money;

}





// ( )

void cashrebate::calcute_rebate(std::string moneystring)

{

	if(moneystring==" ")

		moneyrebate=0.8;

	else if(moneystring==" ")

		moneyrebate=0.9;

}

double cashrebate::acceptcash(double money)

{

	return money*moneyrebate;

}



// ( )

void cashreturn::MoneyReturn(std::string moneycondition_str,std::string moneyreturn_str)

{

	if(moneycondition_str==" 100")

		moneycondition=100;

	if(moneycondition_str==" 200")

		moneycondition=200;

	if(moneycondition_str==" 300")

		moneycondition=300;



	if(moneyreturn_str==" 10")

		moneyreturn=10;

	if(moneyreturn_str==" 50")

		moneyreturn=50;

	if(moneyreturn_str==" 100")

		moneyreturn=100;

}

double cashreturn::acceptcash(double money)

{

	double result=money;

	if(result>=moneycondition)

		result=money-moneyreturn;

	return result;

}



double cashcontxt::getresult(double money)

{

	return cas->acceptcash(money);

}


  
/*main.cpp */

#include "shop.h"

#include<iostream>



using namespace std;



int main()

{

	/*

	string type=" ";

	cashrebate *cx;

	cx=new cashrebate;

	cx->calcute_rebate(type);

	*/



	string type=" 300 100";

	cashreturn *cx;

	cx=new cashreturn;

	cx->MoneyReturn(" 300"," 100");



	cashcontxt *cs;

	cs=new cashcontxt(cx);

	cout<<cs->getresult(1000)<<endl;



	system("pause");

	return 0;

}