Problem2047--CPP-抽象类练习

2047: CPP-抽象类练习

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 161  Solved: 107
[Submit] [Status] [Web Board] [Creator:]

Description

声明一个抽象类:Animal,它有名字、年龄两个属性,另外,还有eat和shout两个纯虚函数。
然后从Animal派生出Cat和Dog两个类,实现eat和shout两个方法。

在主程序中,接收用户的输入,c代表cat,d代表dog,然后根据输入创建对象,比如:
输入
c c d d
就创建两个cat和两个dog对象,然后分别调用它们的shout和eat方法,输出
miaomiao eat fish
miaomiao eat fish
wangwang eat bone
wangwang eat bone

Input

c c d d

Output

miaomiao eat fish
miaomiao eat fish
wangwang eat bone
wangwang eat bone

Sample Input

c d c d

Sample Output

miaomiao eat fish
wangwang eat bone
miaomiao eat fish
wangwang eat bone

Source/Category


[Submit] [Status]