[ create a new paste ] login | about

Link: http://codepad.org/GHH1EoOk    [ raw code | output | fork ]

C++, pasted on Aug 13:
#include <iostream>
#include <string>
using namespace std;
class CashSuper
{
	public:double virtual acceptCash(double total);
};

class Cashnormal: public CashSuper{
	double acceptCash(double total){
		return total;
	}
};

class Cashreturn: public CashSuper{
	private:int all,returns;
	public:
	Cashreturn(int all,int returns){
		this->all = all;
		this->returns = returns;
	}
	double acceptCash(double total){
		if(total > all)
			return total - returns;
		else
			return total ; 
	}
	
};

class Cashrebate: public CashSuper{
	private:double rebate;
	public:
	Cashrebate(int rebate){
		this->rebate = (rebate+0.0) / 10;
	}
	double acceptCash(double total){
			return total*rebate ; 
	}	
};

class Context{
	CashSuper *cs;
	//CashSuper switchs(string cmd){//û±ØÒª..
	public:
	 Context(int cmd){
		switch(cmd){
			case 0:
				cs = new Cashnormal();
				break;
			case 1:
				cs = new Cashrebate(8);
				break;
			case 2:
				cs = new Cashreturn(300,50);
				break; 
		}
	}
	double getresult(double total){
		return cs->acceptCash(total);
	}
};



int main(){
	int cmd;
	double total;
	cin >> cmd >> total;
	Context *answer = new Context(cmd);
	cout << answer->getresult(total); 
}


Output:
1
2
3
t.o:(.gnu.linkonce.r._ZTI10Cashnormal+0x8): undefined reference to `typeinfo for CashSuper'
t.o:(.gnu.linkonce.r._ZTI10Cashrebate+0x8): undefined reference to `typeinfo for CashSuper'
t.o:(.gnu.linkonce.r._ZTI10Cashreturn+0x8): undefined reference to `typeinfo for CashSuper'


Create a new paste based on this one


Comments: