#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; }
感悟:有人说长颈鹿是哑吧,从来不叫;也有人说长颈鹿没有声带,所以不会叫。其实,这两种说法都不对。长颈鹿不但有声带,而且也会叫。那么,它为什么不叫呢?这是因为长颈鹿的声带很特别,声带中间有浅沟,不好发声;另外,长颈鹿发声需要靠肺、胸腔和膈肌的帮助,由于它的脖子太长,这些器官之间相距太远,叫起来很费力气,所以,它们一般很少叫。有时,幼小的长颈鹿找不着妈妈了,也能发出像牛犊的“哞、哞”叫声。。。。。。。哈哈
原文地址:http://blog.csdn.net/zjx211314/article/details/27107331