例程实作----庖丁解羊(下)

原创 2001年09月28日 17:01:00

例程实作<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

                        ----庖丁解羊(下)

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

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

};

 

//嘴巴

class Mouth : public BasePart{

public:

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

};

 

//尾巴

class Stern : public BasePart{

public:

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

};

 

//胡子

class Goatee : public BasePart{

public:

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

};

 

//心

class Heart : public BasePart{

public:

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

};

 

//脾

class Spleen : public BasePart{

public:

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

};

 

//肝

class Liver : public BasePart{

public:

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

};

 

//肺

class Lung : public BasePart{

public:

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

};

 

//胃

class Stomach : public BasePart{

public:

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

};

 

//肠

class Intestine : public BasePart{

public:

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

};

 

//肾

class Kidney : public BasePart{

public:

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

};

 

//脚

class Leg : public BasePart{

public:

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

};

 

//肢体{{部分, 显示=显示肢体},脚[1],绒毛[n],骨架[1]}

class Limb : public Part{

public:

        void Draw()

                {

                cout << "Has a ";

                leg.Draw();

                cout << "Has a ";

                skelecton.Draw();

                cout << "Has some ";

                floss[0].Draw();

                }

private:

        Leg leg;

        Floss floss[10];

        Skelecton skelecton;

};

 

//前肢,后肢{{肢体}}

class Forelimb : public Limb{

public:

        void Draw()

                {

                cout<< "Forelimb " << endl;

                Limb::Draw();

                }

};

 

class Backlimb : public Limb{

public:

        void Draw()

                {

                cout<< "Backlimb " << endl;

                Limb::Draw();

                }

};

 

//四肢{{部分,显示=显示四肢},前肢[2],后肢[2]}

class Extermity : public Part{

public:

        void Draw()

                {

                cout<< "Has a Left ";

                Leftforelimb.Draw();

                cout<< "Has a Right ";

                Rightforelimb.Draw();

                cout<< "Has a Left ";

                Leftbacklimb.Draw();

                cout<< "Has a Right ";

                Rightbacklimb.Draw();

                }

private:

        Forelimb Leftforelimb,Rightforelimb;

        Backlimb Leftbacklimb,Rightbacklimb;

};

 

//内脏{{部分,显示=显示内脏},心[1],脾[1],肝[1],肺[2],胃[1],肠[n],肾[2]}

class Harslet: public Part{

public:

        void Draw()

                {

                cout << "Harslet " <<endl;

                cout << "Has a ";

                heart.Draw();

                cout << "Has a ";

                spleen.Draw();

                cout << "Has a ";

                liver.Draw();

                cout << "Has a Left ";

                Leftlung.Draw();

                cout << "Has a Right ";

                Rightlung.Draw();

                cout << "Has a ";

                stomach.Draw();

                cout << "Has Some ";

                intestine[0].Draw();

                cout << "Has a Left ";

                Leftkidney.Draw();

                cout << "Has a Right ";

                Rightkidney.Draw();

                }

private:

        Heart heart;

        Spleen spleen;

        Liver liver;

        Lung Leftlung , Rightlung;

        Stomach stomach;

        Intestine intestine[10];

        Kidney Leftkidney,Rightkidney;

};

 

//五官{{部分,显示=显示五官},耳朵[2],眼睛[2],鼻子[1],嘴巴[1]}

class Face : public Part{

public:

        void Draw()

                {

                cout << "Face " <<endl;

                cout << "Has a Left ";

                Leftear.Draw();

                cout << "Has a Right ";

                Rightear.Draw();

                cout << "Has a Left ";

                Lefteye.Draw();

                cout << "Has a Right ";

                Righteye.Draw();

                cout << "Has a ";

                nose.Draw();

                cout << "Has a ";

                mouth.Draw();

                }

private:

        Ear Leftear,Rightear;

        Eye Lefteye,Righteye;

        Nose nose;

        Mouth mouth;

};

 

//尾部{{部分,显示=显示尾部},尾巴[1],绒毛[n],骨架[1]}

class Tail: public Part{

public:

        void Draw()

                {

                cout << "Tail " <<endl;

                cout << "Has a ";

                stern.Draw();

                cout << "Has a ";

                skelecton.Draw();

                cout << "Has some ";

                floss[0].Draw();

                }

private:

        Stern stern;

        Floss floss[10];

        Skelecton skelecton;

};

 

//躯体{{部分,显示=显示躯体},胸[1],腹[1],背[1],内脏[1],绒毛[n],骨架[1]}

class Body: public Part{

public:

        void Draw()

                {

                cout << "Body " <<endl;

                cout << "Has a ";

                bosom.Draw();

                cout << "Has a ";

                abdomen.Draw();

                cout << "Has a ";

                backside.Draw();

                cout << "Has a ";

                harslet.Draw();

                cout << "Has a ";

                skelecton.Draw();

                cout << "Has some ";

                floss[0].Draw();

                }

private:

        Bosom bosom;

        Abdomen abdomen;

        Backside backside;

        Harslet harslet;

        Floss floss[10];

        Skelecton skelecton;

};

 

//脑袋{{部分,显示=显示脑袋},五官[1],胡子[n],绒毛[n],骨架[1]}

class Head: public Part{

public:

        void Draw()

                {

                cout <<"Head " << endl;

                cout << "Has a ";

                face.Draw();

                cout << "Has a ";

                skelecton.Draw();

                cout << "Has some ";

                goatee[0].Draw();

                }

private:

        Face face;

        Goatee goatee[10];

        Skelecton skelecton;

};

 

//山羊{{部分,显示=显示山羊},脑袋[1],躯体[1],四肢[1],尾部[1]}

class Sheep: public Part{

public:

        void Draw()

                {

                cout << "Sheep " << endl;

                cout << "Has a ";

                head.Draw();

                cout << "Has a ";

                body.Draw();

                cout << "Has a ";

                extermity.Draw();

                cout << "Has a ";

                tail.Draw();

                }

private:

        Head head;

        Body body;

        Extermity extermity;

        Tail tail;

};

 

void main(void)

{

        Sheep sheep;

        sheep.Draw();

        cin.get();

}

 

结果是:

Sheep

Has a Head

Has a Face

Has a Left Ear  with color :0

Has a Right Ear  with color :0

Has a Left Eye  with color :0

Has a Right Eye  with color :0

Has a Nose  with color :0

Has a Mouth  with color :0

Has a Skelecton  with color :0

Has some Goatee  with color :0

Has a Body

Has a Bosom  with color :0

Has a Abdomen  with color :0

Has a Backside  with color :0

Has a Harslet

Has a Heart  with color :0

Has a Spleen  with color :0

Has a Liver  with color :0

Has a Left Lung  with color :0

Has a Right Lung  with color :0

Has a Stomach  with color :0

Has Some Intestine  with color :0

Has a Left Kidney  with color :0

Has a Right Kidney  with color :0

Has a Skelecton  with color :0

Has some Floss  with color :0

Has a Has a Left Forelimb

Has a Leg  with color :0

Has a Skelecton  with color :0

Has some Floss  with color :0

Has a Right Forelimb

Has a Leg  with color :0

Has a Skelecton  with color :0

Has some Floss  with color :0

Has a Left Backlimb

Has a Leg  with color :0

Has a Skelecton  with color :0

Has some Floss  with color :0

Has a Right Backlimb

Has a Leg  with color :0

Has a Skelecton  with color :0

Has some Floss  with color :0

Has a Tail

Has a Stern  with color :0

Has a Skelecton  with color :0

Has some Floss  with color :0

 

邪门的是,这个程序我从头到尾打完以后,第一遍运行,居然没有错误,连误输入的错误都没有,这是不是说,我的指法又上层楼呢^o^。

 

虽然我提供了源程序,但是我希望还是认真的输入一遍,一来加深印象,二来可以练习指法。程序员的指法也是生产力啊。

 

不过这个程序只是演示性的,使用了固定的数组和变量,事实上弹性还远远不够,有一些属性的数目是可变的,比如羊毛是会掉的,瘸了一条腿的羊还是羊,所以重视弹性的话,这些变量都要改为指针可以动态的增减。

 

好了,说了半天相信读者也累了,还是让大家自己体会吧。

 

2001/9/27

丁宁  

例程实作----庖丁解羊(上)

 例程实作                        ----庖丁解羊(上)作者:HolyFire 在《庖丁解羊----划分》我们曾经将一只可爱的小羊拆成了零件,不知道是否还能否记得那道全羊谱。呵...
  • Apollo_HolyFire
  • Apollo_HolyFire
  • 2001年10月08日 08:40
  • 1086

详解庖丁解牛中文分词器工具的使用

今天在网上看了一篇关于中文分词的文章,有一类是关于基于字符串匹配的中文分词,里面谈到了一个“庖丁解牛分词器”,于是本人就想尝试跑跑这个分词工具。下面是具体的使用步骤: 1.  从网上下载了一个庖丁解...
  • u013709332
  • u013709332
  • 2015年02月02日 10:08
  • 2810

利用庖丁解牛工具进行中文分词

关于如何使用庖丁解牛分词工具可参考:http://www.letiantian.me/2014-11-26-word-segmentation-paoding-analysis/ 该工具可实现自定...
  • fjx1173865548
  • fjx1173865548
  • 2016年11月01日 22:35
  • 1052

庖丁解羊----划分

庖丁解羊                            ----闲谈编程思想作者:HolyFire经过多年的编程,我发现编程的思想对一个程序员是至关重要的,以前拿到一个问题,马上就开始考虑如...
  • Apollo_HolyFire
  • Apollo_HolyFire
  • 2001年08月24日 09:02
  • 1174

解决问题的步骤-庖丁解羊

经过多年的编程,吾发现编程的思想对一个程序员是至关重要的,以前拿到一个问题,马上就开始考虑如何来一点一点把他用代码来实现,于是啃啊啃啊于愁眉笼罩千辛万苦下每完成了一点就欣喜若狂。编着编着发现这里不足,...
  • zky1347888
  • zky1347888
  • 2014年11月24日 22:18
  • 998

2015年蓝桥杯省赛B组第3题--三羊献瑞

观察下面的加法算式:       祥 瑞 生 辉   +   三 羊 献 瑞 -------------------    三 羊 生 瑞 气 其中,相同的汉字代表相同的数字,不同的汉字代表不同的...
  • iamzxf
  • iamzxf
  • 2015年04月13日 10:26
  • 7834

蓝桥杯B组C语言-三羊献瑞

问题描述: 观察下面的加法算式:       祥 瑞 生 辉   +   三 羊 献 瑞 -------------------    三 羊 生 瑞 气 其中,相同的汉字代表相同的数字,不同的...
  • serena_0916
  • serena_0916
  • 2017年02月04日 10:45
  • 816

基于hadoop的分布式分词程序(庖丁分词)

一、使用的分词包——庖丁分词器介绍 1.1、简介: 庖丁系统是个完全基于lucene的中文分词系统,它就是重新建了一个analyzer,叫做PaodingAnalyzer,这个anal...
  • gywtzh0889
  • gywtzh0889
  • 2016年12月01日 16:12
  • 555

dbcp 连接 postgresql 报org.postgresql.jdbc4.Jdbc4Statement.setQueryTimeout(int)

Caused by: org.postgresql.util.PSQLException: 这个 org.postgresql.jdbc4.Jdbc4Statement.setQueryTimeout...
  • yangshaokai
  • yangshaokai
  • 2015年01月21日 16:07
  • 2956

IKAnalyzer和庖丁分词性能对比

  paoding和IK分词效果差不多,IK分词多些但速度差些。原文: http://www.zgkw.cn/FORUMS/blogs/dyx/archive/2008/02/18/59776.asp...
  • kellerdu
  • kellerdu
  • 2008年02月18日 12:35
  • 1652
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:例程实作----庖丁解羊(下)
举报原因:
原因补充:

(最多只允许输入30个字)