第13周项目1动物这样叫(抽象类)
来源:互联网 发布:苹果电脑音乐制作软件 编辑:程序博客网 时间:2024/06/12 22:22
#include <iostream>#include <string>using namespace std;class Animal{public: virtual void cry()=0;};class Mouse : public Animal{private: string name; char sex;public: Mouse(string nam, char s):name(nam),sex(s) {} virtual void cry() { cout<<"我叫"<<name<<",是一只"<<((sex=='m')?"男":"女")<<"老鼠,我的叫声是:吱吱吱!"<<endl; }};class Cat : public Animal{private: string name;public: Cat(string nam):name(nam) {} virtual void cry() { cout<<"我叫"<<name<<",是一只猫,我的叫声是:喵喵喵!"<<endl; }};class Dog : public Animal{private: string name;public: Dog(string nam):name(nam) {} virtual void cry() { cout<<"我叫"<<name<<",是一条狗,我的叫声是:汪汪汪!"<<endl; }};class Giraffe : public Animal{private: string name; char sex;public: Giraffe(string nam,char s):name(nam), sex(s) {} virtual void cry() { cout<<"我叫"<<name<<",是"<<((sex=='m')?"男":"女")<<"长颈鹿,我的脖子太长,发不出声音来!"<<endl; }};int main( ){ Animal *p; 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;}
0 0
- 第13周项目1动物这样叫(抽象类)
- 第13周项目1-动物这样叫(3抽象类)
- 第13周 【项目1-动物这样叫】(1)
- 第13周项目1-动物这样叫(1)
- 第13周项目1-动物这样叫(1)
- 第13周项目1-动物这样叫(1)
- 第13周 【项目1-动物这样叫】(2)
- 第13周 【项目1-动物这样叫】(3)
- 第13周项目1动物这样叫(3)
- 第13周项目1-动物这样叫(2)
- 第13周项目1-动物这样叫(3)
- 第13周项目1-动物这样叫(2)
- 第13周项目1-动物这样叫(3)
- 第13周项目1-动物这样叫(2)
- 第13周项目1-动物这样叫(3)
- 第13周-项目2-动物这样叫(1)
- 第13周-项目1-动物这样叫(2)
- 第13周-项目1-动物这样叫(3)
- 在 docker 之间导出导入镜像
- LINUX GPIO Kernel/User API
- WPF 之Triggers
- Android---50---使用Socket进行通信
- Activiti介绍
- 第13周项目1动物这样叫(抽象类)
- Storm高级原语(一) — Transactional topology
- poj1068
- mysql不能远程登录
- mfc怎么把编辑框内的输入的数字存入int 2,如何把数字输出到编辑框内
- jQuery on()方法
- 第十五章输入/输出2015-05-29
- 字符类型之间的转换
- oracle体系结构