日期:2009-05-07  浏览次数:20528 次

例程实作

                        ----庖丁解羊(下)


#include <iostream>

#include <string>



using namespace std;



class Part{

public:

        virtual void Draw()=0;

        virtual ~Part(){}

};



class Shape{

public:

        Shape( string const& _s ):data( _s ){}

        void Draw( unsigned color )

                {

                cout << data << " with color :" << hex << color << endl;

                } //提供了借口,但是没有实现绘图

private:

        string data;

        //读者可以自己实现绘图部分

};



//绒毛,骨架,胸,腹,背,眼睛,鼻子,嘴巴,心,脾,肝,肠,肾,脚,尾巴,耳朵,肺,胃{{部分,显示=轮廓+颜色},轮廓[1],颜色[1]}



class BasePart : public Part{

public:

        BasePart( string const& _s , unsigned _c ):shape( _s ),color( _c ){}

        void Draw()

                {

                shape.Draw( color );

                }

private:

        Shape shape;

        unsigned color;

};



//绒毛

class Floss : public BasePart{

public:

        Floss( ):BasePart("Floss " ,0){}

};



//骨架

class Skelecton : public BasePart{

public:

        Skelecton( ):BasePart("Skelecton " ,0){}

};



//胸

class Bosom : public BasePart{

public:

        Bosom( ):BasePart("Bosom " ,0){}

};



//腹

class Abdomen : public BasePart{

public:

        Abdomen ( ):BasePart("Abdomen " ,0){}

};



//背

class Backside: public BasePart{

public:

        Backside ( ):BasePart("Backside " ,0){}

};



//眼睛

class Eye : public BasePart{

public:

        Eye ( ):BasePart("Eye " ,0){}

};



//耳朵

class Ear : public BasePart{

public:

        Ear ( ):BasePart("Ear " ,0){}

};



//鼻子

class Nose : public BasePart{

public:

    &nbs