码迷,mamicode.com
首页 > 其他好文 > 详细

递归 将一个十进制数转化为任意进制字符串

时间:2014-05-22 18:30:39      阅读:314      评论:0      收藏:0      [点我收藏+]

标签:des   class   blog   c   code   ext   

Create All kinds of guns.

设计重点:

1 基类作接口

2 继承类是各种不同的类

3 构建工厂类,然后根据需要创造不同的类,可以传入关键字,或者索引等。


#pragma once
#include <string>
#include <iostream>

using namespace std;

//Base class
class Gun
{
public:
	virtual string description()
	{
		return "Generic Gun";
	}
};

//Derived class
class MachineGun :public Gun
{
public:
	string description()
	{
		return "MachineGun - Gun for fast shoot";
	}
};

class LaserGun : public Gun
{
public:
	string description()
	{
		return "LaserGun - Melt everything with heat";
	}
};

class ShockwaveGun :public Gun
{
public:
	string description()
	{
		return "ShockwaveGun - shock down everything";
	}
};

class GofFactory_Gun
{
public:
	GofFactory_Gun()
	{
	}

	Gun *createGun(const string &type)
	{
		if ("MachineGun" == type)
		{
			return (new MachineGun);
		}
		else if ("LaserGun" == type)
		{
			return (new LaserGun); 
		}
		else if ("ShockwaveGun" == type)
		{
			return (new ShockwaveGun);
		}
		else
		{
			return NULL;
		}
	}
};

void GofFactory_Gun_Run()
{
	GofFactory_Gun gofGun;

	Gun *g = gofGun.createGun("MachineGun");
	cout<<g->description()<<endl;

	delete g;
	g = gofGun.createGun("LaserGun");
	cout<<g->description()<<endl;

	delete g;
	g = gofGun.createGun("ShockwaveGun");
	cout<<g->description()<<endl;

	delete g;
}

结果:

bubuko.com,布布扣


递归 将一个十进制数转化为任意进制字符串,布布扣,bubuko.com

递归 将一个十进制数转化为任意进制字符串

标签:des   class   blog   c   code   ext   

原文地址:http://blog.csdn.net/qingdujun/article/details/26494477

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!