/*
* 程序的版权和版本声明部分:
* Copyright (c) 2013, 烟台大学计算机学院
* All rights reserved.
* 文件名称:test.cpp
* 作 者:周经纬
* 完成日期:2014年 5月 27日
* 版 本 号:v12.1
* 项目三
* 输入描述:无
* 问题描述:。
* 程序输出:
* 问题分析:略
* 算法设计:略
*/
#include <iostream>
#include <cstring>
using namespace std;
class Animal
{
public:
virtual void cry()
{
cout<<"不知哪种动物,让我如何学叫?"<<endl;
}
};
class Mouse:public Animal
{
public:
Mouse(string a,char b):name(a),x(b) {}
void cry()
{
if(x=='m')
{
cout<<"我叫"<<name<<","<<"是一只男老鼠,我的叫声是:zhizhizhi-----"<<endl;
}
else
{
cout<<"我叫"<<name<<","<<"是一只母老鼠,我的叫声是:zhizhizhi-----"<<endl;
}
}
private:
string name;
char x;
};
class Cat:public Animal
{
public:
Cat(string a):name(a) {}
void cry()
{
cout<<"我叫"<<name<<","<<"是一只猫,我的叫声是:miaomiaomiao-----"<<endl;
}
private:
string name;
};
class Dog:public Animal
{
public:
Dog(string a):name(a) {}
void cry()
{
cout<<"我叫"<<name<<","<<"是一只狗,我的叫声是:wnagwnagwang-----"<<endl;
}
private:
string name;
};
class Giraffe:public Animal
{
public:
Giraffe(string a,char b):name(a),x(b){}
void cry()
{
if(x=='m')
cout<<"我叫"<<name<<","<<"是一nan长颈鹿,因为脖子太长所以发不出声音"<<endl;
else
cout<<"我叫"<<name<<","<<"是一nv长颈鹿,因为脖子太长所以发不出声音"<<endl;
}
private:
string name;
char x;
};
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;
}