#include <iostream> #include <string> using namespace std; class Animal { public: virtual void cry() { cout<<"不知哪种动物,让我怎样学叫?"<<endl; } }; class Mouse:public Animal { public: Mouse(string nam,char s):name(nam),sex(s) {} void cry() { cout<<"我叫"<<name<<",是一仅仅"; if(sex=='m') cout<<"男老鼠,我的叫声是,吱吱吱!"<<endl; else cout<<"女老鼠,我的叫声是,吱吱吱!"<<endl; } protected: string name; char sex; }; class Cat:public Animal { public: Cat(string nam):name(nam) {} void cry() { cout<<"我叫"<<name<<",是一仅仅猫,我的叫声是,喵喵喵!"<<endl; } protected: string name; }; class Dog:public Animal { public: Dog(string nam):name(nam) {} void cry() { cout<<"我叫"<<name<<",是一仅仅狗,我的叫声是,汪汪汪!"<<endl; } protected: string name; }; class Giraffe:public Animal { public: Giraffe(string nam,char s):name(nam),sex(s) {} void cry() { cout<<"我叫"<<name<<",是一仅仅"; if(sex=='m') cout<<"男长颈鹿,我的脖子太长,发不出声音来!"<<endl; else cout<<"女长颈鹿,我的脖子太长,发不出声音来!"<<endl; } protected: string name; char sex; }; int main( ) { Animal *p; p = new Animal(); p->cry(); Mouse m1("Jerry",'m'); p=&m1; p->cry(); Mouse m2("Jemmy",'f'); p=&m2; p->cry(); Cat c1("Tom"); p=&c1; p->cry(); Dog d1("Droopy"); p=&d1; p->cry(); Giraffe g1("Gill",'m'); p=&g1; p->cry(); return 0; }
感悟:有人说长颈鹿是哑吧,从来不叫;也有人说长颈鹿没有声带,所以不会叫。事实上,这两种说法都不正确。长颈鹿不但有声带,并且也会叫。那么,它为什么不叫呢?这是由于长颈鹿的声带非常特别,声带中间有浅沟,不好发声;另外,长颈鹿发声须要靠肺、胸腔和膈肌的帮助,由于它的脖子太长,这些器官之间相距太远,叫起来非常费力气,所以,它们一般非常少叫。有时,幼小的长颈鹿找不着妈妈了,也能发出像牛犊的“哞、哞”叫声。。。。。。。哈哈