第2章デパート販促(1)——工場モデル

2907 ワード

/*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 CashFactory

{

public:

	static Cashsuper* createcashaccept(std::string type);

};



#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;

}



// ( )

 Cashsuper* CashFactory::createcashaccept(std::string type)

{

	Cashsuper* cs=NULL;

	if(type==" ")

		cs=new cashnormal;

	else if(type==" 300 100")

	{

		cashreturn* csre=new cashreturn;

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

		cs=csre;

	}

	else if(type==" ")

	{

		cashrebate* csreb=new cashrebate;

		csreb->calcute_rebate(" ");

		cs=csreb;

	}

	else

		exit(1);

	return cs;

 }


  
/*main.cpp */

#include "shop.h"

#include<iostream>



using namespace std;



int main()

{

	string type;

	cin>>type;

	Cashsuper* csuper=CashFactory::createcashaccept(type);

	double totleprices=1000;

	double totle=0.0;

	totle=csuper->acceptcash(totleprices);

	cout<<totle<<endl;

	system("pause");

	return 0;

}